示例#1
0
 def get_last_log_info(parser_name):
     result_dict = dict(
         log_name="Parser not started yet",
         new_items=0,
         total_channels=0,
         total_programs=0,
         log_cr_tm="Parser not started yet",
         log_status="Parser not started yet",
         execution_time=0,
     )
     db.execute(
         """ SELECT * FROM log WHERE parser_name='%(parser_name)s'
                    ORDER BY cr_tm DESC; """
         % {"parser_name": parser_name}
     )
     result = db.fetchone()
     if not result:
         return result_dict
     return dict(
         log_name=result.get("parser_name"),
         new_items=result.get("count_new_items"),
         total_channels=result.get("total_channels"),
         total_programs=result.get("total_programs"),
         log_cr_tm=result.get("cr_tm"),
         log_status=result.get("success"),
         execution_time=hours_minutes_seconds_from_seconds(result.get("execution_time")),
     )
示例#2
0
 def save_channels_to_db(self, dict_of_elements):
     new_elements_count = 0
     self.insert_icons_into_files([link["icon"] for link in dict_of_elements.values() if link["icon"]])
     for element in dict_of_elements.keys():
         db.execute(
             """ SELECT COUNT(id) FROM channels WHERE link='{link}'
                        OR name='{name}' """.format(
                 link=element, name=dict_of_elements[element]["name"]
             )
         )
         if db.fetchone()[0] == 0:
             db.execute(
                 """ INSERT INTO channels(name, link, icon_id)
                           VALUES ('{name}', '{link}',
                           (SELECT id FROM files WHERE file_link='{file_link}')); """.format(
                     name=dict_of_elements[element]["name"],
                     link=element,
                     file_link=dict_of_elements[element]["icon"],
                 )
             )
             new_elements_count += 1
     sql_connection.commit()
     return new_elements_count
示例#3
0
 def check_channel_exists(self):
     db.execute(""" SELECT COUNT(id) FROM channels WHERE name='{name}';""".format(name=self.name))
     return db.fetchone()[0]
示例#4
0
 def get_channel(channel_id):
     db.execute(""" SELECT * FROM channels WHERE id='{channel_id}'; """.format(channel_id=channel_id))
     return db.fetchone()