Commit a43f220d by rakesh.pv

1. take input : check in redis : publish to mqtt:store in psl done

parent d7e04952
......@@ -7,10 +7,10 @@ try:
broker = config.get("MQTT_Connection", "broker")
mqtt_port = config.get("MQTT_Connection", "port")
host = config.get("redis_connection", "host")
redis_port = config.get("redis_connection", "redis_port")
table_name = "ticket_details"
postgres_uri = "postgresql://postgres:test@localhost/theater_db"
except Exception as e:
print("Exception-", e)
import json
import paho.mqtt.client as mqtt
import pandas as pd
from fastapi import HTTPException
from scripts.core.handlers.check_availablity import check_seat_avail
from scripts.core.handlers.deleta_all_data import clean_record
from scripts.database.redis.redis_connction import conn
from scripts.model.sql_model import BookingDetails
class Tickets:
......@@ -39,3 +42,16 @@ class Tickets:
return {"message": "Ticket booking successful"}
except Exception as e:
return e
def get_details(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)
print("-------------------------------Booking Details-------------------------------")
print(df)
# Use pandas to save the DataFrame to an Excel file
df.to_excel('temp/booking_details.xlsx', index=False)
except Exception as e:
print(e)
import pickle
from scripts.core.handlers.display_all_seats_in_hall import data_decode, create_json_view
def seat_availability(connection, ticket_class):
try:
if ticket_class == "Gold":
class_list = pickle.loads(connection.get("Gold"))
elif ticket_class == "Silver":
class_list = pickle.loads(connection.get("Silver"))
# 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 None
data = {}
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
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)
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"))
"gold": pickle.loads(connection.get("gold")),
"silver": pickle.loads(connection.get("silver"))
}
print(seats_needed)
# get the availability of seat
if ticket_class not in class_lists:
return None
flag = 0
......@@ -33,3 +73,5 @@ def check_seat_avail(connection, ticket_class, seats_needed):
return True
if flag == 0:
return False
except Exception as e:
print(e)
......@@ -2,6 +2,7 @@ from fastapi import APIRouter
from scripts.core.handlers.book_cinema_tickets import Tickets
from scripts.core.handlers.check_availablity import seat_availability
from scripts.core.handlers.make_redis_db import redis_db_create
from scripts.database.redis.redis_connction import conn
from scripts.model.user_model import user
......@@ -13,15 +14,21 @@ async def index():
return " cinema hall is working"
@router.get("/class_availabilty")
async def check_seat():
x = input(" enter classs gold or silver")
if x == "Gold":
aa = seat_availability(conn, "Gold")
return aa
if x == "Silver":
aa = seat_availability(conn, "Silver")
return aa
@router.get("/set_seats_in_halls", tags=["setting seats in two classes"])
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:
print(e)
@router.get("/check_seats_from_database")
def check_seats(ticket_class: str):
message = seat_availability(conn, ticket_class)
return message
@router.post("/book_cinema_ticket")
......@@ -32,3 +39,14 @@ async def book_cinema_ticket(details: user):
except Exception as e:
print("error ", e)
@router.get("/get_booking_details", tags=["get booking details"])
def get_booking_details():
try:
Tickets.get_details()
return {"data": "list all the data"}
except Exception as e:
print(e)
......@@ -2,4 +2,4 @@ import redis
from scripts.config.application_config import host, redis_port
conn = redis.Redis(host, redis_port, db=0)
conn = redis.Redis("127.0.0.1", 6379, db=0)
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