Exemplo n.º 1
0
def get_tickets_and_sections_by_price():
    jsonData = request.get_json()

    sqlHandler = SqlHandler(mysql)
    event_id = jsonData['eventID']
    aisleSeat = jsonData['aisleSeat']
    earlyAccess = jsonData['earlyAccess']
    handicap = jsonData['handicap']
    desiredNumberTickets = jsonData['desiredNumberTickets']
    priceMode = jsonData['priceMode']
    minPrice = jsonData['priceRange']['min']
    maxPrice = jsonData['priceRange']['max']

    tickets = sqlHandler.get_tickets_by_price(event_id, aisleSeat, earlyAccess,
                                              handicap, desiredNumberTickets,
                                              priceMode, minPrice, maxPrice)

    if tickets:
        sections = []
        my_set = None
        for ticket in tickets:
            sections.append(ticket['section_number'])

        my_set = set(sections)
        sections = list(my_set)

        return jsonify({'tickets': tickets, 'sections': sections})
    else:
        return jsonify({'tickets': False})
Exemplo n.º 2
0
def search_tickets_in_sections_with_filter():
    sqlHandler = SqlHandler(mysql)
    jsondata = request.get_json()
    event_id = jsondata['eventID']
    sections = jsondata['sections']

    minPrice = jsondata['minPrice']
    maxPrice = jsondata['maxPrice']

    aisleSeat = jsondata['aisleSeat']
    earlyAccess = jsondata['earlyAccess']
    handicap = jsondata['handicap']

    desiredNumberTickets = jsondata['desiredNumberTickets']

    tickets = sqlHandler.get_tickets_in_sections_with_filter(
        event_id, sections, minPrice, maxPrice, aisleSeat, earlyAccess,
        handicap, desiredNumberTickets)

    sections = []
    my_set = None
    for ticket in tickets:
        sections.append(ticket['section_number'])

    my_set = set(sections)
    sections = list(my_set)

    return jsonify({'tickets': tickets, 'sections': sections})
Exemplo n.º 3
0
def get_games_with_details():
    if 'application/json' in request.headers.environ['CONTENT_TYPE']:
        jsonData = request.get_json()
        sqlHandler = SqlHandler(mysql)
        eventDetails = sqlHandler.get_games_with_details(
            jsonData['start'], jsonData['end'])
        return jsonify({'eventDetails': eventDetails})
Exemplo n.º 4
0
def create_transaction():
    sqlHandler = SqlHandler(mysql)
    jsonData = request.get_json()
    jwt_service = JWTService()

    buyer_id = jwt_service.get_account(jsonData['token'])
    event_id = jsonData['eventID']
    tickets = jsonData['tickets']
    commission = jsonData['commission']
    tax = jsonData['tax']
    subtotal = jsonData['subtotal']
    total = jsonData['total']
    group_id = jsonData['group_id']
    tax_per_ticket = jsonData['taxPerTicket']
    comm_per_ticket = jsonData['commPerTicket']
    subtotal_per_ticket = jsonData['subtotalPerTicket']

    success = sqlHandler.create_transaction(buyer_id, tickets, commission, tax,
                                            subtotal, total, group_id,
                                            tax_per_ticket, comm_per_ticket,
                                            subtotal_per_ticket)
    if success:
        event_info = sqlHandler.get_event_info(event_id)
        phone_num, email = sqlHandler.get_seller_email_and_phone(group_id)
        thr = threading.Thread(target=TTTEmailClient.send_sale_confirmation,
                               args=(email, event_info, tickets, commission,
                                     tax, subtotal, total))
        thr.start()

    return jsonify({'success': success})
