twtxtlist/src/worker.nim

37 lines
713 B
Nim

import db_sqlite, os, streams, threadpool, twtxt
proc updateSystemUser() =
let
fname = "public" / "twtxt.txt"
db = open("data/twtxt.db", nil, nil, nil)
if fname.existsFile:
try:
fname.removeFile
except: quit "can't make my list"
var
fout = fname.newFileStream fmWrite
if fout.isNil:
echo "wtf it's nil?"
return
let tweets = db.getAllRows(sql"select * from tweets where username='system'")
for tweet in tweets.items:
let tweetObj = tweet.fromDBRow()
echo tweetObj
fout.writeLine $tweetObj
fout.close
echo "Updated system user"
when isMainModule:
while true:
spawn updateTweetsOnce()
updateSystemUser()
sleep 300_000 # 5 minutes