Compare commits

...

15 Commits

Author SHA1 Message Date
Christine Dodrill f12d8d2572 oops 2016-02-12 16:31:27 -08:00
Christine Dodrill a026980d65 ignore @twtxtlist and @directory in the timeline 2016-02-12 11:59:27 -08:00
Christine Dodrill 623d7c920a revert the time fix 2016-02-12 11:37:31 -08:00
Christine Dodrill a9b8d923ba comment this out for now 2016-02-12 11:35:05 -08:00
Christine Dodrill ad101251bb fix ordering with the future? 2016-02-12 11:32:20 -08:00
Christine Dodrill 3839ddd8b9 fix time parsing code 2016-02-12 11:25:54 -08:00
Christine Dodrill db687ce3f6 sigil added usernames 2016-02-12 05:32:51 -08:00
Christine Dodrill 2737f753ca fix isotime string 2016-02-12 03:13:05 -08:00
Christine Dodrill ba941a3029 announce when new users are submitted 2016-02-12 02:46:59 -08:00
Christine Dodrill 34d2bbe207 Show user list in TXT format: /users.txt 2016-02-12 02:29:04 -08:00
Christine Dodrill 1dbe7f6f3d handle errors better here 2016-02-12 02:18:17 -08:00
Christine Dodrill 2e5c37a97c lookup tweets in parallel 2016-02-11 13:34:11 -08:00
Christine Dodrill ac6dd0f0e3 Show tweet/user count in the main page 2016-02-11 07:44:45 -08:00
Christine Dodrill adab4a23fd fix user agent for external HTTP requests 2016-02-11 04:57:52 -08:00
Christine Dodrill 69b3680361 Custom user agent
Ref https://github.com/buckket/twtxt/issues/3#issuecomment-182738604
2016-02-11 03:00:58 -08:00
4 changed files with 47 additions and 17 deletions

View File

@ -1,5 +1,7 @@
<p>welcome to the twtxt list. this is an openly available list of users of <a href="https://github.com/buckket/twtxt">twtxt</a>, the decentralized microblogging tool. this will poll every submitted user every 5 minutes to update its view.</p>
<p>this site currently indexes {{ users }} users and {{ tweets }} tweets.</p>
<h3>links</h3>
<ul>

View File

@ -1,7 +1,8 @@
import db_sqlite, json, httpclient, os, strutils, times, time/gotime
const
ISOTime*: string = "yyyy-MM-dd'T'HH:mm:ss'.000000+'zzz"
ISOTime*: string = "yyyy-MM-dd'T'HH:mm:ss'+'zzz"
version: string = staticExec "git describe --tags --long"
type
Tweet* = object of RootObj
@ -49,11 +50,13 @@ proc fromDBRow*(r: Row): Tweet =
proc getTweetsFrom*(url: string, username: string): seq[Tweet] =
var res = newSeq[Tweet]()
let body = url.getContent(timeout=20_000)
let body = url.getContent(timeout=20_000, userAgent = "twtxtlist/" & version & " (+https://xena.greedo.xeserv.us/files/xena.txt; @xena)")
for line in body.splitLines().items():
if line.len > 0 and line[0] != '#':
res.add(username.parseTweet(line))
try:
res.add(username.parseTweet(line))
except: echo username & " " & getCurrentExceptionMsg()
return res
@ -67,14 +70,4 @@ proc updateTweetsByUser*(db: DBConn, username, url: string) {. gcsafe .} =
db.exec(sql"insert into tweets values(null, ?, ?, ?);", username, tweet.date.timeInfoToTime().toSeconds().int(), tweet.message)
except: discard
except:
echo getCurrentExceptionMsg()
proc updateTweetsOnce*() {. gcsafe .} =
var db = open("./data/twtxt.db", nil, nil, nil)
var users = db.getAllRows sql"select * from users where username != 'twtxtlist'"
for user in users.items():
echo "updating " & $user
db.updateTweetsByUser(user[1], user[2])
echo username & " " & getCurrentExceptionMsg()

View File

@ -1,4 +1,4 @@
import asyncdispatch, db_sqlite, httpclient, jester, moustachu, os, shorturl,
import asyncdispatch, db_sqlite, httpclient, jester, json, moustachu, os, shorturl,
strutils, tables, templates/all, times, tweet/parse, twtxt, typetraits
let
@ -55,7 +55,15 @@ settings:
routes:
get "/":
renderMustache("home", indexTemplate, newContext())
var ctx = newContext()
let
users = db.getValue sql"select count(*) from users"
tweets = db.getValue sql"select count(*) from tweets"
ctx["users"] = users
ctx["tweets"] = tweets
renderMustache("home", indexTemplate, ctx)
get "/changelog":
const log = staticExec "git log -10"
@ -93,6 +101,9 @@ routes:
db.updateTweetsByUser(username, url)
db.exec(sql"insert into users values (null, ?, ?)", username, url)
db.exec(sql"insert into tweets values (null, 'twtxtlist', ?, ?)",
$(getTime().getGMTime().timeinfoToTime().toSeconds()),
"Added user @<" & username & " " & url & ">")
redirect "/users/" & username & "/0"
except: fail()
@ -114,6 +125,20 @@ routes:
renderMustache "users", usersTemplate, ctx
get "/users.txt":
let
headers = {
"Content-Type": "text/plain"
}
users = db.getAllRows(sql"select username, url from users order by username")
var outBuf = ""
for user in users.items():
outBuf &= "twtxt follow " & user[0] & " " & user[1] & "\r\n"
resp Http200, headers, outBuf
get "/users/@name/@page":
try:
var
@ -160,7 +185,7 @@ routes:
get "/timeline/@page":
try:
var
tweets = db.getAllRows(sql"select * from tweets order by time desc limit 20 offset ?", (@"page").parseInt() * 20)
tweets = db.getAllRows(sql"select * from tweets where username <> 'twtxtlist' and username <> 'directory' order by time desc limit 20 offset ?", (@"page").parseInt() * 20)
ctx = newContext()
tweetList = newSeq[Context]()

View File

@ -1,5 +1,15 @@
import db_sqlite, os, streams, threadpool, twtxt
proc updateTweetsOnce() {. gcsafe .} =
var db = open("./data/twtxt.db", nil, nil, nil)
var users = db.getAllRows sql"select * from users where username != 'twtxtlist'"
for user in users.items():
echo "updating " & $user
spawn db.updateTweetsByUser(user[1], user[2])
proc updateSystemUser() =
let
fname = "public" / "twtxt.txt"