Skip to content

Commit d5e5e51

Browse files
committed
saving cursor to db on first full scan
1 parent 9351446 commit d5e5e51

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

utils/Database.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,30 @@ def GetKickClipIdTitles(self):
6161
conn.close()
6262
return titleIdDict
6363

64+
def InsertClipCursor(self,cursor:str):
65+
self.createKickClipsTable()
66+
conn, cur = self.connectCursor()
67+
rowVal = (cursor,"greenLight")
68+
exeString = '''UPDATE kick_clips SET channel_slug=? WHERE clip_id=?'''
69+
cur.execute(exeString,rowVal)
70+
conn.commit()
71+
cur.close()
72+
conn.close()
73+
74+
def GetClipCursor(self):
75+
self.createKickClipsTable()
76+
conn, cur = self.connectCursor()
77+
cursor = ''
78+
rowVal = ("greenLight",)
79+
exeString = '''SELECT channel_slug FROM kick_clips WHERE clip_id=?'''
80+
cur.execute(exeString,rowVal)
81+
fetch = cur.fetchall()
82+
if fetch and fetch[0][0] != None:
83+
cursor = fetch[0][0]
84+
cur.close()
85+
conn.close()
86+
return cursor
87+
6488
def isClipRowCountZero(self):
6589
self.createKickClipsTable()
6690
conn, cur = self.connectCursor()

utils/KickDataGrabber.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@
2222
async def CollectClipData(kickSlug:str, rest: hikari.impl.RESTClientImpl) -> None:
2323
db = Database()
2424
apiUrl = f"https://kick.com/api/v2/channels/{kickSlug}/clips"
25-
if globals.kickClipCursor:
26-
apiUrl = f"{apiUrl}?cursor={globals.kickClipCursor}"
2725
if db.isClipRowCountZero():
2826
db.addKickClipToTable("greenLight",None,None,None,None,None,None,None)
27+
if not db.isClipsFullyScanned():
28+
globals.kickClipCursor = db.GetClipCursor()
29+
if globals.kickClipCursor:
30+
apiUrl = f"{apiUrl}?cursor={globals.kickClipCursor}"
2931
browser = await ndb.GetBrowser(proxy=Constants.KICK_PROXY)
3032
try:
3133
if globals.kickClipCursor in globals.kickVisitedCursors:
@@ -73,6 +75,8 @@ async def CollectClipData(kickSlug:str, rest: hikari.impl.RESTClientImpl) -> Non
7375
globals.kickClipCursor = ""
7476
if viewIncrease > globals.kickClipMostViews:
7577
AddMostViewedClipToGlobal(clip, viewIncrease)
78+
if not db.isClipsFullyScanned():
79+
db.InsertClipCursor(results['nextCursor'])
7680
if not globals.kickClipCursor:
7781
await AnnounceWinnersHandleData(kickSlug, rest, db)
7882
except Exception as e:

0 commit comments

Comments
 (0)