Commit fd13b4c5 by rakesh.pv

publish part

parent 7d02d3f7
from fastapi import FastAPI, Header, HTTPException
import paho.mqtt.client as mqtt
from fastapi import FastAPI, HTTPException
from check import seat_availability, check_seat_avail
from redis_connction import conn
app = FastAPI()
def on_connect(client, userdata, flags, rc):
print("Connected with result code " + str(rc))
client.subscribe("ticket_booking")
def on_message(client, userdata, msg):
print(msg.topic + " " + str(msg.payload))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("192.168.0.220", 1883, 60)
app = FastAPI()
booked_seats = []
@app.get("/class_availabilty")
async def check_seat():
x = input(" enter classs gold or silver")
if x == "Gold":
aa = seat_availability(conn, "Gold")
return aa
@app.post("/book_ticket")
async def book_ticket(
class_type: str,
number_of_tickets: int,
seat_numbers: list[int],
user_name: str,
user_age: int,
user_phone: int,
):
if class_type not in ["gold", "silver"]:
raise HTTPException(status_code=400, detail="Invalid class type")
if len(seat_numbers) != number_of_tickets:
raise HTTPException(status_code=400, detail="Number of seat numbers must match the number of tickets")
#
for seat_number in seat_numbers:
if seat_number not in booked_seats:
print("""ddsd""")
aa = check_seat_avail(conn, class_type, seat_number)
print("result is ", aa)
if not aa:
booked_seats.append(seat_number)
print(booked_seats)
if booked_seats:
raise HTTPException(status_code=400, detail=f"Seat number {booked_seats} is already booked")
booked_seats.pop()
# payload = {class_type: [seat_numbers]}
# client.publish("ticket", str(payload))
# client.subscribe("ticket/#")
return {"message": "Ticket booking successful"}
import uvicorn
if __name__ == '__main__':
uvicorn.run("scripts.core.services.main:app",reload=True)
\ No newline at end of file
import pickle
from redis_connction import conn
from scripts.database.redis.redis_connction import conn
def redis_db_create(connection, ticket_class, seats, total_count):
......
import paho.mqtt.client as mqtt
def on_connect(client, userdata, flags, rc):
print("Connected with result code " + str(rc))
client.subscribe("ticket_booking")
def on_message(client, userdata, msg):
print(msg.topic + " " + str(msg.payload))
client = mqtt.Client()
client.on_connect = on_connect
client.on_message = on_message
client.connect("192.168.0.220", 1883, 60)
from fastapi import FastAPI, HTTPException
from scripts.core.handlers.check_availablity import seat_availability, check_seat_avail
from scripts.database.redis.redis_connction import conn
app = FastAPI()
booked_seats = []
@app.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
@app.post("/book_ticket")
async def book_ticket(
class_type: str,
number_of_tickets: int,
seat_numbers: list[int],
user_name: str,
user_age: int,
user_phone: int,
):
if class_type not in ["gold", "silver"]:
raise HTTPException(status_code=400, detail="Invalid class type")
if len(seat_numbers) != number_of_tickets:
raise HTTPException(status_code=400, detail="Number of seat numbers must match the number of tickets")
#
for seat_number in seat_numbers:
if seat_number not in booked_seats:
print("""ddsd""")
aa = check_seat_avail(conn, class_type, seat_number)
print("result is ", aa)
if not aa:
booked_seats.append(seat_number)
print(booked_seats)
if booked_seats:
raise HTTPException(status_code=400,
detail=f"Seat number that are already booked are : {booked_seats} \n"
f"seat number you are going to book are {seat_numbers}")
booked_seats.pop()
payload = {class_type: seat_numbers}
client.publish("ticket", str(payload))
client.subscribe("ticket/#")
return {"message": "Ticket booking successful"}
from pydantic import BaseModel
class user(BaseModel):
class_type: str
number_of_tickets: int
seat_numbers: list[int]
user_name: str
user_age: int
user_phone: int
import pickle
from redis_connction import conn
from scripts.database.redis.redis_connction import conn
g = pickle.loads(conn.get("Gold"))
g[0][1] = 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