diff --git a/src/time/gotime.nim b/src/time/gotime.nim index 4502577..66fc107 100644 --- a/src/time/gotime.nim +++ b/src/time/gotime.nim @@ -2,7 +2,7 @@ import times proc fixTime(p0: cstring): ptr clonglong {. importc, dynlib: "./gotime.so", noSideEffect .} -proc parseTime*(inp: string): int = +proc parseTime*(inp: string): TimeInfo = let cst = inp.cstring res = cst.fixTime @@ -12,8 +12,9 @@ proc parseTime*(inp: string): int = let resdep = res[] + restime = resdep.fromSeconds - return resdep.int + return restime.timeToTimeInfo when isMainModule: let myTime = fixTime("2006-01-02T15:04:05.000000-07:00") diff --git a/src/twtxt.nim b/src/twtxt.nim index fa8ee38..11c0059 100644 --- a/src/twtxt.nim +++ b/src/twtxt.nim @@ -6,17 +6,17 @@ const type Tweet* = object of RootObj - date*: int + date*: TimeInfo message*: string username*: string proc `$`*(t: Tweet): string = - return t.date.fromSeconds.timeToTimeInfo.format(ISOTime) & " " & t.message + return t.date.format(ISOTime) & " " & t.message proc `%`*(t: Tweet): JsonNode = %* { - "date": t.date, + "date": t.date.format(ISOTime), "message": t.message, "username": t.username, } @@ -32,7 +32,7 @@ proc parseTweet*(user, inp: string): Tweet = splitTweet = inp.split '\t' if splitTweet.len != 2: - raise newException(ValueError, "Invalid tweet " & inp) + raise newException(ValueError, "Invalid tweet") let tdate = splitTweet[0].parseTime @@ -43,7 +43,7 @@ proc parseTweet*(user, inp: string): Tweet = username: user) proc fromDBRow*(r: Row): Tweet = - Tweet(date: r[2].split(".")[0].parseInt(), + Tweet(date: r[2].split(".")[0].parseInt().fromSeconds().timeToTimeInfo(), username: r[1], message: r[3]) @@ -65,21 +65,9 @@ proc updateTweetsByUser*(db: DBConn, username, url: string) {. gcsafe .} = let tweets = getTweetsFrom(url, username) - var counter = 0 - for tweet in tweets.items(): try: - db.exec(sql"insert into tweets values(null, ?, ?, ?);", username, tweet.date, tweet.message) - echo "Adding tweet " & $(%tweet) - counter = counter + 1 + db.exec(sql"insert into tweets values(null, ?, ?, ?);", username, tweet.date.timeInfoToTime().toSeconds().int(), tweet.message) except: discard - - when false: - if counter > 0: - let - msg = "Added " & $counter & " tweets from @<" & username & " " & url & ">" - now = getTime().toSeconds() - - db.exec(sql"insert into tweets values(null, 'twtxtlist', ?, ?);", now, msg) except: echo username & " " & getCurrentExceptionMsg() diff --git a/src/twtxtlist.nim b/src/twtxtlist.nim index 2aee00e..bc02fb8 100644 --- a/src/twtxtlist.nim +++ b/src/twtxtlist.nim @@ -103,7 +103,7 @@ routes: 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 & ">") + "Added user <@" & username & " " & url & ">") redirect "/users/" & username & "/0" except: fail()