Commit 03834878 by ajil.k

updated integrated with all modules

parent ac5ae7e1
......@@ -23,8 +23,9 @@ class Tickets:
# add new booking details
try:
# Check if the data entered
# if 5 >= details.no_of_tickets > 0:
# raise HTTPException(status_code=400, detail="Can book only 5 tickets at a time.")
if 5 < details.no_of_tickets or details.no_of_tickets <= 0:
raise HTTPException(status_code=400, detail="Invalid value for no. of tickets or"
" Can book only 5 tickets at a time.")
if details.preferred_class not in ["gold", "silver"]:
raise HTTPException(status_code=400, detail="Invalid class type")
seats = details.seat_numbers.split(",")
......@@ -97,10 +98,12 @@ class Tickets:
cleaned_data_dict = clean_record(records)
# Use pandas to convert the list of dictionaries to a DataFrame
df = pd.DataFrame(cleaned_data_dict)
print("-------------------------------Booking Details-------------------------------")
print(df)
# Use pandas to save the DataFrame to an Excel file
df.to_excel('external/booking_details.xlsx', index=False)
# Creating excel writer object
writer = pd.ExcelWriter('external/booking_details.xlsx')
# Write dataframe to excel
df.to_excel(writer, index=False)
# save the Excel
writer.save()
except Exception as e:
logger.error(e)
......@@ -117,30 +120,17 @@ class Tickets:
except Exception as e:
logger.error(e)
def json_data(self):
@staticmethod
def json_data(dataframe):
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')}
dataframe["date_of_purchase"] = dataframe["date_of_purchase"].dt.strftime('%Y-%m-%d')
keys = [f"column{i}" for i in range(len(dataframe.columns))]
header_dict = {'header': dict(zip(keys, dataframe.columns))}
data = {"body": dataframe.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)
print("Reading error-", e)
......@@ -7,6 +7,7 @@ from scripts.core.handlers.create_redis_db import redis_db_create
from scripts.core.handlers.get_all_seats import seat_availability
from scripts.database.RedisDB.db_connection import conn
from scripts.logging.logger import logger
import pandas as pd
# Create FastAPI instance
router = APIRouter()
......@@ -61,9 +62,10 @@ def generate_seats():
@router.post(EndPoints.booking_details_json, tags=["Create Json File"])
def booking_details_json_format(file: UploadFile):
async def booking_details_json_format(file: UploadFile):
try:
message = Tickets().json_data()
excel_file = pd.read_excel(await file.read())
message = Tickets().json_data(excel_file)
return message
except Exception as e:
logger.error(e)
......@@ -472,3 +472,152 @@ Traceback (most recent call last):
File "C:\Users\ajil.k\AppData\Local\Programs\Python\Python39\lib\json\encoder.py", line 179, in default
raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Timestamp is not JSON serializable
2023-02-15 12:57:47 - ERROR - [AnyIO worker thread:get_details():114] - [Errno 13] Permission denied: 'external/booking_details.xlsx'
2023-02-15 12:58:36 - ERROR - [AnyIO worker thread:get_details():114] - __init__() got an unexpected keyword argument 'index'
2023-02-15 13:03:32 - ERROR - [AnyIO worker thread:json_data():148] - 'SpooledTemporaryFile' object has no attribute 'seekable'
Traceback (most recent call last):
File "E:\Python\theater_management\scripts\core\handlers\api_functions.py", line 124, in json_data
df = pd.read_excel(filename.file)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\util\_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\util\_decorators.py", line 331, in wrapper
return func(*args, **kwargs)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_base.py", line 482, in read_excel
io = ExcelFile(io, storage_options=storage_options, engine=engine)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_base.py", line 1695, in __init__
self._reader = self._engines[engine](self._io, storage_options=storage_options)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_openpyxl.py", line 557, in __init__
super().__init__(filepath_or_buffer, storage_options=storage_options)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_base.py", line 545, in __init__
self.book = self.load_workbook(self.handles.handle)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_openpyxl.py", line 568, in load_workbook
return load_workbook(
File "E:\Python\theater_management\venv\lib\site-packages\openpyxl\reader\excel.py", line 346, in load_workbook
reader.read()
File "E:\Python\theater_management\venv\lib\site-packages\openpyxl\reader\excel.py", line 287, in read
self.read_manifest()
File "E:\Python\theater_management\venv\lib\site-packages\openpyxl\reader\excel.py", line 134, in read_manifest
src = self.archive.read(ARC_CONTENT_TYPES)
File "C:\Users\ajil.k\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 1472, in read
with self.open(name, "r", pwd) as fp:
File "C:\Users\ajil.k\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 1523, in open
zef_file = _SharedFile(self.fp, zinfo.header_offset,
File "C:\Users\ajil.k\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 722, in __init__
self.seekable = file.seekable
AttributeError: 'SpooledTemporaryFile' object has no attribute 'seekable'
2023-02-15 14:34:40 - ERROR - [AnyIO worker thread:booking_details_json_format():69] - json_data() missing 1 required positional argument: 'filename'
2023-02-15 14:35:41 - ERROR - [AnyIO worker thread:json_data():155] - 'SpooledTemporaryFile' object has no attribute 'seekable'
Traceback (most recent call last):
File "E:\Python\theater_management\scripts\core\handlers\api_functions.py", line 128, in json_data
wb = load_workbook(filename.file)
File "E:\Python\theater_management\venv\lib\site-packages\openpyxl\reader\excel.py", line 346, in load_workbook
reader.read()
File "E:\Python\theater_management\venv\lib\site-packages\openpyxl\reader\excel.py", line 287, in read
self.read_manifest()
File "E:\Python\theater_management\venv\lib\site-packages\openpyxl\reader\excel.py", line 134, in read_manifest
src = self.archive.read(ARC_CONTENT_TYPES)
File "C:\Users\ajil.k\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 1472, in read
with self.open(name, "r", pwd) as fp:
File "C:\Users\ajil.k\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 1523, in open
zef_file = _SharedFile(self.fp, zinfo.header_offset,
File "C:\Users\ajil.k\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 722, in __init__
self.seekable = file.seekable
AttributeError: 'SpooledTemporaryFile' object has no attribute 'seekable'
2023-02-15 14:41:20 - ERROR - [AnyIO worker thread:json_data():157] - expected str, bytes or os.PathLike object, not SpooledTemporaryFile
Traceback (most recent call last):
File "E:\Python\theater_management\scripts\core\handlers\api_functions.py", line 128, in json_data
workbook = xlrd.open_workbook(filename.file)
File "E:\Python\theater_management\venv\lib\site-packages\xlrd\__init__.py", line 166, in open_workbook
file_format = inspect_format(filename, file_contents)
File "E:\Python\theater_management\venv\lib\site-packages\xlrd\__init__.py", line 59, in inspect_format
path = os.path.expanduser(path)
File "C:\Users\ajil.k\AppData\Local\Programs\Python\Python39\lib\ntpath.py", line 293, in expanduser
path = os.fspath(path)
TypeError: expected str, bytes or os.PathLike object, not SpooledTemporaryFile
2023-02-15 14:53:31 - ERROR - [AnyIO worker thread:json_data():148] - 'SpooledTemporaryFile' object has no attribute 'seekable'
Traceback (most recent call last):
File "E:\Python\theater_management\scripts\core\handlers\api_functions.py", line 125, in json_data
df = pd.read_excel(filename.file)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\util\_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\util\_decorators.py", line 331, in wrapper
return func(*args, **kwargs)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_base.py", line 482, in read_excel
io = ExcelFile(io, storage_options=storage_options, engine=engine)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_base.py", line 1695, in __init__
self._reader = self._engines[engine](self._io, storage_options=storage_options)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_openpyxl.py", line 557, in __init__
super().__init__(filepath_or_buffer, storage_options=storage_options)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_base.py", line 545, in __init__
self.book = self.load_workbook(self.handles.handle)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_openpyxl.py", line 568, in load_workbook
return load_workbook(
File "E:\Python\theater_management\venv\lib\site-packages\openpyxl\reader\excel.py", line 346, in load_workbook
reader.read()
File "E:\Python\theater_management\venv\lib\site-packages\openpyxl\reader\excel.py", line 287, in read
self.read_manifest()
File "E:\Python\theater_management\venv\lib\site-packages\openpyxl\reader\excel.py", line 134, in read_manifest
src = self.archive.read(ARC_CONTENT_TYPES)
File "C:\Users\ajil.k\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 1472, in read
with self.open(name, "r", pwd) as fp:
File "C:\Users\ajil.k\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 1523, in open
zef_file = _SharedFile(self.fp, zinfo.header_offset,
File "C:\Users\ajil.k\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 722, in __init__
self.seekable = file.seekable
AttributeError: 'SpooledTemporaryFile' object has no attribute 'seekable'
2023-02-15 15:14:36 - ERROR - [AnyIO worker thread:json_data():147] - 'SpooledTemporaryFile' object has no attribute 'seekable'
Traceback (most recent call last):
File "E:\Python\theater_management\scripts\core\handlers\api_functions.py", line 126, in json_data
df = pd.read_excel(filename.file)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\util\_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\util\_decorators.py", line 331, in wrapper
return func(*args, **kwargs)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_base.py", line 482, in read_excel
io = ExcelFile(io, storage_options=storage_options, engine=engine)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_base.py", line 1695, in __init__
self._reader = self._engines[engine](self._io, storage_options=storage_options)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_openpyxl.py", line 557, in __init__
super().__init__(filepath_or_buffer, storage_options=storage_options)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_base.py", line 545, in __init__
self.book = self.load_workbook(self.handles.handle)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_openpyxl.py", line 568, in load_workbook
return load_workbook(
File "E:\Python\theater_management\venv\lib\site-packages\openpyxl\reader\excel.py", line 346, in load_workbook
reader.read()
File "E:\Python\theater_management\venv\lib\site-packages\openpyxl\reader\excel.py", line 287, in read
self.read_manifest()
File "E:\Python\theater_management\venv\lib\site-packages\openpyxl\reader\excel.py", line 134, in read_manifest
src = self.archive.read(ARC_CONTENT_TYPES)
File "C:\Users\ajil.k\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 1472, in read
with self.open(name, "r", pwd) as fp:
File "C:\Users\ajil.k\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 1523, in open
zef_file = _SharedFile(self.fp, zinfo.header_offset,
File "C:\Users\ajil.k\AppData\Local\Programs\Python\Python39\lib\zipfile.py", line 722, in __init__
self.seekable = file.seekable
AttributeError: 'SpooledTemporaryFile' object has no attribute 'seekable'
2023-02-15 15:20:35 - ERROR - [AnyIO worker thread:booking_details_json_format():76] - 'Tickets' object has no attribute 'json_data'
2023-02-15 15:25:48 - ERROR - [AnyIO worker thread:booking_details_json_format():77] -
2023-02-15 15:26:57 - ERROR - [AnyIO worker thread:booking_details_json_format():77] - 'SpooledTemporaryFile' object has no attribute 'seekable'
2023-02-15 15:29:06 - ERROR - [MainThread:booking_details_json_format():78] -
2023-02-15 16:00:07 - ERROR - [AnyIO worker thread:json_data():142] - Invalid file path or buffer object type: <class 'coroutine'>
Traceback (most recent call last):
File "E:\Python\theater_management\scripts\core\handlers\api_functions.py", line 126, in json_data
df = pd.read_excel(filename.read())
File "E:\Python\theater_management\venv\lib\site-packages\pandas\util\_decorators.py", line 211, in wrapper
return func(*args, **kwargs)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\util\_decorators.py", line 331, in wrapper
return func(*args, **kwargs)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_base.py", line 482, in read_excel
io = ExcelFile(io, storage_options=storage_options, engine=engine)
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_base.py", line 1652, in __init__
ext = inspect_excel_format(
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\excel\_base.py", line 1525, in inspect_excel_format
with get_handle(
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\common.py", line 713, in get_handle
ioargs = _get_filepath_or_buffer(
File "E:\Python\theater_management\venv\lib\site-packages\pandas\io\common.py", line 451, in _get_filepath_or_buffer
raise ValueError(msg)
ValueError: Invalid file path or buffer object type: <class 'coroutine'>
2023-02-15 16:08:29 - ERROR - [MainThread:booking_details_json_format():71] - timed out
2023-02-15 16:10:54 - ERROR - [MainThread:booking_details_json_format():71] - object SpooledTemporaryFile can't be used in 'await' expression
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