fix: youtube stats background sync failures
diff --git a/erpnext/utilities/doctype/video/video.py b/erpnext/utilities/doctype/video/video.py
index a39d0a9..15dbccd 100644
--- a/erpnext/utilities/doctype/video/video.py
+++ b/erpnext/utilities/doctype/video/video.py
@@ -9,6 +9,7 @@
import pytz
from frappe import _
from frappe.model.document import Document
+from frappe.utils import cint
from pyyoutube import Api
@@ -46,7 +47,7 @@
def get_frequency(value):
# Return numeric value from frequency field, return 1 as fallback default value: 1 hour
if value != "Daily":
- return frappe.utils.cint(value[:2].strip())
+ return cint(value[:2].strip())
elif value:
return 24
return 1
@@ -120,24 +121,12 @@
video_stats = entry.to_dict().get("statistics")
video_id = entry.to_dict().get("id")
stats = {
- "like_count": video_stats.get("likeCount"),
- "view_count": video_stats.get("viewCount"),
- "dislike_count": video_stats.get("dislikeCount"),
- "comment_count": video_stats.get("commentCount"),
- "video_id": video_id,
+ "like_count": cint(video_stats.get("likeCount")),
+ "view_count": cint(video_stats.get("viewCount")),
+ "dislike_count": cint(video_stats.get("dislikeCount")),
+ "comment_count": cint(video_stats.get("commentCount")),
}
-
- 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,
- )
+ frappe.db.set_value("Video", video_id, stats)
video_list = frappe.get_all("Video", fields=["youtube_video_id"])
if len(video_list) > 50: