diff --git a/src/twit2blogpkg/server.nim b/src/twit2blogpkg/server.nim index f4dc6aa..f063c10 100644 --- a/src/twit2blogpkg/server.nim +++ b/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) diff --git a/src/twit2blogpkg/templates.nim b/src/twit2blogpkg/templates.nim index 630c2ff..d132d6d 100644 --- a/src/twit2blogpkg/templates.nim +++ b/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):