Update tweets to /twtxt.txt

This commit is contained in:
Christine Dodrill 2016-02-07 07:37:07 -08:00
parent 1bd31f9cac
commit 4a5671133a
3 changed files with 31 additions and 5 deletions

1
public/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
twtxt.txt

View File

@ -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 =
%*

View File

@ -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
updateSystemUser()
sleep 300_000 # 5 minutes