Update tweets to /twtxt.txt
This commit is contained in:
parent
1bd31f9cac
commit
4a5671133a
|
@ -0,0 +1 @@
|
|||
twtxt.txt
|
|
@ -10,7 +10,7 @@ type
|
|||
username*: string
|
||||
|
||||
proc `$`*(t: Tweet): string =
|
||||
t.date.format(ISOTime) & '\x09' & t.message
|
||||
return join([t.date.format(ISOTime), t.message], "\t")
|
||||
|
||||
proc `%`*(t: Tweet): JsonNode =
|
||||
%*
|
||||
|
|
|
@ -1,9 +1,34 @@
|
|||
import os, threadpool, twtxt
|
||||
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:
|
||||
fout.writeLine $(tweet.fromDBRow())
|
||||
|
||||
fout.close
|
||||
|
||||
echo "Updated system user"
|
||||
|
||||
when isMainModule:
|
||||
while true:
|
||||
try:
|
||||
spawn updateTweetsOnce()
|
||||
except: discard
|
||||
spawn updateTweetsOnce()
|
||||
updateSystemUser()
|
||||
|
||||
sleep 300_000 # 5 minutes
|
||||
|
|
Loading…
Reference in New Issue