Browse Source

implement basic thread renderer

pull/1/head
Wesley Kerfoot 4 years ago
parent
commit
18dbea42f1
  1. 3
      src/twit2blog.nim
  2. 13
      src/twit2blogpkg/twitter.nim

3
src/twit2blog.nim

@ -30,5 +30,4 @@ when isMainModule:
stderr.writeLine("Invalid Arguments. Must provide both --user and --thread (or -u and -t). E.g. -u:foo -t:123")
quit(1)
for tweet in twitterParams["thread"].getThread(twitterParams["user"]):
echo tweet
echo twitterParams["thread"].renderThread(twitterParams["user"])

13
src/twit2blogpkg/twitter.nim

@ -1,4 +1,4 @@
import httpClient, base64, uri, json, os, strformat, sequtils
import httpClient, base64, uri, json, os, strformat, sequtils, strutils
proc buildAuthHeader() : string =
let consumerKey = "TWITTER_CONSUMER_KEY".getEnv
@ -65,3 +65,14 @@ proc getThread*(tweetStart : string, user : string) : seq[string] =
else:
return nextTweetID.getThread(user)
proc stripAts(tweet : string) : string =
let words = tweet.split(" ")
var stripped : seq[string]
for word in words:
if word[0] != '@':
stripped &= word
stripped.join(" ")
proc renderThread*(tweetID : string, user : string) : string =
let thread = tweetID.getThread(user).map(stripAts).map(capitalizeAscii).join("\n\n")
fmt"### By {user}" & "\n" & fmt"{thread}"

Loading…
Cancel
Save