Exemplo n.º 5
0
    def createListing(self):
        sqlHandler = SqlHandler(self.mysql)
        jwt_service = JWTService()
        jsonData = self.json

        sectionNum = jsonData['section']
        rowNum = jsonData['row']
        seatsInfo = jsonData['seatsInfo']
        ticketPrice = jsonData['ticketPrice']
        numberOfTickets = jsonData['numberOfTickets']
        minPurchaseSize = jsonData['minPurchaseSize']
        gameDate = jsonData['dbGameDate']
        accountID = jwt_service.get_account(jsonData['token'])

        ticketIds = sqlHandler.insert_ticket_listing(sectionNum, rowNum,
                                                     seatsInfo, ticketPrice,
                                                     numberOfTickets,
                                                     minPurchaseSize, gameDate,
                                                     accountID)

        print(ticketIds)

        mysqlInsertSuccess = False

        if (ticketIds):
            mysqlInsertSuccess = True

        fileUploadSuccess = self.pdfworker.splitPDF(self.file, ticketIds)
        #fileUploadSuccess = True

        return mysqlInsertSuccess and fileUploadSuccess
Exemplo n.º 6
0
def get_account_info():
    if 'application/json' in request.headers.environ['CONTENT_TYPE']:
        jsonData = request.get_json()
        try:
            jwt_service = JWTService()
            account_id = jwt_service.get_account(jsonData['token'])
            sqlHandler = SqlHandler(mysql)
            return jsonify(sqlHandler.get_account_info(account_id))
        except Exception as e:
            return jsonify({'authenticated': False})
Exemplo n.º 7
0
def get_buyer_purchases():
    jsonData = request.get_json()
    try:
        jwt_service = JWTService()
        account_id = jwt_service.get_account(jsonData['token'])
        sqlHandler = SqlHandler(mysql)
        transactions = sqlHandler.get_buyer_transactions(account_id)
        return jsonify({'purchases': transactions, 'authenticated': True})
    except Exception as e:
        print(e)
        return jsonify({'authenticated': False})
Exemplo n.º 8
0
def hold_tickets():
    jsonData = request.get_json()
    try:
        jwt_service = JWTService()
        account_id = jwt_service.get_account(jsonData['token'])
        sqlHandler = SqlHandler(mysql)
        result = sqlHandler.hold_tickets(account_id, jsonData['ticketIds'])
        return jsonify({'authenticated': result, 'timer': 30000})  # 5 minutes
    except Exception as e:
        print(e)
        return jsonify({'authenticated': False})
Exemplo n.º 9
0
 def verify_credentials(self, account):
     sqlHandler = SqlHandler(self.mysql)
     loginResultDict = {'authenticated': False}
     try :
         loginResultDict = sqlHandler.verify_credentials(account.email, account.password)
         if (loginResultDict['authenticated']):
             jwt_token = jwt_service.encode_auth_token(loginResultDict['account_id'])
             loginResultDict['token'] = jwt_token.decode('utf-8')
     except Exception as e:
         print(e)
     return loginResultDict
Exemplo n.º 10
0
def unlock_tickets():
    jsonData = request.get_json()
    try:
        jwt_service = JWTService()
        #account_id = jwt_service.get_account(jsonData['token'])
        sqlHandler = SqlHandler(mysql)
        result = sqlHandler.unlock_tickets(jsonData['ticketIds'])
        return jsonify({'authenticated': result})  #
    except Exception as e:
        print(e)
        return jsonify({'authenticated': False})
Exemplo n.º 11
0
def validateTicketInfo():
    jsonData = request.get_json()
    sectionNum = jsonData['sectionNum']
    rowNum = jsonData['rowNum']
    seatNums = jsonData['seatNums']
    gameDate = jsonData['gameDate']

    sqlHandler = SqlHandler(mysql)
    ticketInfoResults = sqlHandler.validate_ticket_info(
        sectionNum, rowNum, seatNums, gameDate)
    return jsonify({'ticketInfoResults': ticketInfoResults})
