system user

This commit is contained in:
Christine Dodrill 2016-02-06 10:45:51 -08:00
parent 11df9c4657
commit 4518b08e4d
2 changed files with 20 additions and 6 deletions

View File

@ -10,7 +10,7 @@ type
username*: string username*: string
proc `$`*(t: Tweet): string = proc `$`*(t: Tweet): string =
t.date.format(ISOTime) & "\t" & t.message t.date.format(ISOTime) & '\x09' & t.message
proc `%`*(t: Tweet): JsonNode = proc `%`*(t: Tweet): JsonNode =
%* %*
@ -41,6 +41,11 @@ proc parseTweet*(user, inp: string): Tweet =
message: message, message: message,
username: user) username: user)
proc fromDBRow*(r: Row): Tweet =
Tweet(date: r[2].split(".")[0].parseInt().fromSeconds().timeToTimeInfo(),
username: r[1],
message: r[3])
proc getTweetsFrom*(url: string, username: string): seq[Tweet] = proc getTweetsFrom*(url: string, username: string): seq[Tweet] =
var res = newSeq[Tweet]() var res = newSeq[Tweet]()
@ -72,6 +77,8 @@ proc updateTweetsOnce*() =
when isMainModule: when isMainModule:
while true: while true:
updateTweetsOnce() try:
updateTweetsOnce()
except: discard
sleep 300_000 # 5 minutes sleep 300_000 # 5 minutes

View File

@ -66,11 +66,18 @@ routes:
renderMustache("home", indexTemplate, newContext()) renderMustache("home", indexTemplate, newContext())
get "/content/system": get "/content/system":
let myHeaders = { let
"Content-Type": "text/plain", myHeaders = {
} "Content-Type": "text/plain",
}
tweets = db.getAllRows(sql"select * from tweets where username='system'")
resp Http200, myHeaders, "hi" var res = ""
for tweet in tweets.items():
res &= $(tweet.fromDBRow()) & "\r\n"
resp Http200, myHeaders, res
get "/timeline": get "/timeline":
redirect "/timeline/0" redirect "/timeline/0"