chore: Error Logging and exception hnadling on connection failure

This commit is contained in:
marination 2020-08-02 17:13:34 +05:30
parent c16ace6732
commit e3495116dd

View File

@ -26,24 +26,28 @@ def get_video_stats(docname, youtube_id, update=True):
api_key = frappe.db.get_single_value("Video Settings", "api_key") api_key = frappe.db.get_single_value("Video Settings", "api_key")
api = Api(api_key=api_key) api = Api(api_key=api_key)
video = api.get_video_by_id(video_id=youtube_id) try:
video_stats = video.items[0].to_dict().get('statistics') video = api.get_video_by_id(video_id=youtube_id)
stats = { video_stats = video.items[0].to_dict().get('statistics')
'like_count' : video_stats.get('likeCount'), stats = {
'view_count' : video_stats.get('viewCount'), 'like_count' : video_stats.get('likeCount'),
'dislike_count' : video_stats.get('dislikeCount'), 'view_count' : video_stats.get('viewCount'),
'comment_count' : video_stats.get('commentCount') 'dislike_count' : video_stats.get('dislikeCount'),
} 'comment_count' : video_stats.get('commentCount')
}
if not update: if not update:
return stats return stats
frappe.db.sql(""" frappe.db.sql("""
UPDATE `tabVideo` UPDATE `tabVideo`
SET SET
like_count = %(like_count)s, like_count = %(like_count)s,
view_count = %(view_count)s, view_count = %(view_count)s,
dislike_count = %(dislike_count)s, dislike_count = %(dislike_count)s,
comment_count = %(comment_count)s comment_count = %(comment_count)s
WHERE name = {0}""".format(frappe.db.escape(docname)), stats) #nosec WHERE name = {0}""".format(frappe.db.escape(docname)), stats) #nosec
frappe.db.commit() frappe.db.commit()
except:
message = "Please make sure you are connected to the Internet"
frappe.log_error(message + "\n\n" + frappe.get_traceback(), "Failed to Update YouTube Statistics for Video: {0}".format(docname))