Commit b8e7b169 by arjun.b

first commit

parents
# 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
<?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
\ No newline at end of file
import uvicorn
from fastapi import FastAPI
from scripts.logging.logging import logger
from scripts.services.publish import router
app = FastAPI()
app.include_router(router)
if __name__ == "__main__":
try:
uvicorn.run(app, port=8765)
except Exception as e:
logger.error(e)
print(e)
import configparser
try:
config = configparser.ConfigParser()
config.read(r"conf\app.conf")
# logging file path
file_name = config.get("log_file_path1", "file_name")
except configparser.NoOptionError as e:
print(f"could not find conf file {e}")
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker, declarative_base, Session
from scripts.logging.logging import logger
def db_connect():
try:
engine = create_engine("postgresql://postgres:123@localhost/ticket")
Session=sessionmaker(autocommit=False, autoflush=False, bind=engine)
session = Session()
return session
except Exception as e:
logger.error(e)
print(e)
class EndPoints:
root="/"
publish="/"
\ No newline at end of file
from scripts.constants.db_connect import db_connect
from scripts.database.model import Ticket
from scripts.logging.logging import logger
import redis
import pickle
class Book_Ticket:
@staticmethod
def book_ticket(ticket):
try:
# gold_row = 10
# gold_seat_per_row = 30
# silver_row = 5
# silver_seat_per_row = 25
booking = []
r = redis.Redis(host='localhost', port=6379, db=3)
# Check the availability of seats in the preferred class
if ticket.pref_class == 'Gold':
total_rows = 10
total_seats_per_row = 30
key = 'gold_class_seats'
elif ticket.pref_class == 'Silver':
total_rows = 5
total_seats_per_row = 25
key = 'silver_class_seats'
# Get the current seat availability
seat_availability = r.get(key)
if seat_availability:
seat_availability = int(seat_availability)
else:
seat_availability = total_rows * total_seats_per_row
r.set(key, seat_availability)
# Check if there are enough seats available
if seat_availability >= ticket.no_of_ticket:
seat_numbers = []
for i in range(ticket.no_of_ticket):
seat_numbers.append(f'{ticket.pref_class}-{seat_availability - i}')
r.decr(key, ticket.no_of_ticket)
# save ticket details to database
save_ticket = Ticket(
mobile_no=ticket.mobile_no,
pref_class=ticket.pref_class,
no_of_ticket=ticket.no_of_ticket,
age=ticket.age
)
session = db_connect()
session.add(save_ticket)
r.hset(ticket.pref_class, pickle.loads(save_ticket))
session.commit()
booking.append(ticket)
print("ticket booked successfully")
except Exception as e:
logger.error(e)
print(e)
from sqlalchemy import Column, String, Integer, text
from sqlalchemy.orm import declarative_base
Base = declarative_base()
class Ticket(Base):
__tablename__ = "ticket_details"
# id = Column(Integer, primary_key=True, server_default=text("SERIAL"))
mobile_no = Column(String, primary_key=True, unique=True, index=True)
pref_class = Column(String)
no_of_ticket = Column(Integer)
age = Column(Integer)
from pydantic import BaseModel
class Film_Ticket(BaseModel):
mobile_no: int
pref_class: str
no_of_ticket: int
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'
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.book_ticket import Book_Ticket
from scripts.database.schema import Film_Ticket
router = APIRouter()
@router.get(EndPoints.root, tags=["root"])
def root():
return {"data": "ticket booking task"}
@router.post("/book ticket", tags=["book tickets"])
def book_ticket(ticket: Film_Ticket):
Book_Ticket.book_ticket(ticket)
return {"data": "ticket booked successfully"}
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