Ejemplo n.º 1
0
def add_iata_to_db(iata):
    if db_session.query(IATA).filter_by(code=iata).count() == 0:
        iata_model = IATA(code=iata)
        db_session.add(iata_model)
        db_session.commit()
        return iata_model
    else:
        return db_session.query(IATA).filter_by(code=iata)[0]
Ejemplo n.º 2
0
def create(args: CreateParams):
    hotels = Hotels(name=args.name,
                    address=args.address,
                    created_at=datetime.now(),
                    updated_at=datetime.now())
    db_session.add(hotels)
    db_session.commit()
    db_session.refresh(hotels)
    return hotels
Ejemplo n.º 3
0
def queue_partner_emails():
    try:
        users = db_session.query(Users).filter(
            Users.wants_emails == True).all()
        for user in users:
            print("Sending email to {}...".format(user.email))
            partner = get_next_partner(user.uuid)
            if not partner:
                print("Reseting prayers for {}!".format(user.email))
                db_session.query(Prayers).filter(
                    Prayers.user_id == str(user.uuid)).filter(
                        Prayers.partner_id != None).delete(
                            synchronize_session=False)
                db_session.commit()
                partner = get_next_partner(user.uuid)
            message = Mail(from_email=From('*****@*****.**',
                                           '3ABC Prayer Reminders'),
                           to_emails=user.email)

            message.dynamic_template_data = {
                'user_name':
                user.name,
                'email':
                partner.email,
                'name':
                partner.name,
                'type':
                partner.type,
                'image':
                partner.image_url if partner.image_url is not None else None,
                'description':
                partner.description
                if partner.description is not None else None,
                'location':
                partner.location if partner.location is not None else None,
            }
            message.template_id = 'd-5f8116bd407849d5a06e66d586354bdb'

            sg = SendGridAPIClient(
                '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'
            )
            response = sg.send(message)
            print(response.status_code)

            new_prayer = Prayers(member_id=None,
                                 partner_id=partner.ccbid,
                                 user_id=user.uuid)
            db_session.add(new_prayer)
            db_session.commit()
        return 200
    except Exception as e:
        print('Failed sending partner emails')
        print(e)
        return 500
    finally:
        db_session.close()
Ejemplo n.º 4
0
def add_content_server(hostname, name, host_url):
    """Add a new content server to the database"""

    content_server = ContentServers(hostname=hostname,
                                    name=name,
                                    host_url=host_url)
    db_session.add(content_server)
    db_session.commit()

    click.echo(f'Content server added\n'
               f'hostname: {hostname}\nname:{name}\nurl:{host_url}')
Ejemplo n.º 5
0
def create_monitor():
    """generate monitor data"""

    # logger
    logger = logging.getLogger("monitors")
    codes = [200, 200, 200, 500, 404]
    for i in range(5):
        mon = MonitorFactory(
            endpoint=f"http://apidash.dev:8000/api/v1/status/{codes[i]}")
        logger.info(f"Adding monitor {mon.name}")
        db_session.add(mon)
    db_session.commit()
Ejemplo n.º 6
0
def queue_emails():
    try:
        users = db_session.query(Users).filter(
            Users.wants_emails == True).all()
        for user in users:
            print("Sending email to {}...".format(user.email))
            member = get_next_member(user.uuid)
            if not member:
                print("Reseting prayers for {}!".format(user.email))
                db_session.query(Prayers).filter(
                    Prayers.user_id == str(user.uuid)).filter(
                        Prayers.member_id != None).delete(
                            synchronize_session=False)
                db_session.commit()
                member = get_next_member(user.uuid)
            message = Mail(from_email=From('*****@*****.**',
                                           '3ABC Prayer Reminders'),
                           to_emails=user.email)

            member_since = member.member_since.strftime('%B %Y')
            message.dynamic_template_data = {
                'email': member.email,
                'name': member.name,
                'member_since': member_since,
                'image':
                member.image_url if member.image_url is not None else None,
                'username':
                user.name if user.name is not None else user.username
            }
            message.template_id = 'd-0a35a380ad214eb0b6152ddaa961f420'

            sg = SendGridAPIClient(
                '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'
            )
            response = sg.send(message)
            print(response.status_code)

            new_prayer = Prayers(member_id=member.ccbid,
                                 partner_id=None,
                                 user_id=user.uuid)
            db_session.add(new_prayer)
            db_session.commit()
        return 200
    except Exception as e:
        print('Failed sending all emails')
        print(e)
        return 500
    finally:
        db_session.close()
Ejemplo n.º 7
0
def add_ticket_to_db(ticket, date_search, iata_from_model, iata_to_model):
    ticket_info = check_ticket(ticket)
    if ticket_info["flights"][0]["invalid"] == 1:
        return
    ticket["price"] = ticket_info["flights_price"]
    new_ticket = Ticket(
        fly_from=iata_from_model,
        fly_to=iata_to_model,
        date_from=ticket["date_from"],
        date_to=ticket["date_to"],
        date_search=date_search,
        booking_token=ticket["booking_token"],
        price=ticket["price"],
    )
    db_session.add(new_ticket)
    db_session.commit()