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 save_programs(channel_id, list_of_programs_classes): db.executemany( """ INSERT INTO tv_programs(name, genre, show_date, show_time, channel_id) VALUES(%(name)s, %(genre)s, %(show_date)s, %(show_time)s, %(channel_id)s); """, [ { "name": cls.name, "genre": cls.genre, "show_date": cls.show_date, "show_time": cls.show_time, "channel_id": channel_id, } for cls in list_of_programs_classes ], ) sql_connection.commit()