Exemplo n.º 12
0
    def confirm_registration(self, data):
        registerResult = {'registrationStatus': True}
        registrationID = data['registrationID']
        sqlHandler = SqlHandler(self.mysql)
        success = sqlHandler.get_account_for_confirmation(registrationID)

        if not success:
            registerResult['errorMessage'] = ERROR_MESSAGES[
                'REGISTRATION_CONFIRM_ERROR']
            registerResult['registrationStatus'] = False

        return registerResult
Exemplo n.º 13
0
class DataHandler:
    def __init__(self, openrouteservice_api_key):
        self._database = SqlHandler()
        self._openrouteservice_handler = OpenRouteServiceHandler(
            openrouteservice_api_key)

    def close(self):
        self._database.close()

    def get_values_between_cities(self, city_1: str, city_2: str,
                                  option: str) -> float:

        for city in [city_1, city_2]:
            self.get_coordinates_from_city(
                city)  # insert into database if not already existing

        if not self._database.get_value(city_1, city_2, option):
            self._load_and_save_distance_and_duration(city_1, city_2)

        return self._database.get_value(city_1, city_2, option)

    def _load_and_save_distance_and_duration(self, city_1: str,
                                             city_2: str) -> None:
        coordinates_1 = self._database.get_coordinates_from_city(city_1)
        coordinates_2 = self._database.get_coordinates_from_city(city_2)
        distance, duration = self._openrouteservice_handler. \
            get_distance_duration_between_cities(coordinates_1,
                                                 coordinates_2)
        self._database.set_distance_duration(city_1, city_2, distance,
                                             duration)

    def get_coordinates_from_city(self, city: str) -> Coordinates:
        coordinates = self._database.get_coordinates_from_city(city)
        if not self._check_if_coordinates_are_valid(coordinates):
            coordinates = self._load_and_save_new_coordinates(city)

        return coordinates

    def _load_and_save_new_coordinates(self, city: str) -> Coordinates:
        coordinates = self._openrouteservice_handler.get_coordinate_of_city(
            city)
        self._database.set_coordinates_from_city(city, coordinates.longitude,
                                                 coordinates.latitude)
        return coordinates

    @staticmethod
    def _check_if_coordinates_are_valid(coordinates: Coordinates) -> bool:
        return not (coordinates.longitude == 0 and coordinates.latitude == 0)
Exemplo n.º 14
0
def get_seller_listings():
    jsonData = request.get_json()
    try:
        jwt_service = JWTService()
        account_id = jwt_service.get_account(jsonData['token'])
        sqlHandler = SqlHandler(mysql)
        transactions = sqlHandler.get_seller_transactions(account_id)
        listings = sqlHandler.get_seller_tickets(account_id)
        # Concatenate the two arrays into one listings array to be consumed by frontend page
        return jsonify({
            'listings': listings + transactions,
            'authenticated': True
        })
    except Exception as e:
        print(e)
        return jsonify({'authenticated': False})
Exemplo n.º 15
0
def search_tickets_in_zone_with_filter():
    sqlHandler = SqlHandler(mysql)
    jsonData = request.get_json()

    event_id = jsonData['eventID']
    section_type_id = jsonData['section_type_id']

    minPrice = jsonData['minPrice']
    maxPrice = jsonData['maxPrice']

    aisleSeat = jsonData['aisleSeat']
    earlyAccess = jsonData['earlyAccess']
    handicap = jsonData['handicap']

    desiredNumberTickets = jsonData['desiredNumberTickets']

    tickets = sqlHandler.get_tickets_in_section_type_with_filter(
        event_id, section_type_id, minPrice, maxPrice, aisleSeat, earlyAccess,
        handicap, desiredNumberTickets)
    return jsonify({'tickets': tickets})
