fix: youtube stats background sync failures
This commit is contained in:
parent
925b9d985e
commit
bedb11ee67
@ -9,6 +9,7 @@ import frappe
|
|||||||
import pytz
|
import pytz
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe.utils import cint
|
||||||
from pyyoutube import Api
|
from pyyoutube import Api
|
||||||
|
|
||||||
|
|
||||||
@ -46,7 +47,7 @@ def is_tracking_enabled():
|
|||||||
def get_frequency(value):
|
def get_frequency(value):
|
||||||
# Return numeric value from frequency field, return 1 as fallback default value: 1 hour
|
# Return numeric value from frequency field, return 1 as fallback default value: 1 hour
|
||||||
if value != "Daily":
|
if value != "Daily":
|
||||||
return frappe.utils.cint(value[:2].strip())
|
return cint(value[:2].strip())
|
||||||
elif value:
|
elif value:
|
||||||
return 24
|
return 24
|
||||||
return 1
|
return 1
|
||||||
@ -120,24 +121,12 @@ def batch_update_youtube_data():
|
|||||||
video_stats = entry.to_dict().get("statistics")
|
video_stats = entry.to_dict().get("statistics")
|
||||||
video_id = entry.to_dict().get("id")
|
video_id = entry.to_dict().get("id")
|
||||||
stats = {
|
stats = {
|
||||||
"like_count": video_stats.get("likeCount"),
|
"like_count": cint(video_stats.get("likeCount")),
|
||||||
"view_count": video_stats.get("viewCount"),
|
"view_count": cint(video_stats.get("viewCount")),
|
||||||
"dislike_count": video_stats.get("dislikeCount"),
|
"dislike_count": cint(video_stats.get("dislikeCount")),
|
||||||
"comment_count": video_stats.get("commentCount"),
|
"comment_count": cint(video_stats.get("commentCount")),
|
||||||
"video_id": video_id,
|
|
||||||
}
|
}
|
||||||
|
frappe.db.set_value("Video", video_id, stats)
|
||||||
frappe.db.sql(
|
|
||||||
"""
|
|
||||||
UPDATE `tabVideo`
|
|
||||||
SET
|
|
||||||
like_count = %(like_count)s,
|
|
||||||
view_count = %(view_count)s,
|
|
||||||
dislike_count = %(dislike_count)s,
|
|
||||||
comment_count = %(comment_count)s
|
|
||||||
WHERE youtube_video_id = %(video_id)s""",
|
|
||||||
stats,
|
|
||||||
)
|
|
||||||
|
|
||||||
video_list = frappe.get_all("Video", fields=["youtube_video_id"])
|
video_list = frappe.get_all("Video", fields=["youtube_video_id"])
|
||||||
if len(video_list) > 50:
|
if len(video_list) > 50:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user