def remove(message_id, channel_id): """ Removes message from database Parameters: message_id (int): The ID of the message channel_id (int): The channel ID Returns: None """ #remove it in message list inside database data = database.getData() for i in data['messages']: if int(i['message_id']) == int(message_id): data['messages'].remove(i) break #remove it in channel for j in data['channels']: if int(j['channel_id']) == int(channel_id): for x in j['messages']: if int(x['message_id']) == int(message_id): j['messages'].remove(x) break database.update_database(data) return {}
def handle_rating(data): print("Rating:", data) to_find = {'driver': data['driver']} db_driver = database.find_from_database("ride_sharing_app", "ratings", to_find) if db_driver is None: print("In if: ", data) database.insert_into_database("ride_sharing_app", "ratings", data) else: print("In else: ", data) print(type(db_driver['number'])) n = db_driver['number'] + 1 rate = (db_driver['number'] * db_driver['rating'] + data['rating']) / n data['number'] = n data['rating'] = rate print("End else: ", data) database.update_database("ride_sharing_app", "ratings", to_find, data) print(db_driver) if data and '_id' in data.keys(): del data['_id'] if db_driver and '_id' in db_driver.keys(): del db_driver['_id'] dic = '{ "Old data": ' + json.dumps(db_driver) + ', "New data": ' + json.dumps(data) + ' }' response = app.response_class( response=dic, status=200, mimetype='application/json' ) return response
def collect(data, addr, conn): data = data.split("#")[0] data = data.split("b'")[1] database.create_database() IP = data.split(',')[0] auth_type = data.split(',')[1] mac_addr = data.split(',')[2] ID = data.split(',')[3] hello_timeout = data.split(',')[4] _data = (IP, auth_type, mac_addr, ID, hello_timeout) database.update_database(_data)
def update_data(force=False): """ checks to see if data needs updating, and update if so currently updates daily, could maybe be less frequent """ last_update_str, = database.get_database_updated() # returns a 1-tuple, unpack it last_update = datetime.date.fromisoformat(last_update_str) if last_update < datetime.date.today() or force: popfile, co2file, countryfile = data_fetch.get_dataset_files() new_data = handle_csv.load_data(popfile, co2file, countryfile) popfile.close() co2file.close() countryfile.close() database.update_database(new_data)
def api_uuid(): # Check if a UUID was provided as part of the URL # If UUID is provided, assign it to a variable # If not UUID is provided, display error in browser # Repeat for other arguments arguments = ['uuid', 'temp', 'humid', 'alert', 'lat', 'long', 'time'] argument_data = {} for argument in arguments: if argument in request.args: if request.args[argument] is not None: argument_data[argument] = request.args[argument] else: return f"Error, {argument} not provided. Please specify a {argument}" update_database(argument_data) check = "Successful Request!" if argument_data['alert'] == "1": check = send_message('content.txt', argument_data['uuid']) return check
def edit(message_id, channel_id, message): """ Edit message in database Parameters: message_id (int): The ID of the message channel_id (int): The channel ID message(str): The new message Returns: None """ #edit message it in channel data = database.getData() for j in data['channels']: if int(j['channel_id']) == int(channel_id): for x in j['messages']: if int(x['message_id']) == int(message_id): x['message'] = message break database.update_database(data) return {}
def main(config_file=None): try: config.load(config_file or "songfone.conf") except Exception as err: print( f"Error, config file not loaded ({type(err).__name__}): {err}", file=sys.stderr, ) return try: config.make_output() except Exception as err: print(f"Error, cannot create output directory or file: {err}", file=sys.stderr) return wants_changed_time = os.path.getmtime(config.wants_file) fulfill_wants() print(":: wanted files complete") update_database() print(":: database update complete") while wants_changed_time < os.path.getmtime(config.wants_file): wants_changed_time = os.path.getmtime(config.wants_file) fulfill_wants()
elif script_mode == "autothumb": log( "Start method - Autodownload Artist Thumbnails in background", xbmc.LOGNOTICE ) artwork_type = "artistthumb" elif script_mode == "autobanner": log( "Start method - Autodownload Artist Music Banners in background", xbmc.LOGNOTICE ) artwork_type = "musicbanner" if artwork_type in ( "fanart", "clearlogo", "artistthumb", "musicbanner" ) and enable_all_artists: download_count, successfully_downloaded = auto_download( artwork_type, all_artists_list, background=True ) else: download_count, successfully_downloaded = auto_download( artwork_type, album_artists, background=True ) log( "Autodownload of %s artwork completed\nTotal artwork downloaded: %d" % ( artwork_type, download_count ), xbmc.LOGNOTICE ) elif script_mode == "update": log( "Start method - Update Database in background", xbmc.LOGNOTICE ) xbmcgui.Window( 10000 ).setProperty( "cdart_manager_update", "True" ) clear_cache = update_cache() update_database( background = True ) local_artists = get_local_artists_db( mode="album_artists", background = True ) if enable_all_artists: all_artists = get_local_artists_db( mode="all_artists", background = True ) else: all_artists = [] d = datetime.datetime.utcnow() present_datecode = calendar.timegm( d.utctimetuple() ) first_check( all_artists, local_artists, background = True, update_db = clear_cache ) elif script_mode == "autoall": xbmcgui.Window( 10000 ).setProperty( "cdart_manager_running", "True" ) log( "Start method - Autodownload all artwork in background", xbmc.LOGNOTICE ) total_artwork = 0 for artwork_type in ( "cdart", "cover", "fanart", "clearlogo", "artistthumb", "musicbanner" ): log( "Start method - Autodownload %s in background" % artwork_type, xbmc.LOGNOTICE ) if artwork_type in ( "fanart", "clearlogo", "artistthumb", "musicbanner" ) and enable_all_artists:
"musicbanner") and enable_all_artists: download_count, successfully_downloaded = auto_download( artwork_type, all_artists_list, background=True) else: download_count, successfully_downloaded = auto_download( artwork_type, album_artists, background=True) log( "Autodownload of %s artwork completed\nTotal artwork downloaded: %d" % (artwork_type, download_count), xbmc.LOGNOTICE) elif script_mode == "update": log("Start method - Update Database in background", xbmc.LOGNOTICE) xbmcgui.Window(10000).setProperty("cdart_manager_update", "True") clear_cache = update_cache() update_database(background=True) local_artists = get_local_artists_db(mode="album_artists", background=True) if enable_all_artists: all_artists = get_local_artists_db(mode="all_artists", background=True) else: all_artists = [] d = datetime.datetime.utcnow() present_datecode = calendar.timegm(d.utctimetuple()) first_check(all_artists, local_artists, background=True, update_db=clear_cache) elif script_mode == "autoall": xbmcgui.Window(10000).setProperty("cdart_manager_running",