2019-08-11 19:26:37 +00:00
|
|
|
import times, sequtils, options
|
2019-06-20 18:04:18 +00:00
|
|
|
import norm/sqlite
|
2019-06-20 14:16:20 +00:00
|
|
|
|
2019-06-20 18:04:18 +00:00
|
|
|
export sqlite, options
|
|
|
|
|
2019-08-06 17:02:38 +00:00
|
|
|
type
|
|
|
|
VideoType* = enum
|
|
|
|
vmap, m3u8, mp4
|
|
|
|
|
2019-06-20 18:04:18 +00:00
|
|
|
db("cache.db", "", "", ""):
|
|
|
|
type
|
|
|
|
Profile* = object
|
|
|
|
username*: string
|
|
|
|
fullname*: string
|
2019-08-11 19:26:55 +00:00
|
|
|
location*: string
|
|
|
|
website*: string
|
2019-06-24 00:09:32 +00:00
|
|
|
bio*: string
|
2019-06-20 18:04:18 +00:00
|
|
|
userpic*: string
|
|
|
|
banner*: string
|
|
|
|
following*: string
|
|
|
|
followers*: string
|
|
|
|
tweets*: string
|
2019-08-11 19:26:55 +00:00
|
|
|
likes*: string
|
2019-06-20 18:04:18 +00:00
|
|
|
verified* {.
|
|
|
|
dbType: "STRING",
|
|
|
|
parseIt: parseBool(it.s)
|
|
|
|
formatIt: $it
|
|
|
|
.}: bool
|
|
|
|
protected* {.
|
|
|
|
dbType: "STRING",
|
|
|
|
parseIt: parseBool(it.s)
|
|
|
|
formatIt: $it
|
|
|
|
.}: bool
|
2019-08-11 19:26:55 +00:00
|
|
|
joinDate* {.
|
|
|
|
dbType: "INTEGER",
|
|
|
|
parseIt: it.i.fromUnix(),
|
|
|
|
formatIt: it.toUnix()
|
|
|
|
.}: Time
|
2019-06-20 18:04:18 +00:00
|
|
|
updated* {.
|
|
|
|
dbType: "INTEGER",
|
|
|
|
parseIt: it.i.fromUnix(),
|
|
|
|
formatIt: getTime().toUnix()
|
|
|
|
.}: Time
|
2019-06-20 14:16:20 +00:00
|
|
|
|
2019-08-06 17:02:38 +00:00
|
|
|
Video* = object
|
|
|
|
videoId*: string
|
|
|
|
contentId*: string
|
|
|
|
durationMs*: int
|
|
|
|
url*: string
|
|
|
|
thumb*: string
|
|
|
|
views*: string
|
|
|
|
playbackType* {.
|
|
|
|
dbType: "STRING",
|
|
|
|
parseIt: parseEnum[VideoType](it.s),
|
|
|
|
formatIt: $it,
|
|
|
|
.}: VideoType
|
|
|
|
available* {.
|
|
|
|
dbType: "STRING",
|
|
|
|
parseIt: parseBool(it.s)
|
|
|
|
formatIt: $it
|
|
|
|
.}: bool
|
|
|
|
|
2019-06-20 18:04:18 +00:00
|
|
|
type
|
2019-07-11 17:22:23 +00:00
|
|
|
QueryKind* = enum
|
2019-08-06 15:41:06 +00:00
|
|
|
replies, media, multi, custom = "search"
|
2019-07-03 09:46:03 +00:00
|
|
|
|
|
|
|
Query* = object
|
2019-07-11 17:22:23 +00:00
|
|
|
kind*: QueryKind
|
2019-07-04 09:55:19 +00:00
|
|
|
filters*: seq[string]
|
|
|
|
includes*: seq[string]
|
|
|
|
excludes*: seq[string]
|
2019-08-06 15:41:06 +00:00
|
|
|
fromUser*: seq[string]
|
2019-07-04 09:55:19 +00:00
|
|
|
sep*: string
|
2019-07-03 09:46:03 +00:00
|
|
|
|
2019-06-24 03:14:14 +00:00
|
|
|
Gif* = object
|
|
|
|
url*: string
|
|
|
|
thumb*: string
|
|
|
|
|
2019-07-04 02:18:32 +00:00
|
|
|
GalleryPhoto* = object
|
|
|
|
url*: string
|
|
|
|
tweetId*: string
|
|
|
|
color*: string
|
|
|
|
|
2019-06-29 12:11:23 +00:00
|
|
|
Poll* = object
|
|
|
|
options*: seq[string]
|
|
|
|
values*: seq[int]
|
|
|
|
votes*: string
|
|
|
|
status*: string
|
|
|
|
leader*: int
|
|
|
|
|
2019-07-11 17:22:23 +00:00
|
|
|
CardKind* = enum
|
2019-07-15 14:03:01 +00:00
|
|
|
summary = "summary"
|
|
|
|
summaryLarge = "summary_large_image"
|
|
|
|
promoWebsite = "promo_website"
|
|
|
|
promoVideo = "promo_video_website"
|
|
|
|
player = "player"
|
|
|
|
liveEvent = "live_event"
|
2019-07-11 17:22:23 +00:00
|
|
|
|
|
|
|
Card* = object
|
|
|
|
kind*: CardKind
|
|
|
|
id*: string
|
|
|
|
query*: string
|
|
|
|
url*: string
|
|
|
|
title*: string
|
|
|
|
dest*: string
|
|
|
|
text*: string
|
2019-07-15 14:03:01 +00:00
|
|
|
image*: Option[string]
|
|
|
|
video*: Option[Video]
|
2019-07-11 17:22:23 +00:00
|
|
|
|
2019-06-24 06:07:36 +00:00
|
|
|
Quote* = object
|
2019-06-24 03:14:14 +00:00
|
|
|
id*: string
|
|
|
|
profile*: Profile
|
|
|
|
text*: string
|
2019-07-01 22:52:50 +00:00
|
|
|
reply*: seq[string]
|
|
|
|
hasThread*: bool
|
2019-06-25 00:58:33 +00:00
|
|
|
sensitive*: bool
|
2019-07-04 02:38:23 +00:00
|
|
|
available*: bool
|
2019-07-01 22:52:50 +00:00
|
|
|
thumb*: string
|
|
|
|
badge*: string
|
2019-06-24 03:14:14 +00:00
|
|
|
|
2019-07-01 21:22:00 +00:00
|
|
|
Retweet* = object
|
|
|
|
by*: string
|
|
|
|
id*: string
|
|
|
|
|
2019-07-01 21:48:25 +00:00
|
|
|
TweetStats* = object
|
|
|
|
replies*: string
|
|
|
|
retweets*: string
|
|
|
|
likes*: string
|
|
|
|
|
2019-06-24 03:14:14 +00:00
|
|
|
Tweet* = ref object
|
2019-06-20 14:16:20 +00:00
|
|
|
id*: string
|
2019-07-04 12:54:15 +00:00
|
|
|
threadId*: string
|
2019-06-20 14:16:20 +00:00
|
|
|
profile*: Profile
|
|
|
|
text*: string
|
|
|
|
time*: Time
|
|
|
|
shortTime*: string
|
2019-07-01 22:52:50 +00:00
|
|
|
reply*: seq[string]
|
2019-06-20 14:16:20 +00:00
|
|
|
pinned*: bool
|
2019-07-01 22:52:50 +00:00
|
|
|
available*: bool
|
|
|
|
hasThread*: bool
|
2019-07-01 21:48:25 +00:00
|
|
|
stats*: TweetStats
|
2019-07-01 21:22:00 +00:00
|
|
|
retweet*: Option[Retweet]
|
2019-06-24 03:14:14 +00:00
|
|
|
quote*: Option[Quote]
|
2019-07-11 17:22:23 +00:00
|
|
|
card*: Option[Card]
|
2019-06-24 03:14:14 +00:00
|
|
|
gif*: Option[Gif]
|
|
|
|
video*: Option[Video]
|
|
|
|
photos*: seq[string]
|
2019-06-29 12:11:23 +00:00
|
|
|
poll*: Option[Poll]
|
2019-06-20 14:16:20 +00:00
|
|
|
|
2019-07-03 05:18:19 +00:00
|
|
|
Thread* = ref object
|
2019-07-01 01:13:12 +00:00
|
|
|
tweets*: seq[Tweet]
|
|
|
|
more*: int
|
2019-06-20 14:16:20 +00:00
|
|
|
|
2019-06-24 03:14:14 +00:00
|
|
|
Conversation* = ref object
|
2019-06-20 14:16:20 +00:00
|
|
|
tweet*: Tweet
|
2019-07-01 01:13:12 +00:00
|
|
|
before*: Thread
|
|
|
|
after*: Thread
|
|
|
|
replies*: seq[Thread]
|
2019-06-20 14:16:20 +00:00
|
|
|
|
2019-06-25 05:36:36 +00:00
|
|
|
Timeline* = ref object
|
2019-07-01 01:13:12 +00:00
|
|
|
tweets*: seq[Tweet]
|
2019-06-25 05:36:36 +00:00
|
|
|
minId*: string
|
|
|
|
maxId*: string
|
|
|
|
hasMore*: bool
|
2019-07-10 22:42:31 +00:00
|
|
|
beginning*: bool
|
2019-07-03 09:46:03 +00:00
|
|
|
query*: Option[Query]
|
2019-06-25 05:36:36 +00:00
|
|
|
|
2019-07-31 00:15:43 +00:00
|
|
|
Config* = ref object
|
|
|
|
address*: string
|
|
|
|
port*: int
|
|
|
|
title*: string
|
|
|
|
staticDir*: string
|
|
|
|
cacheDir*: string
|
|
|
|
profileCacheTime*: int
|
|
|
|
|
2019-07-01 01:13:12 +00:00
|
|
|
proc contains*(thread: Thread; tweet: Tweet): bool =
|
|
|
|
thread.tweets.anyIt(it.id == tweet.id)
|