def update_user_heartbeat_timestamp(user_id): cur = conn.cursor() cur.execute( "update et_users set last_heartbeat_timestamp = %s where id=%s;", (utils.get_timestamp_ms(), user_id)) cur.close() conn.commit()
def create_user(id_token, name, email): cur = conn.cursor() timestamp_now = utils.get_timestamp_ms() cur.execute( "insert into et_users(id_token, name, email, last_sync_timestamp, last_heartbeat_timestamp) values (%s,%s,%s,%s,%s);", (id_token, name, email, timestamp_now, timestamp_now)) cur.close() conn.commit() return get_existing_user_by_email(email=email)
def store_direct_message(src_user_id, trg_user_id, subject, content): try: cur = conn.cursor() cur.execute( "insert into et_direct_messages(src_user_id, trg_user_id, timestamp, subject, content) values (%s,%s,%s,%s,%s);", (src_user_id, trg_user_id, utils.get_timestamp_ms(), subject, content)) cur.close() conn.commit() return True except (Exception, psycopg2.DatabaseError) as e: print('db_mgr.store_direct_message', e) return False
def bind_participant_to_campaign(user_id, campaign_id): cur = conn.cursor() cur.execute('select campaign_id from et_users where id=%s;', (user_id, )) old_campaign_id = cur.fetchone()[0] if old_campaign_id is not None and old_campaign_id == campaign_id: cur.close() return False # already bound cur.execute( 'select * from et_campaign_to_user_maps where user_id=%s and campaign_id=%s;', (user_id, campaign_id)) row = cur.fetchone() new_binding = row is None if new_binding: cur.execute( 'insert into et_campaign_to_user_maps(user_id, campaign_id, join_timestamp) values (%s,%s,%s);', (user_id, campaign_id, utils.get_timestamp_ms())) cur.execute('update et_users set campaign_id = %s where id=%s;', (campaign_id, user_id)) cur.close() conn.commit() return new_binding
def campaign_has_started(campaign_id): return utils.get_timestamp_ms() >= get_campaign_start_timestamp( campaign_id=campaign_id)