Add worker for updating from twtxt files
This commit is contained in:
parent
cf9a26b0cb
commit
ec4dab6953
|
@ -1,3 +1,4 @@
|
||||||
twtxtlist
|
twtxtlist
|
||||||
|
twtxt
|
||||||
nimcache
|
nimcache
|
||||||
*.db
|
*.db
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
twtxt
|
|
|
@ -1,4 +1,4 @@
|
||||||
import json, httpclient, strutils, times
|
import db_sqlite, json, httpclient, os, strutils, times
|
||||||
|
|
||||||
const
|
const
|
||||||
ISOTime*: string = "yyyy-MM-dd'T'HH:mm:ss'.000000'zzz"
|
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
|
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:
|
when isMainModule:
|
||||||
let
|
updateTweets()
|
||||||
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)
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import asyncdispatch, db_sqlite, jester, moustachu, os, shorturl,
|
import asyncdispatch, db_sqlite, jester, moustachu, os, shorturl,
|
||||||
strutils, tables, times, typetraits
|
strutils, tables, times, twtxt, typetraits
|
||||||
|
|
||||||
const
|
const
|
||||||
baseTemplate*: string = staticRead "./templates/layout.mustache"
|
baseTemplate*: string = staticRead "./templates/layout.mustache"
|
||||||
|
|
|
@ -5,7 +5,7 @@ author = "Christine Dodrill"
|
||||||
description = "a list of twtxt hacker feeds"
|
description = "a list of twtxt hacker feeds"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
srcDir = "src"
|
srcDir = "src"
|
||||||
bin = @["twtxtlist"]
|
bin = @["twtxtlist", "twtxt"]
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue