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 let path = url.parseUri.path
var author : string var author : string
var tweetID : int 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)) some(ThreadRequest(tweetID : $tweetID, author: author))
else: else:
none(ThreadRequest) none(ThreadRequest)
@ -26,6 +26,8 @@ var chan : Channel[ThreadRequest]
# Max 20 items processing # Max 20 items processing
chan.open(20) chan.open(20)
# Database functions
let db = open("twit2blog.db", "", "", "") let db = open("twit2blog.db", "", "", "")
proc createTweetTable() = proc createTweetTable() =
@ -61,6 +63,8 @@ proc insertThread(thread : TwitterThread) =
thread.author, thread.author,
thread.tweets) thread.tweets)
# Routes
router twitblog: router twitblog:
get "/": get "/":
# Lists all authors # Lists all authors
@ -101,6 +105,8 @@ router twitblog:
let threads = toSeq(threadIDs(author)) let threads = toSeq(threadIDs(author))
resp author.listThreads(threads) resp author.listThreads(threads)
# Entry points
proc startServer* = proc startServer* =
createTweetTable() createTweetTable()
defer: db.close() defer: db.close()
@ -113,8 +119,8 @@ proc handleRenders* =
echo "Starting processing queue" echo "Starting processing queue"
while true: while true:
let t : ThreadRequest = chan.recv() let t : ThreadRequest = chan.recv()
if threadExists(t.tweetID, t.author).isSome: if threadExists(t.tweetID, t.author).isSome:
echo "We already have this thread, so we're skipping it"
continue continue
let tweets = t.tweetID.renderThread(t.author) 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 li: a(href = fmt"/thread/{author}/status/{thread}"): text thread
result = $vnode result = $vnode
## Main page # Main page
proc listAuthors*(authors : seq[string]) : VNode = proc listAuthors*(authors : seq[string]) : VNode =
let title = "Authors" let title = "Authors"
let vnode = buildHtml(tdiv): let vnode = buildHtml(tdiv):

Loading…
Cancel
Save