Commit 698b2b03 by ajil.k

integrated with all modules

parent 0b54d002
...@@ -7,3 +7,5 @@ class EndPoints: ...@@ -7,3 +7,5 @@ class EndPoints:
get_booking_details = "/get_booking_details/" get_booking_details = "/get_booking_details/"
show_begin = "/show_begin" show_begin = "/show_begin"
get_booking_details_between = "/get_booking_details_between/" get_booking_details_between = "/get_booking_details_between/"
booking_details_json = "/booking_details_json/"
...@@ -100,7 +100,7 @@ class Tickets: ...@@ -100,7 +100,7 @@ class Tickets:
print("-------------------------------Booking Details-------------------------------") print("-------------------------------Booking Details-------------------------------")
print(df) print(df)
# Use pandas to save the DataFrame to an Excel file # Use pandas to save the DataFrame to an Excel file
df.to_excel('temp/booking_details.xlsx', index=False) df.to_excel('external/booking_details.xlsx', index=False)
except Exception as e: except Exception as e:
logger.error(e) logger.error(e)
...@@ -113,6 +113,34 @@ class Tickets: ...@@ -113,6 +113,34 @@ class Tickets:
# Use pandas to convert the list of dictionaries to a DataFrame # Use pandas to convert the list of dictionaries to a DataFrame
df = pd.DataFrame(cleaned_data_dict) df = pd.DataFrame(cleaned_data_dict)
# Use pandas to save the DataFrame to an Excel file # Use pandas to save the DataFrame to an Excel file
df.to_excel(f'temp/booking_from_{from_date}_to_{to_date}_.xlsx', index=False) df.to_excel(f'external/booking_from_{from_date}_to_{to_date}_.xlsx', index=False)
except Exception as e: except Exception as e:
logger.error(e) logger.error(e)
def json_data(self):
try:
records = self.session.query(BookingDetails).all()
cleaned_data_dict = clean_record(records)
# Use pandas to convert the list of dictionaries to a DataFrame
df = pd.DataFrame(cleaned_data_dict)
df["date_of_purchase"] = df["date_of_purchase"].apply(lambda x: x.strftime('%Y-%m-%d'))
# df = pd.read_excel(filename)
# Print number of rows and columns
# print("Number of rows: ", len(df))
# # Setting "header" dictionary
keys = []
column_names = df.columns.tolist()
for i in range(len(column_names)):
keys.append("column" + str(i))
header_dict = {'header': dict(zip(keys, column_names))}
# Setting 'body' dictionary
data = {"body": df.to_dict(orient='records')}
json_dict = {**header_dict, **data}
# Create the JSON file
with open("external/bookings.json", "w") as json_file:
# Write data to the file
json.dump(json_dict, json_file, indent=4)
return json_dict
except Exception as e:
logger.exception(e)
print("Data insertion error-", e)
# importing libraries # importing libraries
from fastapi import APIRouter, UploadFile
from fastapi import APIRouter
from scripts.constants.endpoints import EndPoints from scripts.constants.endpoints import EndPoints
from scripts.constants.schema import ticket_booking from scripts.constants.schema import ticket_booking
from scripts.core.handlers.api_functions import Tickets from scripts.core.handlers.api_functions import Tickets
...@@ -60,3 +58,12 @@ def generate_seats(): ...@@ -60,3 +58,12 @@ def generate_seats():
except Exception as e: except Exception as e:
logger.error(e) logger.error(e)
print(e) print(e)
@router.post(EndPoints.booking_details_json, tags=["Create Json File"])
def booking_details_json_format(file: UploadFile):
try:
message = Tickets().json_data()
return message
except Exception as e:
logger.error(e)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment