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
proc `$`*(t: Tweet): string =
t.date.format(ISOTime) & "\t" & t.message
t.date.format(ISOTime) & '\x09' & t.message
proc `%`*(t: Tweet): JsonNode =
%*
@ -41,6 +41,11 @@ proc parseTweet*(user, inp: string): Tweet =
message: message,
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] =
var res = newSeq[Tweet]()
@ -72,6 +77,8 @@ proc updateTweetsOnce*() =
when isMainModule:
while true:
updateTweetsOnce()
try:
updateTweetsOnce()
except: discard
sleep 300_000 # 5 minutes

View File

@ -66,11 +66,18 @@ routes:
renderMustache("home", indexTemplate, newContext())
get "/content/system":
let myHeaders = {
"Content-Type": "text/plain",
}
let
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":
redirect "/timeline/0"