|
@@ -143,3 +143,36 @@ def delete_subscription(database, sub_id):
|
|
|
sys.exit(1)
|
|
|
else:
|
|
|
LOGGER.info(_("Subscription deleted successfully!"))
|
|
|
+
|
|
|
+
|
|
|
+def update_subscriptions(database, conf):
|
|
|
+ """
|
|
|
+ Updates data about videos in a subscription.
|
|
|
+
|
|
|
+ :param conf: configuration object
|
|
|
+ :type conf: lib_stov.configuration.Conf
|
|
|
+ :param database: database object
|
|
|
+ :type database: lib_stov.database.Db
|
|
|
+ """
|
|
|
+ subscriptions_list = database.get_subscriptions(conf)
|
|
|
+ for element in subscriptions_list:
|
|
|
+ videos = database.get_videos(element.get_id(), conf)
|
|
|
+ element.gather_videos(videos)
|
|
|
+ try:
|
|
|
+ element.update_data()
|
|
|
+ except stov_exceptions.YoutubeAPITimeoutException as error:
|
|
|
+ LOGGER.error(error)
|
|
|
+ except stov_exceptions.NoDataFromYoutubeAPIException as error:
|
|
|
+ LOGGER.error(error)
|
|
|
+ for video in element.parsed_response.videos:
|
|
|
+ if not database.video_in_database(video.ytid):
|
|
|
+ if element.check_string_match(video):
|
|
|
+ try:
|
|
|
+ database.insert_video(video, element.get_id())
|
|
|
+ except stov_exceptions.DBWriteAccessFailedException as \
|
|
|
+ error:
|
|
|
+ LOGGER.error(error)
|
|
|
+ sys.exit(1)
|
|
|
+ else:
|
|
|
+ LOGGER.debug(_("Video %s successfully inserted into "
|
|
|
+ "database."), video.title)
|