def sync_tables(): """ Periodic task for fetching and saving tables from Poster @todo #187:30min Set up scheduler for celery, docs - http://docs.celeryproject.org/en/ latest/userguide/periodic-tasks.html#id5 Also should make small refactoring: celery.py should situated in timelessis/celery.py not in timelessis/sync/celery.py """ auth_data = PosterAuthData( application_id=os.environ.get("poster_application_id"), application_secret=os.environ.get("poster_application_secret"), redirect_uri=os.environ.get("poster_redirect_uri"), code=os.environ.get("poster_code"), ) auth_token = Authenticated(auth_data=auth_data).auth() poster = Poster(auth_token=auth_token) for poster_table in poster.tables(): table = DB.session(Table).query.filter_by( name=poster_table["name"], floor_id=poster_table["floor_id"]).first() if table: new_table = Table.merge_with_poster(table, poster_table) DB.session.add(new_table) else: new_table = Table.create_by_poster(poster_table) DB.session.merge(new_table) DB.session.commit()
def sync_locations(): """ Periodic task for fetching and saving location from Poster """ for poster_location in __poster_api().locations(): location = DB.session(Location).query.filter_by( name=poster_location["name"], code=poster_location["code"] ).first() merge_data( model=Location, poster_data=poster_location, timelessis_data=location )
def sync_customers(): """ Periodic task for fetching and saving tables from Poster """ for poster_customer in __poster_api().customers(): customer = DB.session(Customer).query.filter_by( first_name=poster_customer["first_name"], last_name=poster_customer["last_name"] ).first() merge_data( model=Customer, poster_data=poster_customer, timelessis_data=customer )
def sync_tables(): """ Periodic task for fetching and saving tables from Poster @todo #187:30min Set up scheduler for celery, docs - http://docs.celeryproject.org/en/ latest/userguide/periodic-tasks.html#id5 Also should make small refactoring: celery.py should situated in timelessis/celery.py not in timelessis/sync/celery.py """ for poster_table in __poster_api().tables(): table = DB.session(Table).query.filter_by( name=poster_table["name"], floor_id=poster_table["floor_id"] ).first() merge_data( model=Table, poster_data=poster_table, timelessis_data=table )