def generategmusicplaylist(**kwargs): station = kwargs.get('station', None) genre = kwargs.get('genre', None) if 'station' in kwargs: dbtable = kwargs.get('dbtable', 'gmusicstations') else: dbtable = kwargs.get('dbtable', 'gmusicgenres') create_db_connection('gmusiclibrary.db') querystring = "SELECT id FROM " + dbtable if (station is not None) or (genre is not None): querystring = querystring + " WHERE" if (station is not None): querystring = querystring + " name LIKE '%" + station.lower( ).translate(removepunct).strip() + "%' AND" if (genre is not None): querystring = querystring + " name LIKE '%" + genre.lower().translate( removepunct).strip() + "%' AND" querystring = querystring + " id IS NOT NULL;" item_ids = read_db_table(querystring) for item in item_ids: if (station is not None): generateplaylistfromstation(item[0]) else: generateplaylistfromgenre(item[0]) close_db_connection()
def sighandler(): try: close_db_connection() os.remove(PID_FILE) except: pass time.sleep(0.2) sys.exit()
def creategmusicplaylist(**kwargs): clearplaylists() global musicplaylisttype musicplaylisttype = 'gmusic' song = kwargs.get('song', None) artist = kwargs.get('artist', None) album = kwargs.get('album', None) playlist = kwargs.get('playlist', None) podcast = kwargs.get('podcast', None) if 'playlist' in kwargs and playlist is not None: dbtable = kwargs.get('dbtable', 'gmusicplaylists') elif 'podcast' in kwargs and podcast is not None: dbtable = kwargs.get('dbtable', 'gmusicpodcasts') else: dbtable = kwargs.get('dbtable', 'gmusicsongs') create_db_connection('gmusiclibrary.db') querystring = "SELECT id FROM " + dbtable if (artist is not None) or (album is not None) or (song is not None) or ( playlist is not None) or (podcast is not None): querystring = querystring + " WHERE" if (artist is not None): querystring = querystring + " albumArtist LIKE '%" + artist.lower( ).translate(removepunct).strip() + "%' AND" if (album is not None): querystring = querystring + " album LIKE '%" + album.lower().translate( removepunct).strip() + "%' AND" if (song is not None): querystring = querystring + " title LIKE '%" + song.lower().translate( removepunct).strip() + "%' AND" if (playlist is not None): querystring = querystring + " name LIKE '%" + playlist.lower( ).translate(removepunct).strip() + "%' AND" if (podcast is not None): querystring = querystring + " name LIKE '%" + podcast.lower( ).translate(removepunct).strip() + "%' AND" querystring = querystring + " id IS NOT NULL" if (podcast is not None): querystring = querystring + " ORDER BY time DESC" querystring = querystring + ";" songs_ids = read_db_table(querystring) playlist = [] for song in songs_ids: playlist.append(song[0]) close_db_connection() if playlist: with open('gmusicplaylist.json', 'w') as output_file: json.dump(playlist, output_file)
def updategmusiclibrary(): try: create_db_connection('gmusiclibrary.db') drop_db_table('gmusicsongs') drop_db_table('gmusicplaylists') drop_db_table('gmusicstations') drop_db_table('gmusicgenres') drop_db_table('gmusicpodcasts') create_db_table('gmusicsongs', ['album', 'albumArtist', 'id', 'title']) getsongsfromlibraryandsavetodb('gmusicsongs') create_db_table('gmusicplaylists', ['name', 'id', 'album', 'albumArtist', 'title']) getsongsfromplaylistandsavetodb('gmusicplaylists') create_db_table('gmusicstations', ['name', 'id']) getstationsandsavetodb('gmusicstations') create_db_table('gmusicgenres', ['name', 'id']) getgenresandsavetodb('gmusicgenres') create_db_table('gmusicpodcasts', ['name', 'id', 'time']) getpodcastsandsavetodb('gmusicpodcasts') commit_db_connection() close_db_connection() return True except Exception: return False
def teardown_request(exception): db.close_db_connection()
def after(exception): db.close_db_connection(exception)
def tearDown(self): """Clear all tables in the database and close the connection.""" db.close_db_connection(self) super(DatabaseTestCase, self).tearDown()
def tearDown(self): self.execute_sql('sql/clear-db.sql') self.execute_sql('sql/init-db.sql') db.close_db_connection() super().tearDown()
def bounce_db_connection(): """Bounce the database connection; ensures data are persistent.""" db.close_db_connection() db.open_db_connection()
def teardown_request(exception): """Close database connection after each request. """ db.close_db_connection(g.db)
def tearDown(self): """Clear all tables in the database and close the connection.""" self.execute_script('db/clear_db.sql') db.close_db_connection() super(DatabaseTestCase, self).tearDown()
except TelegramError: print("Error restrict_chat_member():", str(err)) pass return infos = get_user_info(cm.user.username) if infos is None: try: bot.restrict_chat_member(chat_id=group, user_id=userid, can_send_messages=True, can_send_media_messages=False, can_send_other_messages=False, can_add_web_page_previews=False) except TelegramError as err: print("Error restrict_chat_member():", str(err)) pass finally: return print("User verified: skipping") if __name__ == "__main__": bot = telegram.Bot(token=BOT_TOKEN) open_db_connection() with open("members.lst", "r") as f: for line in f: apply_restriction(int(line.rstrip("\n"))) print("---") time.sleep(0.5) close_db_connection()
def tearDown(self): db.close_db_connection() super(DatabaseTestCase, self).tearDown()
def tearDown(self): db.close_db_connection() super(ApplicationTestCase, self).tearDown()