Commit 15f3c7ec by rakesh.pv

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

parent a43f220d
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)
# 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)
from scripts.database.postgresql.model import Base
from scripts.logging.logger import logger
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from scripts.config.application_config import postgres_uri
def db_connect():
try:
engine = create_engine(postgres_uri)
sessions = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base.metadata.create_all(engine)
session = sessions()
return session
except Exception as e:
logger.error(e)
from datetime import date
from sqlalchemy import Column, Integer, String, Date, Boolean, BIGINT
from sqlalchemy.orm import declarative_base
from scripts.config.application_config import table_name
Base = declarative_base()
# create BookingDetails class
class BookingDetails(Base):
__tablename__ = table_name
booking_id = Column(Integer, primary_key=True)
mobile_no = Column(BIGINT)
preferred_class = Column(String)
no_of_tickets = Column(Integer)
seat_numbers = Column(String)
date_of_purchase = Column(Date, default=date.today())
age = Column(Integer)
deleted = Column(Boolean, default=False)
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