nitter/src/experimental/parser/graphql.nim

38 lines
1.3 KiB
Nim
Raw Normal View History

2023-01-20 04:54:19 +01:00
import options
2022-01-26 17:24:03 +01:00
import jsony
import user, ../types/[graphuser, graphlistmembers]
from ../../types import User, VerifiedType, Result, Query, QueryKind
2022-01-26 17:24:03 +01:00
proc parseGraphUser*(json: string): User =
if json.len == 0 or json[0] != '{':
return
2022-01-26 17:24:03 +01:00
let raw = json.fromJson(GraphUser)
2023-01-20 04:54:19 +01:00
if raw.data.userResult.result.unavailableReason.get("") == "Suspended":
2023-01-20 04:54:19 +01:00
return User(suspended: true)
2023-11-25 06:31:15 +01:00
result = raw.data.userResult.result.legacy
result.id = raw.data.userResult.result.restId
2023-11-25 11:11:57 +01:00
if result.verifiedType == VerifiedType.none and raw.data.userResult.result.isBlueVerified:
result.verifiedType = blue
proc parseGraphListMembers*(json, cursor: string): Result[User] =
result = Result[User](
beginning: cursor.len == 0,
query: Query(kind: userList)
)
let raw = json.fromJson(GraphListMembers)
for instruction in raw.data.list.membersTimeline.timeline.instructions:
if instruction.kind == "TimelineAddEntries":
for entry in instruction.entries:
case entry.content.entryType
of TimelineTimelineItem:
let userResult = entry.content.itemContent.userResults.result
if userResult.restId.len > 0:
2023-11-25 06:31:15 +01:00
result.content.add userResult.legacy
of TimelineTimelineCursor:
if entry.content.cursorType == "Bottom":
result.bottom = entry.content.value