def add_name(discord_author_name, name): tar_doc_id = find_single_doc_id(db.collection('users'), 'discord_user', discord_author_name) db.collection('users').document(tar_doc_id).update( {'name' : name} ) return(f'Added {name}')
def log_item_prices(item_name, prices): for price in prices: data = { 'date' : db_helper.get_current_time(), 'item_name' : item_name, 'price' : price, } db.collection('price_log').add(data)
def add_item_to_items_collection(item_name): if db.collection('items').where('item_name','==',item_name).get(): return data = { 'item_name' : item_name, 'avg' : 0, 'max' : 0, 'median' : 0, 'min' : 0, 'update_date' : db_helper.get_current_time(), } db.collection('items').add(data)
def update_items_collection(item_name): log_query = db.collection('price_log').where('item_name', '==', item_name).get() prices = [doc.to_dict()['price'] for doc in log_query] item_db_id = db_helper.find_single_doc_id(db.collection('items'),'item_name',item_name) db.collection('items').document(item_db_id).update( { 'avg' : int(sum(prices)/len(prices)), 'max' : max(prices), 'median' : median(prices), 'min' : min(prices), 'update_date' : db_helper.get_current_time(), } )
def remove_char(ign): print('Removing Character...') chars_c = db.collection('characters') target_doc_id = chars_c.where('ign', '==', ign).get()[0].id chars_c.document(target_doc_id).delete() return (f'Deleted {ign} successfully')
def get_user_or_char(target): user_or_chars = 'characters' ref = db.collection(user_or_chars) try: find_single_doc_id(ref, 'ign', target) except IndexError: user_or_chars = 'users' return user_or_chars
def log_daily(pq_type, ign_list): # Verify it's a correct daily if pq_type.lower() not in dailies: return ( f'Incorrect boss type. Please enter one of the following: {dailies}' ) chars_c = db.collection('characters') for ign in ign_list: log_single_daily(chars_c, pq_type, ign.lower()) return (f'Logged {pq_type} for {ign_list}')
def add_char(command_list, author_info): print('Adding character...') # Check if user exists. If not, add a new user users_c = db.collection('users') if check_doc_exists(users_c, str(author_info.id)) is False: print ('Adding new user') add_user(users_c, str(author_info.id), str(author_info.name.lower())) # Check if character exists characters_c = db.collection('characters') if check_doc_exists(characters_c, command_list[0]) is True: return (f'{command_list[0]} already exists!') # If the user exists and the character does NOT exist, then create a new character document in the users collection data = { 'ign' : command_list[0].lower(), 'class' : command_list[1].lower(), 'apq_type' : command_list[2].lower(), 'user' : db.collection('users').document(str(author_info.id)) } db.collection('characters').document(command_list[0].lower()).set(data) #import pdb; pdb.set_trace() return (f'Added a new character: {command_list[0]}')
def query_character(target): print('Character query') target_char = db.collection('characters').where('ign', '==', target).get()[0] target_dailies = [] time_log = None for daily in dailies: try: time_log = target_char.get(daily) except KeyError: continue gmt_now = time.gmtime() if (gmt_now[0] == time_log[0] and gmt_now[1] == time_log[1] and gmt_now[2] == time_log[2]): target_dailies.append(daily) return (f'{target} has ran {target_dailies} today')
def db_print(collection): docs = db.collection(collection).stream() for doc in docs: print(f'{doc.id} => {doc.to_dict()}')
def get_item_info(item_name): item_info = db.collection('items').where('item_name', '==', item_name).get() if len(item_info) == 0: return return item_info[0].to_dict()
def query_user_daily(daily_type, user_name, name_type): #ref = ('/users/156976596987674624') ref = db.collection('users').where(name_type, '==', user_name).get() #import pdb; pdb.set_trace() chars_list = db.collection('characters').where('user', '==', ref[0])