Add simple job_details card support
This commit is contained in:
@@ -12,7 +12,7 @@ proc parseGraphUser*(json: string): User =
|
||||
if raw.data.userResult.result.unavailableReason.get("") == "Suspended":
|
||||
return User(suspended: true)
|
||||
|
||||
result = toUser raw.data.userResult.result.legacy
|
||||
result = raw.data.userResult.result.legacy
|
||||
result.id = raw.data.userResult.result.restId
|
||||
result.verified = result.verified or raw.data.userResult.result.isBlueVerified
|
||||
|
||||
@@ -30,7 +30,7 @@ proc parseGraphListMembers*(json, cursor: string): Result[User] =
|
||||
of TimelineTimelineItem:
|
||||
let userResult = entry.content.itemContent.userResults.result
|
||||
if userResult.restId.len > 0:
|
||||
result.content.add toUser userResult.legacy
|
||||
result.content.add userResult.legacy
|
||||
of TimelineTimelineCursor:
|
||||
if entry.content.cursorType == "Bottom":
|
||||
result.bottom = entry.content.value
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import std/[options, tables, strutils, strformat, sugar]
|
||||
import jsony
|
||||
import user
|
||||
import ../types/unifiedcard
|
||||
from ../../types import Card, CardKind, Video
|
||||
from ../../utils import twimg, https
|
||||
@@ -27,6 +28,14 @@ proc parseMediaDetails(data: ComponentData; card: UnifiedCard; result: var Card)
|
||||
result.text = data.topicDetail.title
|
||||
result.dest = "Topic"
|
||||
|
||||
proc parseJobDetails(data: ComponentData; card: UnifiedCard; result: var Card) =
|
||||
data.destination.parseDestination(card, result)
|
||||
|
||||
result.kind = jobDetails
|
||||
result.title = data.title
|
||||
result.text = data.shortDescriptionText
|
||||
result.dest = &"@{data.profileUser.username} · {data.location}"
|
||||
|
||||
proc parseAppDetails(data: ComponentData; card: UnifiedCard; result: var Card) =
|
||||
let app = card.appStoreData[data.appId][0]
|
||||
|
||||
@@ -84,6 +93,8 @@ proc parseUnifiedCard*(json: string): Card =
|
||||
component.parseMedia(card, result)
|
||||
of buttonGroup:
|
||||
discard
|
||||
of jobDetails:
|
||||
component.data.parseJobDetails(card, result)
|
||||
of ComponentType.hidden:
|
||||
result.kind = CardKind.hidden
|
||||
of ComponentType.unknown:
|
||||
|
||||
@@ -68,6 +68,11 @@ proc toUser*(raw: RawUser): User =
|
||||
|
||||
result.expandUserEntities(raw)
|
||||
|
||||
proc parseHook*(s: string; i: var int; v: var User) =
|
||||
var u: RawUser
|
||||
parseHook(s, i, u)
|
||||
v = toUser u
|
||||
|
||||
proc parseUser*(json: string; username=""): User =
|
||||
handleErrors:
|
||||
case error.code
|
||||
@@ -75,7 +80,7 @@ proc parseUser*(json: string; username=""): User =
|
||||
of userNotFound: return
|
||||
else: echo "[error - parseUser]: ", error
|
||||
|
||||
result = toUser json.fromJson(RawUser)
|
||||
result = json.fromJson(User)
|
||||
|
||||
proc parseUsers*(json: string; after=""): Result[User] =
|
||||
result = Result[User](beginning: after.len == 0)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import options
|
||||
import user
|
||||
from ../../types import User
|
||||
|
||||
type
|
||||
GraphUser* = object
|
||||
@@ -9,7 +9,7 @@ type
|
||||
result*: UserResult
|
||||
|
||||
UserResult = object
|
||||
legacy*: RawUser
|
||||
legacy*: User
|
||||
restId*: string
|
||||
isBlueVerified*: bool
|
||||
unavailableReason*: Option[string]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import std/tables
|
||||
import user
|
||||
from ../../types import User
|
||||
|
||||
type
|
||||
Search* = object
|
||||
@@ -7,7 +7,7 @@ type
|
||||
timeline*: Timeline
|
||||
|
||||
GlobalObjects = object
|
||||
users*: Table[string, RawUser]
|
||||
users*: Table[string, User]
|
||||
|
||||
Timeline = object
|
||||
instructions*: seq[Instructions]
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import options, tables
|
||||
from ../../types import VideoType, VideoVariant
|
||||
import std/[options, tables, times]
|
||||
import jsony
|
||||
from ../../types import VideoType, VideoVariant, User
|
||||
|
||||
type
|
||||
Text* = distinct string
|
||||
|
||||
UnifiedCard* = object
|
||||
componentObjects*: Table[string, Component]
|
||||
destinationObjects*: Table[string, Destination]
|
||||
@@ -13,6 +16,7 @@ type
|
||||
media
|
||||
swipeableMedia
|
||||
buttonGroup
|
||||
jobDetails
|
||||
appStoreDetails
|
||||
twitterListDetails
|
||||
communityDetails
|
||||
@@ -29,12 +33,15 @@ type
|
||||
appId*: string
|
||||
mediaId*: string
|
||||
destination*: string
|
||||
location*: string
|
||||
title*: Text
|
||||
subtitle*: Text
|
||||
name*: Text
|
||||
memberCount*: int
|
||||
mediaList*: seq[MediaItem]
|
||||
topicDetail*: tuple[title: Text]
|
||||
profileUser*: User
|
||||
shortDescriptionText*: string
|
||||
|
||||
MediaItem* = object
|
||||
id*: string
|
||||
@@ -69,12 +76,9 @@ type
|
||||
title*: Text
|
||||
category*: Text
|
||||
|
||||
Text = object
|
||||
content: string
|
||||
|
||||
TypeField = Component | Destination | MediaEntity | AppStoreData
|
||||
|
||||
converter fromText*(text: Text): string = text.content
|
||||
converter fromText*(text: Text): string = string(text)
|
||||
|
||||
proc renameHook*(v: var TypeField; fieldName: var string) =
|
||||
if fieldName == "type":
|
||||
@@ -86,6 +90,7 @@ proc enumHook*(s: string; v: var ComponentType) =
|
||||
of "media": media
|
||||
of "swipeable_media": swipeableMedia
|
||||
of "button_group": buttonGroup
|
||||
of "job_details": jobDetails
|
||||
of "app_store_details": appStoreDetails
|
||||
of "twitter_list_details": twitterListDetails
|
||||
of "community_details": communityDetails
|
||||
@@ -106,3 +111,18 @@ proc enumHook*(s: string; v: var MediaType) =
|
||||
of "photo": photo
|
||||
of "model3d": model3d
|
||||
else: echo "ERROR: Unknown enum value (MediaType): ", s; photo
|
||||
|
||||
proc parseHook*(s: string; i: var int; v: var DateTime) =
|
||||
var str: string
|
||||
parseHook(s, i, str)
|
||||
v = parse(str, "yyyy-MM-dd hh:mm:ss")
|
||||
|
||||
proc parseHook*(s: string; i: var int; v: var Text) =
|
||||
if s[i] == '"':
|
||||
var str: string
|
||||
parseHook(s, i, str)
|
||||
v = Text(str)
|
||||
else:
|
||||
var t: tuple[content: string]
|
||||
parseHook(s, i, t)
|
||||
v = Text(t.content)
|
||||
|
||||
Reference in New Issue
Block a user