Browse Source

cleanup

master
Wesley Kerfoot 4 years ago
parent
commit
e8f6c07745
  1. 10
      src/twit2blogpkg/server.nim
  2. 3
      src/twit2blogpkg/templates.nim

10
src/twit2blogpkg/server.nim

@ -16,7 +16,7 @@ proc parseTweetUrl(url : string) : Option[ThreadRequest] =
let path = url.parseUri.path
var author : string
var tweetID : int
if scanf(path, "/$w/status/$i", author, tweetID):
if scanf(path, "/$w/status/$i$.", author, tweetID):
some(ThreadRequest(tweetID : $tweetID, author: author))
else:
none(ThreadRequest)
@ -26,6 +26,8 @@ var chan : Channel[ThreadRequest]
# Max 20 items processing
chan.open(20)
# Database functions
let db = open("twit2blog.db", "", "", "")
proc createTweetTable() =
@ -61,6 +63,8 @@ proc insertThread(thread : TwitterThread) =
thread.author,
thread.tweets)
# Routes
router twitblog:
get "/":
# Lists all authors
@ -101,6 +105,8 @@ router twitblog:
let threads = toSeq(threadIDs(author))
resp author.listThreads(threads)
# Entry points
proc startServer* =
createTweetTable()
defer: db.close()
@ -113,8 +119,8 @@ proc handleRenders* =
echo "Starting processing queue"
while true:
let t : ThreadRequest = chan.recv()
if threadExists(t.tweetID, t.author).isSome:
echo "We already have this thread, so we're skipping it"
continue
let tweets = t.tweetID.renderThread(t.author)

3
src/twit2blogpkg/templates.nim

@ -31,7 +31,8 @@ proc listThreads*(author : string,
li: a(href = fmt"/thread/{author}/status/{thread}"): text thread
result = $vnode
## Main page
# Main page
proc listAuthors*(authors : seq[string]) : VNode =
let title = "Authors"
let vnode = buildHtml(tdiv):

Loading…
Cancel
Save