Commit 2d48d4c8 authored by arjun.b's avatar arjun.b

integrated

parents
FILE_PATH=temp/logging_log_ERROR.log
TOKEN=ticket2/
DELETE_TOPIC=ticket2/delete
CANCEL_TOPIC=ticket2/cancel_all
POSTGRES_URI=postgresql://postgres:test@localhost/ticket
MQTT_HOST=192.168.0.220
PORT=1883
TABLE_NAME=ticket_details
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N801" />
</list>
</option>
</inspection_tool>
</profile>
</component>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (Ticket-publish)" project-jdk-type="Python SDK" />
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/Ticket-publish.iml" filepath="$PROJECT_DIR$/.idea/Ticket-publish.iml" />
</modules>
</component>
</project>
\ No newline at end of file
r python:S3776ö"TRefactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed.(Ž‹ìõüÿÿÿÿ
m python:S3776¶"TRefactor this function to reduce its Cognitive Complexity from 40 to the 15 allowed.(ôÒŽ×
M python:S1135Ý"4Complete the task associated to this "TODO" comment.(Ͷ»û
r python:S3776š "TRefactor this function to reduce its Cognitive Complexity from 18 to the 15 allowed.(¦Ã§Öûÿÿÿÿ
U python:S5754µ "<Specify an exception class to catch or reraise the exception(ˆÊÉ·
r python:S3776Þ "TRefactor this function to reduce its Cognitive Complexity from 27 to the 15 allowed.(³»ó‘ýÿÿÿÿ
R python:S1135¶
"4Complete the task associated to this "TODO" comment.( £ˆ”ýÿÿÿÿ
A python:S108Ç")Either remove or fill this block of code.(ã‘Û¾
r python:S3776Û"TRefactor this function to reduce its Cognitive Complexity from 35 to the 15 allowed.(ϭбþÿÿÿÿ
r python:S3776Ù"TRefactor this function to reduce its Cognitive Complexity from 58 to the 15 allowed.(÷­öŠýÿÿÿÿ
r python:S3776Ù"TRefactor this function to reduce its Cognitive Complexity from 26 to the 15 allowed.(¾àÿæøÿÿÿÿ
E python:S1481À"'Remove the unused local variable "obj".(䩵ñùÿÿÿÿ
r python:S3776Ñ"TRefactor this function to reduce its Cognitive Complexity from 28 to the 15 allowed.(˜­óîúÿÿÿÿ
M python:S1135´"4Complete the task associated to this "TODO" comment.(­ß…Æ
m python:S3776®"TRefactor this function to reduce its Cognitive Complexity from 36 to the 15 allowed.(ÖÞ•Ñ
m python:S3776¿ "TRefactor this function to reduce its Cognitive Complexity from 25 to the 15 allowed.(ù¶ÎÙ
U python:S5754³!"<Specify an exception class to catch or reraise the exception(ˆÊÉ·
U python:S5754¿#"<Specify an exception class to catch or reraise the exception(ˆÊÉ·
S python:S2836Ž$"5Add a "break" statement or remove this "else" clause.(³£œ‰øÿÿÿÿ
\ No newline at end of file
H python:S1066"/Merge this if statement with the enclosing one.(
k python:S1226"MIntroduce a new variable or use its initial value before reassigning 'dict_'.(
\ No newline at end of file
`
0venv/Lib/site-packages/sqlalchemy/orm/session.py,8\2\82b5a4e003bc46f722987f102bd24b2052704617
a
1venv/Lib/site-packages/sqlalchemy/orm/decl_api.py,d\f\df30e052d0bbb84a453d3c6584c1f74ac22a2ed6
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
import uvicorn
from scripts.logging.logging import logger
if __name__ == "__main__":
try:
uvicorn.run("main:app", port=8765)
except Exception as e:
logger.error(e)
print(e)
[log_file_path1]
file_name=scripts/external/logging_log
[excel_path]
file_path=scripts/external/booking_details.xlsx
\ No newline at end of file
import uvicorn
from fastapi import FastAPI
from scripts.logging.logging import logger
from scripts.services.delete_ticket import delete_ticket
from scripts.services.publish import router
app = FastAPI()
app.include_router(router)
app.include_router(delete_ticket)
if __name__ == "__main__":
try:
uvicorn.run(app, port=8765)
except Exception as e:
logger.error(e)
print(e)
import configparser
import os
from dotenv import load_dotenv
try:
config = configparser.ConfigParser()
config.read(r"conf\app.conf")
# logging file path
file_name = config.get("log_file_path1", "file_name")
# Excel file path
file_path = config.get("excel_path", "file_path")
except configparser.NoOptionError as e:
print(f"could not find conf file {e}")
try:
load_dotenv()
token = os.getenv("TOKEN")
del_topic = os.getenv("DELETE_TOPIC")
can_topic = os.getenv("CANCEL_TOPIC")
postgres_uri = os.getenv("POSTGRES_URI")
host = os.getenv("MQTT_HOST")
port_no = os.getenv("PORT")
table_name = os.getenv("TABLE_NAME")
except Exception as e:
print(e)
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from scripts.database.model import Base
from scripts.logging.logging import logger
def db_connect():
try:
engine = create_engine("postgresql://postgres:123@localhost/ticket")
sessions = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base.metadata.create_all(engine)
session = sessions()
return session
except Exception as e:
logger.error(e)
print(e)
import redis
# gold seats db on redis
conn = redis.Redis('127.0.0.1', db=4)
class EndPoints:
root = "/"
book_ticket = "/book ticket"
delete_a_ticket = "/delete_ticket{ticket_id}"
get_booking_details = "/get_booking_details/"
cancel_all_tickets = "/cancel_all_tickets/"
seat_availability = "/seat_availability/"
show_begin = "/show_begin"
get_booking_details_between = "/get_booking_details_between/"
import pickle
# check for the seat availability
def check_seat_avail(connection, ticket_class, seats_needed):
try:
class_lists = {
"gold": pickle.loads(connection.get("gold")),
"silver": pickle.loads(connection.get("silver"))
}
# get the availability of seat
if ticket_class not in class_lists:
return None
flag = 0
for seats in class_lists[ticket_class]:
if seats_needed in seats:
flag += 1
return True
if flag == 0:
return False
except Exception as e:
print(e)
import json
import pandas as pd
from fastapi import HTTPException
import paho.mqtt.client as mqtt
from scripts.config.application_config import token, host, file_path
from scripts.config.db_connect import db_connect
from scripts.config.redis_connection import conn
from scripts.core.handlers.avail_seat_redis import check_seat_avail
from scripts.core.handlers.format_data_from_db import clean_record
from scripts.database.model import Ticket
from scripts.logging.logging import logger
class BookTicket:
@staticmethod
def book_ticket(ticket):
try:
client = mqtt.Client()
client.connect(host, 1883, 60)
booked_list = []
# Check if the data entered
if ticket.no_of_tickets > 5:
return HTTPException(status_code=400, detail="Can book only 5 tickets at a time.")
if ticket.preferred_class not in ["gold", "silver"]:
return HTTPException(status_code=400, detail="Invalid class type")
seats = ticket.seat_no.split(",")
integer_list = [int(item) for item in seats]
if len(integer_list) != ticket.no_of_tickets:
return HTTPException(status_code=400,
detail="Number of seat numbers must match the number of tickets")
for seat_ in integer_list:
if seat_ not in booked_list:
if not check_seat_avail(conn, ticket.preferred_class, int(seat_)):
booked_list.append(seat_)
if booked_list:
return HTTPException(status_code=400,
detail=f"Seat number that are already booked are : {booked_list} \n"
f"seat number you are going to book are {integer_list}")
payload = {ticket.preferred_class: integer_list}
client.publish(token + ticket.preferred_class, json.dumps(payload))
# save ticket details to database
save_ticket = Ticket(
mobile_no=ticket.mobile_no,
preferred_class=ticket.preferred_class,
no_of_tickets=ticket.no_of_tickets,
seat_no=ticket.seat_no,
age=ticket.age
)
session = db_connect()
session.add(save_ticket)
session.commit()
return "ticket booked successfully"
except Exception as e:
print(e)
logger.error(e)
class BookingDetails:
@staticmethod
def get_details():
try:
session = db_connect()
records = session.query(Ticket).all()
dict_records_clean = clean_record(records)
# Use pandas to convert the list of dictionaries to a DataFrame
df = pd.DataFrame(dict_records_clean)
# Use pandas to save the DataFrame to an Excel file
df.to_excel(file_path, index=False)
except Exception as e:
logger.error(e)
# create redis db
import pickle
def redis_db_create(connection, ticket_class, seats, total_count):
try:
mapper_ticket_class = {
"gold": lambda count: connection.set("gold_available_seats", count),
"silver": lambda count: connection.set("silver_available_seats", count)
}
# if the class is not present
if ticket_class not in mapper_ticket_class:
return None
# getting the class from the mapper
mapper_ticket_class[ticket_class](total_count)
list_ = []
# appending to the list for creating the redis db
for row in range(1, total_count, seats):
list_.append([seat for seat in range(row, row + seats)])
return True if connection.set(ticket_class, pickle.dumps(list_)) else False
except Exception as e:
print(e)
import json
import paho.mqtt.client as mqtt
from scripts.config.application_config import host, can_topic, del_topic
from scripts.config.db_connect import db_connect
from scripts.database.model import Ticket
from scripts.logging.logging import logger
class db_handler:
@staticmethod
def delete_row(booking_id):
try:
client = mqtt.Client()
client.connect(host, 1883, 60)
# Soft delete a row in the ticket_details table
session = db_connect()
ticket = session.query(Ticket).filter(Ticket.booking_id == booking_id).first()
if ticket is not None:
ticket.deleted = True
session.commit()
no_seats = ticket.seat_no
data_of_list = no_seats.split(",")
integer_list = [int(item) for item in data_of_list]
data = {ticket.preferred_class: integer_list}
client.publish(del_topic, json.dumps(data))
return data
else:
print(f"Ticket with id {booking_id} is not exist")
logger.error(f"Ticket with id {booking_id} is not exist")
return {"message": f"ticket with id {booking_id} not exist",
"status": "Ticket not exist",
"data": booking_id}
except Exception as e:
logger.error(e)
@staticmethod
def cancel_tickets():
try:
client = mqtt.Client()
client.connect(host, 1883, 60)
session = db_connect()
query = session.query(Ticket).update({Ticket.deleted: True})
# Commit the changes to the database
session.commit()
if query is not None:
# Publish the Message
message = "Show Cancelled"
client.publish(can_topic, message)
except Exception as e:
logger.error(e)
def clean_record(records):
dict_records = [record.__dict__ for record in records]
# Remove any keys from the dictionaries that start with an underscore
dict_records_clean = [
{
key: values for key, values in record.items() if not key.startswith('_')
}
for record in dict_records
]
return dict_records_clean
# check if class seats are available
import pickle
def data_decode(val):
# decode the val to integers
if int(val.decode('UTF-8')):
return True
else:
return False
def create_json_view(connection, ticket_class):
mapper_ticket_class = {
"gold": pickle.loads(connection.get("gold")),
"silver": pickle.loads(connection.get("silver"))
}
class_list = mapper_ticket_class[ticket_class]
data = {"message": "Seat Availability"}
# create the json for the user to view
for i, row in enumerate(class_list):
data["Row {}".format(i + 1)] = ", ".join(map(str, row))
return data
# check if seats are available if then return seats else then return class that's available or return houseful
def seat_availability(connection, ticket_class):
try:
# counter for the checking if one class is full then get the other class
counter = None
class_avail = {
"gold": connection.get("gold_available_seats"),
"silver": connection.get("silver_available_seats")
}
# decode the data and the seat availability
for key, val in class_avail.items():
check_status = data_decode(val)
if key == ticket_class and check_status:
return create_json_view(connection, ticket_class)
elif key is not ticket_class and check_status:
counter = key
continue
if counter is not None:
return {"message": "Seat Availability", "Status": "Not Available", counter: "Available"}
else:
return {"HouseFull"}
except Exception as e:
print(e)
from datetime import datetime
from sqlalchemy import Column, String, Integer, Boolean, DateTime
from sqlalchemy.orm import declarative_base
Base = declarative_base()
class Ticket(Base):
__tablename__ = "ticket_details"
booking_id = Column(Integer, primary_key=True)
mobile_no = Column(String, unique=True)
preferred_class = Column(String)
no_of_tickets = Column(Integer)
seat_no = Column(String)
date_of_purchase = Column(DateTime, default=datetime.now())
age = Column(Integer)
deleted = Column(Boolean, default=False)
from pydantic import BaseModel
class FilmTicket(BaseModel):
mobile_no: int
preferred_class: str
no_of_tickets: int
seat_no: str
age: int
2023-02-10 12:35:30 - ERROR - [MainThread:<module>():9] - Class <class 'scripts.database.model.Ticket'> does not have a __table__ or __tablename__ specified and does not inherit from an existing table-mapped class.
2023-02-10 12:38:28 - ERROR - [MainThread:<module>():9] - name '__tablename__' is not defined
2023-02-10 12:39:07 - ERROR - [MainThread:<module>():9] - Mapper Mapper[Ticket(ticket_details)] could not assemble any primary key columns for mapped table 'ticket_details'
2023-02-10 13:02:15 - ERROR - [MainThread:<module>():9] - Invalid args for response field! Hint: check that <class 'scripts.database.model.Ticket'> is a valid Pydantic field type. If you are using a return type annotation that is not a valid Pydantic field (e.g. Union[Response, dict, None]) you can disable generating the response model from the type annotation with the path operation decorator parameter response_model=None. Read more: https://fastapi.tiangolo.com/tutorial/response-model/
2023-02-10 14:11:02 - ERROR - [MainThread:<module>():9] - Invalid args for response field! Hint: check that <class 'scripts.database.model.Ticket'> is a valid Pydantic field type. If you are using a return type annotation that is not a valid Pydantic field (e.g. Union[Response, dict, None]) you can disable generating the response model from the type annotation with the path operation decorator parameter response_model=None. Read more: https://fastapi.tiangolo.com/tutorial/response-model/
2023-02-10 14:12:14 - ERROR - [MainThread:<module>():9] - Invalid args for response field! Hint: check that <class 'scripts.database.model.Ticket'> is a valid Pydantic field type. If you are using a return type annotation that is not a valid Pydantic field (e.g. Union[Response, dict, None]) you can disable generating the response model from the type annotation with the path operation decorator parameter response_model=None. Read more: https://fastapi.tiangolo.com/tutorial/response-model/
2023-02-10 14:17:32 - ERROR - [MainThread:<module>():9] - Invalid args for response field! Hint: check that <class 'scripts.database.model.Ticket'> is a valid Pydantic field type. If you are using a return type annotation that is not a valid Pydantic field (e.g. Union[Response, dict, None]) you can disable generating the response model from the type annotation with the path operation decorator parameter response_model=None. Read more: https://fastapi.tiangolo.com/tutorial/response-model/
2023-02-10 14:18:29 - ERROR - [MainThread:<module>():9] - Invalid args for response field! Hint: check that <class 'scripts.database.model.Ticket'> is a valid Pydantic field type. If you are using a return type annotation that is not a valid Pydantic field (e.g. Union[Response, dict, None]) you can disable generating the response model from the type annotation with the path operation decorator parameter response_model=None. Read more: https://fastapi.tiangolo.com/tutorial/response-model/
2023-02-10 15:39:53 - ERROR - [MainThread:<module>():12] - No module named 'psycopg2'
2023-02-10 18:55:36 - ERROR - [AnyIO worker thread:book_ticket():56] - Invalid input of type: 'Ticket'. Convert to a bytes, string, int or float first.
2023-02-10 18:57:15 - ERROR - [AnyIO worker thread:book_ticket():55] - Invalid input of type: 'Ticket'. Convert to a bytes, string, int or float first.
2023-02-10 18:59:21 - ERROR - [AnyIO worker thread:book_ticket():56] - a bytes-like object is required, not 'Ticket'
2023-02-10 19:02:10 - ERROR - [AnyIO worker thread:book_ticket():57] - a bytes-like object is required, not 'Ticket'
2023-02-13 10:18:19 - ERROR - [AnyIO worker thread:book_ticket():56] - a bytes-like object is required, not 'Ticket'
2023-02-13 10:20:02 - ERROR - [AnyIO worker thread:book_ticket():56] - (psycopg2.errors.UndefinedColumn) column "age" of relation "ticket_details" does not exist
LINE 1: ...ket_details (mobile_no, pref_class, no_of_ticket, age, statu...
^
[SQL: INSERT INTO ticket_details (mobile_no, pref_class, no_of_ticket, age, status) VALUES (%(mobile_no)s, %(pref_class)s, %(no_of_ticket)s, %(age)s, %(status)s)]
[parameters: {'mobile_no': 74645636363, 'pref_class': 'Gold', 'no_of_ticket': 1, 'age': 34, 'status': None}]
(Background on this error at: https://sqlalche.me/e/20/f405)
2023-02-13 10:24:36 - ERROR - [AnyIO worker thread:book_ticket():56] - (psycopg2.errors.UndefinedTable) relation "ticket_details" does not exist
LINE 1: INSERT INTO ticket_details (mobile_no, pref_class, no_of_tic...
^
[SQL: INSERT INTO ticket_details (mobile_no, pref_class, no_of_ticket, age, status) VALUES (%(mobile_no)s, %(pref_class)s, %(no_of_ticket)s, %(age)s, %(status)s)]
[parameters: {'mobile_no': 9998887775, 'pref_class': 'Gold', 'no_of_ticket': 2, 'age': 33, 'status': None}]
(Background on this error at: https://sqlalche.me/e/20/f405)
2023-02-13 10:31:45 - ERROR - [AnyIO worker thread:book_ticket():56] - (psycopg2.errors.UndefinedTable) relation "ticket_details" does not exist
LINE 1: INSERT INTO ticket_details (mobile_no, pref_class, no_of_tic...
^
[SQL: INSERT INTO ticket_details (mobile_no, pref_class, no_of_ticket, age) VALUES (%(mobile_no)s, %(pref_class)s, %(no_of_ticket)s, %(age)s) RETURNING ticket_details.status]
[parameters: {'mobile_no': 0, 'pref_class': 'Gold', 'no_of_ticket': 0, 'age': 0}]
(Background on this error at: https://sqlalche.me/e/20/f405)
2023-02-13 10:39:10 - ERROR - [AnyIO worker thread:book_ticket():56] - (builtins.TypeError) Not a boolean value: 'false'
[SQL: INSERT INTO ticket_details (mobile_no, pref_class, no_of_ticket, age, status) VALUES (%(mobile_no)s, %(pref_class)s, %(no_of_ticket)s, %(age)s, %(status)s)]
[parameters: [{'pref_class': 'Gold', 'age': 0, 'mobile_no': 0, 'no_of_ticket': 0}]]
2023-02-13 10:40:36 - ERROR - [AnyIO worker thread:book_ticket():56] - (psycopg2.errors.UndefinedTable) relation "ticket_details" does not exist
LINE 1: INSERT INTO ticket_details (mobile_no, pref_class, no_of_tic...
^
[SQL: INSERT INTO ticket_details (mobile_no, pref_class, no_of_ticket, age, status) VALUES (%(mobile_no)s, %(pref_class)s, %(no_of_ticket)s, %(age)s, %(status)s)]
[parameters: {'mobile_no': 0, 'pref_class': 'Gold', 'no_of_ticket': 0, 'age': 0, 'status': False}]
(Background on this error at: https://sqlalche.me/e/20/f405)
2023-02-13 11:16:01 - ERROR - [AnyIO worker thread:book_ticket():56] - (psycopg2.errors.UndefinedColumn) column "date_of_purchase" of relation "ticket_details" does not exist
LINE 1: ...etails (mobile_no, pref_class, no_of_ticket, age, date_of_pu...
^
[SQL: INSERT INTO ticket_details (mobile_no, pref_class, no_of_ticket, age, date_of_purchase, status) VALUES (%(mobile_no)s, %(pref_class)s, %(no_of_ticket)s, %(age)s, %(date_of_purchase)s, %(status)s) RETURNING ticket_details.ticket_id]
[parameters: {'mobile_no': 7766453245, 'pref_class': 'Silver', 'no_of_ticket': 3, 'age': 24, 'date_of_purchase': datetime.date(2023, 2, 13), 'status': False}]
(Background on this error at: https://sqlalche.me/e/20/f405)
2023-02-13 12:09:04 - ERROR - [AnyIO worker thread:delete_row():23] - (psycopg2.errors.UndefinedFunction) operator does not exist: integer = boolean
LINE 3: ..._details.ticket_id = 3 AND ticket_details.ticket_id = false
^
HINT: No operator matches the given name and argument types. You might need to add explicit type casts.
[SQL: SELECT ticket_details.ticket_id AS ticket_details_ticket_id, ticket_details.mobile_no AS ticket_details_mobile_no, ticket_details.pref_class AS ticket_details_pref_class, ticket_details.no_of_ticket AS ticket_details_no_of_ticket, ticket_details.age AS ticket_details_age, ticket_details.date_of_purchase AS ticket_details_date_of_purchase, ticket_details.status AS ticket_details_status
FROM ticket_details
WHERE ticket_details.ticket_id = %(ticket_id_1)s AND ticket_details.ticket_id = false
LIMIT %(param_1)s]
[parameters: {'ticket_id_1': 3, 'param_1': 1}]
(Background on this error at: https://sqlalche.me/e/20/f405)
2023-02-13 14:22:56 - ERROR - [AnyIO worker thread:book_ticket():57] - 'Film_Ticket' object has no attribute 'row'
2023-02-13 15:01:38 - ERROR - [AnyIO worker thread:book_ticket():61] - local variable 'key' referenced before assignment
2023-02-13 15:04:01 - ERROR - [AnyIO worker thread:book_ticket():61] - 'Film_Ticket' object has no attribute 'row'
2023-02-13 15:07:44 - ERROR - [AnyIO worker thread:book_ticket():60] - 'pref_class' is an invalid keyword argument for Ticket
2023-02-13 15:09:05 - ERROR - [AnyIO worker thread:book_ticket():60] - (psycopg2.errors.UndefinedColumn) column "preferred_class" of relation "ticket_details" does not exist
LINE 1: INSERT INTO ticket_details (mobile_no, preferred_class, no_o...
^
[SQL: INSERT INTO ticket_details (mobile_no, preferred_class, no_of_tickets, date_of_purchase, age, status) VALUES (%(mobile_no)s, %(preferred_class)s, %(no_of_tickets)s, %(date_of_purchase)s, %(age)s, %(status)s) RETURNING ticket_details.booking_id]
[parameters: {'mobile_no': 1111, 'preferred_class': 'Gold', 'no_of_tickets': 3, 'date_of_purchase': datetime.date(2023, 2, 13), 'age': 45, 'status': False}]
(Background on this error at: https://sqlalche.me/e/20/f405)
2023-02-13 16:33:42 - ERROR - [AnyIO worker thread:book_ticket():63] - (psycopg2.errors.InvalidTextRepresentation) invalid input syntax for type integer: "[21,22]"
LINE 1: ...hase, age, status) VALUES (9876543210, 'Gold', 2, '[21,22]',...
^
[SQL: INSERT INTO ticket_details (mobile_no, preferred_class, no_of_tickets, seat_no, date_of_purchase, age, status) VALUES (%(mobile_no)s, %(preferred_class)s, %(no_of_tickets)s, %(seat_no)s, %(date_of_purchase)s, %(age)s, %(status)s) RETURNING ticket_details.booking_id]
[parameters: {'mobile_no': 9876543210, 'preferred_class': 'Gold', 'no_of_tickets': 2, 'seat_no': '[21,22]', 'date_of_purchase': datetime.date(2023, 2, 13), 'age': 22, 'status': False}]
(Background on this error at: https://sqlalche.me/e/20/9h9h)
2023-02-13 16:35:04 - ERROR - [AnyIO worker thread:book_ticket():63] - (psycopg2.errors.InvalidTextRepresentation) invalid input syntax for type integer: "[21,21]"
LINE 1: ...hase, age, status) VALUES (7766554433, 'Gold', 2, '[21,21]',...
^
[SQL: INSERT INTO ticket_details (mobile_no, preferred_class, no_of_tickets, seat_no, date_of_purchase, age, status) VALUES (%(mobile_no)s, %(preferred_class)s, %(no_of_tickets)s, %(seat_no)s, %(date_of_purchase)s, %(age)s, %(status)s) RETURNING ticket_details.booking_id]
[parameters: {'mobile_no': 7766554433, 'preferred_class': 'Gold', 'no_of_tickets': 2, 'seat_no': '[21,21]', 'date_of_purchase': datetime.date(2023, 2, 13), 'age': 34, 'status': False}]
(Background on this error at: https://sqlalche.me/e/20/9h9h)
2023-02-13 16:37:04 - ERROR - [AnyIO worker thread:book_ticket():63] - (psycopg2.errors.InvalidTextRepresentation) invalid input syntax for type integer: "['23','34','65']"
LINE 1: ...hase, age, status) VALUES (9876643430, 'Gold', 3, '[''23'','...
^
[SQL: INSERT INTO ticket_details (mobile_no, preferred_class, no_of_tickets, seat_no, date_of_purchase, age, status) VALUES (%(mobile_no)s, %(preferred_class)s, %(no_of_tickets)s, %(seat_no)s, %(date_of_purchase)s, %(age)s, %(status)s) RETURNING ticket_details.booking_id]
[parameters: {'mobile_no': 9876643430, 'preferred_class': 'Gold', 'no_of_tickets': 3, 'seat_no': "['23','34','65']", 'date_of_purchase': datetime.date(2023, 2, 13), 'age': 20, 'status': False}]
(Background on this error at: https://sqlalche.me/e/20/9h9h)
2023-02-13 16:37:59 - ERROR - [AnyIO worker thread:book_ticket():63] - (psycopg2.errors.InvalidTextRepresentation) invalid input syntax for type integer: "12,34"
LINE 1: ...chase, age, status) VALUES (775665220, 'Gold', 2, '12,34', '...
^
[SQL: INSERT INTO ticket_details (mobile_no, preferred_class, no_of_tickets, seat_no, date_of_purchase, age, status) VALUES (%(mobile_no)s, %(preferred_class)s, %(no_of_tickets)s, %(seat_no)s, %(date_of_purchase)s, %(age)s, %(status)s) RETURNING ticket_details.booking_id]
[parameters: {'mobile_no': 775665220, 'preferred_class': 'Gold', 'no_of_tickets': 2, 'seat_no': '12,34', 'date_of_purchase': datetime.date(2023, 2, 13), 'age': 12, 'status': False}]
(Background on this error at: https://sqlalche.me/e/20/9h9h)
2023-02-13 16:38:54 - ERROR - [AnyIO worker thread:book_ticket():63] - (psycopg2.errors.InvalidTextRepresentation) invalid input syntax for type integer: "12,13"
LINE 1: ...hase, age, status) VALUES (8877665544, 'Gold', 2, '12,13', '...
^
[SQL: INSERT INTO ticket_details (mobile_no, preferred_class, no_of_tickets, seat_no, date_of_purchase, age, status) VALUES (%(mobile_no)s, %(preferred_class)s, %(no_of_tickets)s, %(seat_no)s, %(date_of_purchase)s, %(age)s, %(status)s) RETURNING ticket_details.booking_id]
[parameters: {'mobile_no': 8877665544, 'preferred_class': 'Gold', 'no_of_tickets': 2, 'seat_no': '12,13', 'date_of_purchase': datetime.date(2023, 2, 13), 'age': 32, 'status': False}]
(Background on this error at: https://sqlalche.me/e/20/9h9h)
2023-02-13 16:41:49 - ERROR - [AnyIO worker thread:book_ticket():63] - (psycopg2.errors.InvalidTextRepresentation) invalid input syntax for type integer: "12,13"
LINE 1: ...chase, age, status) VALUES (223344550, 'Gold', 2, '12,13', '...
^
[SQL: INSERT INTO ticket_details (mobile_no, preferred_class, no_of_tickets, seat_no, date_of_purchase, age, status) VALUES (%(mobile_no)s, %(preferred_class)s, %(no_of_tickets)s, %(seat_no)s, %(date_of_purchase)s, %(age)s, %(status)s) RETURNING ticket_details.booking_id]
[parameters: {'mobile_no': 223344550, 'preferred_class': 'Gold', 'no_of_tickets': 2, 'seat_no': '12,13', 'date_of_purchase': datetime.date(2023, 2, 13), 'age': 20, 'status': False}]
(Background on this error at: https://sqlalche.me/e/20/9h9h)
2023-02-13 16:48:19 - ERROR - [AnyIO worker thread:book_ticket():63] - (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "ticket_details_mobile_no_key"
DETAIL: Key (mobile_no)=(9988776655) already exists.
[SQL: INSERT INTO ticket_details (mobile_no, preferred_class, no_of_tickets, seat_no, date_of_purchase, age, status) VALUES (%(mobile_no)s, %(preferred_class)s, %(no_of_tickets)s, %(seat_no)s, %(date_of_purchase)s, %(age)s, %(status)s) RETURNING ticket_details.booking_id]
[parameters: {'mobile_no': 9988776655, 'preferred_class': 'Gold', 'no_of_tickets': 2, 'seat_no': '[11, 12]', 'date_of_purchase': datetime.date(2023, 2, 13), 'age': 20, 'status': False}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2023-02-13 17:09:37 - ERROR - [AnyIO worker thread:book_ticket():61] - (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "ticket_details_mobile_no_key"
DETAIL: Key (mobile_no)=(9988776655) already exists.
[SQL: INSERT INTO ticket_details (mobile_no, preferred_class, no_of_tickets, seat_no, date_of_purchase, age, status) VALUES (%(mobile_no)s, %(preferred_class)s, %(no_of_tickets)s, %(seat_no)s, %(date_of_purchase)s, %(age)s, %(status)s) RETURNING ticket_details.booking_id]
[parameters: {'mobile_no': 9988776655, 'preferred_class': 'Gold', 'no_of_tickets': 2, 'seat_no': '6768', 'date_of_purchase': datetime.date(2023, 2, 13), 'age': 30, 'status': False}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2023-02-13 17:15:59 - ERROR - [AnyIO worker thread:delete_row():30] - 'str' object has no attribute 'spit'
2023-02-13 17:20:23 - ERROR - [AnyIO worker thread:delete_row():31] - 'str' object has no attribute 'spit'
2023-02-13 17:32:39 - ERROR - [AnyIO worker thread:delete_row():32] - 'str' object has no attribute 'spit'
2023-02-13 17:33:45 - ERROR - [AnyIO worker thread:delete_row():28] - Ticket with id 10 is not exist
2023-02-13 17:33:45 - ERROR - [AnyIO worker thread:delete_row():32] - 'NoneType' object has no attribute 'seat_no'
2023-02-13 17:34:21 - ERROR - [AnyIO worker thread:delete_row():27] - Ticket with id 10 is not exist
2023-02-13 17:34:21 - ERROR - [AnyIO worker thread:delete_row():31] - 'NoneType' object has no attribute 'seat_no'
2023-02-13 17:37:02 - ERROR - [AnyIO worker thread:delete_row():24] - Ticket with id 8 is not exist
2023-02-13 17:37:02 - ERROR - [AnyIO worker thread:delete_row():28] - 'NoneType' object has no attribute 'seat_no'
2023-02-13 17:45:20 - ERROR - [AnyIO worker thread:delete_row():29] - 'str' object has no attribute 'spit'
2023-02-13 17:47:49 - ERROR - [AnyIO worker thread:delete_row():30] - 'str' object has no attribute 'spit'
2023-02-13 17:49:44 - ERROR - [AnyIO worker thread:delete_row():30] - 'str' object has no attribute 'spit'
2023-02-13 17:52:15 - ERROR - [AnyIO worker thread:delete_row():32] - 'str' object has no attribute 'spit'
2023-02-13 17:54:21 - ERROR - [AnyIO worker thread:delete_row():32] - 'str' object has no attribute 'spit'
2023-02-13 18:47:50 - ERROR - [AnyIO worker thread:delete_row():26] - Ticket with id 19 is not exist
2023-02-14 14:13:54 - ERROR - [AnyIO worker thread:delete_row():29] - type object 'Ticket' has no attribute 'status'
2023-02-14 14:14:54 - ERROR - [AnyIO worker thread:delete_row():29] - type object 'Ticket' has no attribute 'status'
2023-02-14 14:16:47 - ERROR - [AnyIO worker thread:delete_row():29] - type object 'Ticket' has no attribute 'status'
2023-02-14 15:09:33 - ERROR - [AnyIO worker thread:get_details():81] - index 0 is out of bounds for axis 0 with size 0
2023-02-14 15:56:34 - ERROR - [AnyIO worker thread:book_ticket():51] - local variable 'key' referenced before assignment
2023-02-14 16:08:50 - ERROR - [AnyIO worker thread:book_ticket():51] - (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "ticket_details_mobile_no_key"
DETAIL: Key (mobile_no)=(8989898989) already exists.
[SQL: INSERT INTO ticket_details (mobile_no, preferred_class, no_of_tickets, seat_no, date_of_purchase, age, deleted) VALUES (%(mobile_no)s, %(preferred_class)s, %(no_of_tickets)s, %(seat_no)s, %(date_of_purchase)s, %(age)s, %(deleted)s) RETURNING ticket_details.booking_id]
[parameters: {'mobile_no': 8989898989, 'preferred_class': 'Gold', 'no_of_tickets': 1, 'seat_no': '25', 'date_of_purchase': datetime.datetime(2023, 2, 14, 16, 8, 7, 834305), 'age': 21, 'deleted': False}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2023-02-15 10:47:39 - ERROR - [AnyIO worker thread:book_ticket():58] - module 'paho.mqtt' has no attribute 'Client'
2023-02-15 10:52:32 - ERROR - [AnyIO worker thread:book_ticket():58] - 'Film_Ticket' object has no attribute 'preferred_class'
2023-02-15 11:00:37 - ERROR - [AnyIO worker thread:book_ticket():58] -
2023-02-15 11:09:30 - ERROR - [AnyIO worker thread:book_ticket():58] -
2023-02-15 11:16:46 - ERROR - [AnyIO worker thread:book_ticket():59] - 'Film_Ticket' object has no attribute 'seat_numbers'
2023-02-15 11:19:41 - ERROR - [AnyIO worker thread:book_ticket():59] - 'Film_Ticket' object has no attribute 'no_of_ticket'
2023-02-15 11:21:27 - ERROR - [AnyIO worker thread:delete_row():35] - name 'json' is not defined
2023-02-15 11:44:32 - ERROR - [AnyIO worker thread:book_ticket():60] -
2023-02-15 11:50:32 - ERROR - [AnyIO worker thread:book_ticket():60] -
2023-02-15 11:55:03 - ERROR - [AnyIO worker thread:book_ticket():60] - unsupported operand type(s) for /: 'str' and 'str'
2023-02-15 11:56:57 - ERROR - [AnyIO worker thread:book_ticket():60] - unsupported operand type(s) for /: 'str' and 'str'
2023-02-15 11:58:17 - ERROR - [AnyIO worker thread:book_ticket():60] -
2023-02-15 12:01:07 - ERROR - [AnyIO worker thread:book_ticket():60] - (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "ticket_details_mobile_no_key"
DETAIL: Key (mobile_no)=(909878999) already exists.
[SQL: INSERT INTO ticket_details (mobile_no, preferred_class, no_of_tickets, seat_no, date_of_purchase, age, deleted) VALUES (%(mobile_no)s, %(preferred_class)s, %(no_of_tickets)s, %(seat_no)s, %(date_of_purchase)s, %(age)s, %(deleted)s) RETURNING ticket_details.booking_id]
[parameters: {'mobile_no': 909878999, 'preferred_class': 'silver', 'no_of_tickets': 1, 'seat_no': '10', 'date_of_purchase': datetime.datetime(2023, 2, 15, 11, 59, 11, 327369), 'age': 43, 'deleted': False}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2023-02-15 12:21:17 - ERROR - [AnyIO worker thread:book_ticket():60] - (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "ticket_details_mobile_no_key"
DETAIL: Key (mobile_no)=(0) already exists.
[SQL: INSERT INTO ticket_details (mobile_no, preferred_class, no_of_tickets, seat_no, date_of_purchase, age, deleted) VALUES (%(mobile_no)s, %(preferred_class)s, %(no_of_tickets)s, %(seat_no)s, %(date_of_purchase)s, %(age)s, %(deleted)s) RETURNING ticket_details.booking_id]
[parameters: {'mobile_no': 0, 'preferred_class': 'gold', 'no_of_tickets': 1, 'seat_no': '90', 'date_of_purchase': datetime.datetime(2023, 2, 15, 12, 18, 27, 311098), 'age': 2, 'deleted': False}]
(Background on this error at: https://sqlalche.me/e/20/gkpj)
2023-02-15 12:31:45 - ERROR - [AnyIO worker thread:book_ticket():60] -
2023-02-15 12:32:55 - ERROR - [AnyIO worker thread:book_ticket():60] -
2023-02-15 12:53:28 - ERROR - [AnyIO worker thread:book_ticket():59] -
2023-02-15 14:08:42 - ERROR - [AnyIO worker thread:book_ticket():59] -
2023-02-15 14:13:19 - ERROR - [AnyIO worker thread:book_ticket():59] -
2023-02-15 14:14:14 - ERROR - [AnyIO worker thread:book_ticket():59] -
2023-02-15 14:20:51 - ERROR - [AnyIO worker thread:book_ticket():59] -
import logging
import os
from logging.handlers import RotatingFileHandler
from scripts.config.application_config import file_name
def get_logger():
"""
Creates a rotating log
"""
__logger__ = logging.getLogger('')
__logger__.setLevel("ERROR")
log_formatter = '%(asctime)s - %(levelname)-6s - [%(threadName)5s:%(funcName)5s():%(lineno)s] - %(message)s'
time_format = "%Y-%m-%d %H:%M:%S"
formatter = logging.Formatter(log_formatter, time_format)
log_file = os.path.join(f"{file_name}_ERROR.log")
temp_handler = RotatingFileHandler(log_file,
maxBytes=100000000,
backupCount=5)
temp_handler.setFormatter(formatter)
__logger__.addHandler(temp_handler)
return __logger__
logger = get_logger()
from fastapi import APIRouter
from scripts.constants.end_points import EndPoints
from scripts.core.handlers.delete_ticket import db_handler
delete_ticket = APIRouter()
@delete_ticket.post(EndPoints.delete_a_ticket, tags=["delete a ticket"])
def delete_tickets(tid: int):
res = db_handler.delete_row(tid)
return {f'tickets {res} deleted'}
@delete_ticket.get(EndPoints.cancel_all_tickets, tags=["cancel show"])
async def cancel_all_tickets():
db_handler.cancel_tickets()
return {"Message": "Cancelled all Tickets"}
from fastapi import APIRouter
from scripts.config.redis_connection import conn
from scripts.constants.end_points import EndPoints
from scripts.core.handlers.book_ticket import BookingDetails, BookTicket
from scripts.core.handlers.create_redis_db import redis_db_create
from scripts.core.handlers.get_all_the_data import seat_availability
from scripts.database.schema import FilmTicket
from scripts.logging.logging import logger
router = APIRouter()
@router.get(EndPoints.root, tags=["root"])
def root():
return {"data": "ticket booking task"}
@router.get(EndPoints.show_begin, tags=["Show begin"])
def generate_seats():
try:
redis_db_create(conn, "gold", 30, 300)
redis_db_create(conn, "silver", 25, 125)
return "booking started"
except Exception as e:
logger.error(e)
print(e)
@router.get(EndPoints.seat_availability,tags=["check seat availability"])
def check_seats(ticket_class: str):
message = seat_availability(conn, ticket_class)
return message
@router.post(EndPoints.book_ticket, tags=["book tickets"])
def book_ticket(ticket: FilmTicket):
try:
return BookTicket.book_ticket(ticket)
except Exception as e:
print(e)
logger.error(e)
@router.get(EndPoints.get_booking_details, tags=["get booking details"])
def get_booking_details():
try:
BookingDetails.get_details()
return {"data": "list all the data"}
except Exception as e:
logger.error(e)
print(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