Exemplo n.º 16
0
def sendTicketsPDF():
    if 'application/json' in request.headers.environ['CONTENT_TYPE']:
        jsonData = request.get_json()
        jwt_service = JWTService()
        sqlHandler = SqlHandler(mysql)
        try:
            accountID = jwt_service.get_account(jsonData['token'])
            email = sqlHandler.get_user_email(accountID)

            ticketIds = jsonData['ticketIds']
            outputPDF = pdfworker.getCombinedPDF(ticketIds)
            outputPDFName = "Tickets.pdf"

            thr = threading.Thread(
                target=TTTEmailClient.send_combined_ticket_file,
                args=(email, outputPDF, outputPDFName))
            thr.start()
        except Exception as e:
            print(e)
            return jsonify({'success': False})
    else:
        return requestNotSupported()
    return jsonify({'success': True})
Exemplo n.º 17
0
def all_teams():
    sqlHandler = SqlHandler(mysql)
    teams = sqlHandler.get_all_teams()
    return jsonify({'teams': teams})
Exemplo n.º 18
0
import pandas as pd
from sql_handler import SqlHandler
import os

script_path = os.getcwd()
data = pd.read_csv(script_path + '/eurofxref-hist.csv')

columns = [col + ' numeric' for col in data.columns[1:4]]
columns = ',\n'.join(columns)

print(columns)
# data = pd.read_csv(script_path + '/eurofxref-hist.csv')
# print(data.head(5))

sql = SqlHandler()
# sql.drop_table()
# sql.create_table(columns)
sql.copy_csv_into_table(data)
def unit_under_test(mocker):
    return SqlHandler()
Exemplo n.º 20
0
def get_fees():
    jsonData = request.get_json()
    sqlHandler = SqlHandler(mysql)
    percentages = sqlHandler.get_fees()
    return jsonify({'percentages': percentages})
Exemplo n.º 21
0
 def check_for_email(self, email):
     sqlHandler = SqlHandler(self.mysql)
     existingAccount = sqlHandler.check_for_email(email)
     if existingAccount > 0:
         return True
     return False
Exemplo n.º 22
0
def get_country_names():
    sqlHandler = SqlHandler(mysql)
    countries = sqlHandler.get_country_names()
    return jsonify({'country': countries})
Exemplo n.º 23
0
def get_country_states():
    jsonData = request.get_json()
    country_id = jsonData['countryID']
    sqlHandler = SqlHandler(mysql)
    stateNames = sqlHandler.get_country_states(country_id)
    return jsonify({'stateNames': stateNames})
Exemplo n.º 24
0
def game_dates():
    sqlHandler = SqlHandler(mysql)
    date = sqlHandler.get_game_dates()
    return jsonify({'date': date})
Exemplo n.º 25
0
def get_opponent_by_date():
    jsonData = request.get_json()
    date = jsonData['gameDate']
    sqlHandler = SqlHandler(mysql)
    opponentName = sqlHandler.get_opponent_by_date(date)
    return jsonify({'opponentName': opponentName})
Exemplo n.º 26
0
def get_group_of_tickets():
    jsonData = request.get_json()
    sqlHandler = SqlHandler(mysql)
    group_id = jsonData['group_id']
    tickets = sqlHandler.get_group(group_id)
    return jsonify({'tickets': tickets})
Exemplo n.º 27
0
 def insert_account_registration(self, account):
     registrationID = uuid.uuid4().hex
     sqlHandler = SqlHandler(self.mysql)
     sqlHandler.insert_account_registration(account, registrationID)
     return registrationID
Exemplo n.º 28
0
def get_event():
    jsondata = request.get_json()
    eventID = jsondata['eventID']
    sqlHandler = SqlHandler(mysql)
    event = sqlHandler.get_event(eventID)
    return jsonify({'event': event})
Exemplo n.º 29
0
def get_games_list():
    sqlHandler = SqlHandler(mysql)
    games = sqlHandler.get_teams_for_games()
    return jsonify({'games': games})
Exemplo n.º 30
0
def games_by_team():
    sqlHandler = SqlHandler(mysql)
    jsondata = request.get_json()
    team_id = jsondata['team_id']
    games = sqlHandler.get_games_by_team(team_id)
    return jsonify({'games': games})