From 4a5671133a3e304f8fa7e45fb6c7d6af6e8f8cd0 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sun, 7 Feb 2016 07:37:07 -0800 Subject: [PATCH] Update tweets to /twtxt.txt --- public/.gitignore | 1 + src/twtxt.nim | 2 +- src/worker.nim | 33 +++++++++++++++++++++++++++++---- 3 files changed, 31 insertions(+), 5 deletions(-) create mode 100644 public/.gitignore diff --git a/public/.gitignore b/public/.gitignore new file mode 100644 index 0000000..9864c84 --- /dev/null +++ b/public/.gitignore @@ -0,0 +1 @@ +twtxt.txt diff --git a/src/twtxt.nim b/src/twtxt.nim index 067bed0..2cf5850 100644 --- a/src/twtxt.nim +++ b/src/twtxt.nim @@ -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 = %* diff --git a/src/worker.nim b/src/worker.nim index b28532a..d7c6488 100644 --- a/src/worker.nim +++ b/src/worker.nim @@ -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