Add worker for updating from twtxt files

This commit is contained in:
Christine Dodrill 2016-02-06 08:41:23 -08:00
parent cf9a26b0cb
commit ec4dab6953
5 changed files with 22 additions and 17 deletions

1
.gitignore vendored
View File

@ -1,3 +1,4 @@
twtxtlist
twtxt
nimcache
*.db

1
src/.gitignore vendored
View File

@ -1 +0,0 @@
twtxt

View File

@ -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()

View File

@ -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"

View File

@ -5,7 +5,7 @@ author = "Christine Dodrill"
description = "a list of twtxt hacker feeds"
license = "MIT"
srcDir = "src"
bin = @["twtxtlist"]
bin = @["twtxtlist", "twtxt"]
# Dependencies