From ec4dab6953baaa5c34ad51effd81a9ffd8e6f517 Mon Sep 17 00:00:00 2001 From: Christine Dodrill Date: Sat, 6 Feb 2016 08:41:23 -0800 Subject: [PATCH] Add worker for updating from twtxt files --- .gitignore | 1 + src/.gitignore | 1 - src/twtxt.nim | 33 +++++++++++++++++++-------------- src/twtxtlist.nim | 2 +- twtxtlist.nimble | 2 +- 5 files changed, 22 insertions(+), 17 deletions(-) delete mode 100644 src/.gitignore diff --git a/.gitignore b/.gitignore index 9c49590..422ef8b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ twtxtlist +twtxt nimcache *.db diff --git a/src/.gitignore b/src/.gitignore deleted file mode 100644 index 8fa3a67..0000000 --- a/src/.gitignore +++ /dev/null @@ -1 +0,0 @@ -twtxt diff --git a/src/twtxt.nim b/src/twtxt.nim index 433b953..5cc9663 100644 --- a/src/twtxt.nim +++ b/src/twtxt.nim @@ -1,4 +1,4 @@ -import json, httpclient, strutils, times +import db_sqlite, json, httpclient, os, strutils, times const ISOTime*: string = "yyyy-MM-dd'T'HH:mm:ss'.000000'zzz" @@ -52,17 +52,22 @@ proc getTweetsFrom*(url: string, username: string): seq[Tweet] = return res +proc updateTweets*() = + var db = open("./data/twtxt.db", nil, nil, nil) + + while true: + var users = db.getAllRows sql"select * from users" + + for user in users.items(): + echo user + let + username = user[1] + url = user[2] + tweets = getTweetsFrom(url, username) + + echo tweets + + sleep 300_000 # 5 minutes + when isMainModule: - let - now = getLocalTime(getTime()) - t: Tweet = Tweet(date: now, - message: "Test message", - username: "Xena") - - const testInp = "2016-02-05T19:30:46.964649+00:00 This is a tweet via twtxt!" - - echo "xena".parseTweet testInp - - echo pretty(%t, 4) - - echo pretty(%getTweetsFrom("https://xena.greedo.xeserv.us/files/xena.txt", "xena"), 4) + updateTweets() diff --git a/src/twtxtlist.nim b/src/twtxtlist.nim index 4a14d66..3729d2b 100644 --- a/src/twtxtlist.nim +++ b/src/twtxtlist.nim @@ -1,5 +1,5 @@ import asyncdispatch, db_sqlite, jester, moustachu, os, shorturl, - strutils, tables, times, typetraits + strutils, tables, times, twtxt, typetraits const baseTemplate*: string = staticRead "./templates/layout.mustache" diff --git a/twtxtlist.nimble b/twtxtlist.nimble index 33d4b40..8efd8a4 100644 --- a/twtxtlist.nimble +++ b/twtxtlist.nimble @@ -5,7 +5,7 @@ author = "Christine Dodrill" description = "a list of twtxt hacker feeds" license = "MIT" srcDir = "src" -bin = @["twtxtlist"] +bin = @["twtxtlist", "twtxt"] # Dependencies