Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
ticket_booking_task
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ajil.k
ticket_booking_task
Commits
03834878
Commit
03834878
authored
Feb 15, 2023
by
ajil.k
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated integrated with all modules
parent
ac5ae7e1
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
28 deletions
+20
-28
external/booking_details.xlsx
+0
-0
scripts/core/handlers/api_functions.py
+16
-26
scripts/services/api_call.py
+4
-2
temp/_ERROR.log
+0
-0
No files found.
external/booking_details.xlsx
View file @
03834878
No preview for this file type
scripts/core/handlers/api_functions.py
View file @
03834878
...
...
@@ -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
)
scripts/services/api_call.py
View file @
03834878
...
...
@@ -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
)
temp/_ERROR.log
View file @
03834878
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment