def insert_icons_into_files(list_of_links): db.execute( """ SELECT file_link FROM files WHERE file_link IN %(list_of_links)s; """ % {"list_of_links": tuple(list_of_links)} ) links = [link["file_link"] for link in db.fetchall()] db.executemany( """ INSERT INTO files(file_link) VALUES(%(link)s); """, [{"link": elem} for elem in list_of_links if elem not in links], ) sql_connection.commit()
def get_full_channels_info(): db.execute( """ SELECT c.name, c.cr_tm, c.link, c.web_site, c.description, f.file_link as icon_link FROM channels c LEFT JOIN files f ON c.icon_id=f.id; """ ) db_elements = [] for elem in db.fetchall(): db_elements.append( { "name": elem["name"].decode("utf-8"), "cr_tm": elem["cr_tm"], "link": elem["link"], "web_site": elem["web_site"], "description": elem["description"].decode("utf-8") if elem["description"] else None, "icon_link": elem["icon_link"], } ) return db_elements
def get_channels_id_and_link(): db.execute(""" SELECT id, link FROM channels; """) return [{"id": channel_id, "link": link} for channel_id, link in db.fetchall()]