revert the time fix
This commit is contained in:
parent
a9b8d923ba
commit
623d7c920a
|
@ -2,7 +2,7 @@ import times
|
||||||
|
|
||||||
proc fixTime(p0: cstring): ptr clonglong {. importc, dynlib: "./gotime.so", noSideEffect .}
|
proc fixTime(p0: cstring): ptr clonglong {. importc, dynlib: "./gotime.so", noSideEffect .}
|
||||||
|
|
||||||
proc parseTime*(inp: string): int =
|
proc parseTime*(inp: string): TimeInfo =
|
||||||
let
|
let
|
||||||
cst = inp.cstring
|
cst = inp.cstring
|
||||||
res = cst.fixTime
|
res = cst.fixTime
|
||||||
|
@ -12,8 +12,9 @@ proc parseTime*(inp: string): int =
|
||||||
|
|
||||||
let
|
let
|
||||||
resdep = res[]
|
resdep = res[]
|
||||||
|
restime = resdep.fromSeconds
|
||||||
|
|
||||||
return resdep.int
|
return restime.timeToTimeInfo
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
let myTime = fixTime("2006-01-02T15:04:05.000000-07:00")
|
let myTime = fixTime("2006-01-02T15:04:05.000000-07:00")
|
||||||
|
|
|
@ -6,17 +6,17 @@ const
|
||||||
|
|
||||||
type
|
type
|
||||||
Tweet* = object of RootObj
|
Tweet* = object of RootObj
|
||||||
date*: int
|
date*: TimeInfo
|
||||||
message*: string
|
message*: string
|
||||||
username*: string
|
username*: string
|
||||||
|
|
||||||
proc `$`*(t: Tweet): 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 =
|
proc `%`*(t: Tweet): JsonNode =
|
||||||
%*
|
%*
|
||||||
{
|
{
|
||||||
"date": t.date,
|
"date": t.date.format(ISOTime),
|
||||||
"message": t.message,
|
"message": t.message,
|
||||||
"username": t.username,
|
"username": t.username,
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ proc parseTweet*(user, inp: string): Tweet =
|
||||||
splitTweet = inp.split '\t'
|
splitTweet = inp.split '\t'
|
||||||
|
|
||||||
if splitTweet.len != 2:
|
if splitTweet.len != 2:
|
||||||
raise newException(ValueError, "Invalid tweet " & inp)
|
raise newException(ValueError, "Invalid tweet")
|
||||||
|
|
||||||
let
|
let
|
||||||
tdate = splitTweet[0].parseTime
|
tdate = splitTweet[0].parseTime
|
||||||
|
@ -43,7 +43,7 @@ proc parseTweet*(user, inp: string): Tweet =
|
||||||
username: user)
|
username: user)
|
||||||
|
|
||||||
proc fromDBRow*(r: Row): Tweet =
|
proc fromDBRow*(r: Row): Tweet =
|
||||||
Tweet(date: r[2].split(".")[0].parseInt(),
|
Tweet(date: r[2].split(".")[0].parseInt().fromSeconds().timeToTimeInfo(),
|
||||||
username: r[1],
|
username: r[1],
|
||||||
message: r[3])
|
message: r[3])
|
||||||
|
|
||||||
|
@ -65,21 +65,9 @@ proc updateTweetsByUser*(db: DBConn, username, url: string) {. gcsafe .} =
|
||||||
let
|
let
|
||||||
tweets = getTweetsFrom(url, username)
|
tweets = getTweetsFrom(url, username)
|
||||||
|
|
||||||
var counter = 0
|
|
||||||
|
|
||||||
for tweet in tweets.items():
|
for tweet in tweets.items():
|
||||||
try:
|
try:
|
||||||
db.exec(sql"insert into tweets values(null, ?, ?, ?);", username, tweet.date, tweet.message)
|
db.exec(sql"insert into tweets values(null, ?, ?, ?);", username, tweet.date.timeInfoToTime().toSeconds().int(), tweet.message)
|
||||||
echo "Adding tweet " & $(%tweet)
|
|
||||||
counter = counter + 1
|
|
||||||
except: discard
|
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:
|
except:
|
||||||
echo username & " " & getCurrentExceptionMsg()
|
echo username & " " & getCurrentExceptionMsg()
|
||||||
|
|
|
@ -103,7 +103,7 @@ routes:
|
||||||
db.exec(sql"insert into users values (null, ?, ?)", username, url)
|
db.exec(sql"insert into users values (null, ?, ?)", username, url)
|
||||||
db.exec(sql"insert into tweets values (null, 'twtxtlist', ?, ?)",
|
db.exec(sql"insert into tweets values (null, 'twtxtlist', ?, ?)",
|
||||||
$(getTime().getGMTime().timeinfoToTime().toSeconds()),
|
$(getTime().getGMTime().timeinfoToTime().toSeconds()),
|
||||||
"Added user @<" & username & " " & url & ">")
|
"Added user <@" & username & " " & url & ">")
|
||||||
|
|
||||||
redirect "/users/" & username & "/0"
|
redirect "/users/" & username & "/0"
|
||||||
except: fail()
|
except: fail()
|
||||||
|
|
Loading…
Reference in New Issue