mirror of
https://github.com/zedeus/nitter
synced 2026-10-26 20:53:25 +00:00
parent
1e03595784
commit
55a331cc50
9 changed files with 185 additions and 9 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import options, strutils
|
||||
import jsony
|
||||
import user, utils, ../types/[graphuser, graphlistmembers]
|
||||
import user, utils, ../types/[graphuser, graphlistmembers, graphfollowers]
|
||||
from ../../types import User, VerifiedType, Result, Query, QueryKind
|
||||
|
||||
proc parseUserResult*(userResult: UserResult): User =
|
||||
|
|
@ -67,3 +67,25 @@ proc parseGraphListMembers*(json, cursor: string): Result[User] =
|
|||
of TimelineTimelineCursor:
|
||||
if entry.content.cursorType == "Bottom":
|
||||
result.bottom = entry.content.value
|
||||
|
||||
proc parseGraphFollowers*(json, cursor: string; kind: QueryKind): Result[User] =
|
||||
result = Result[User](
|
||||
beginning: cursor.len == 0,
|
||||
query: Query(kind: kind)
|
||||
)
|
||||
|
||||
if json.len == 0 or json[0] != '{':
|
||||
return
|
||||
|
||||
let raw = json.fromJson(GraphFollowers)
|
||||
for instruction in raw.data.user.result.timeline.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:
|
||||
result.content.add parseUserResult(userResult)
|
||||
of TimelineTimelineCursor:
|
||||
if entry.content.cursorType == "Bottom":
|
||||
result.bottom = entry.content.value
|
||||
|
|
|
|||
17
src/experimental/types/graphfollowers.nim
Normal file
17
src/experimental/types/graphfollowers.nim
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
import graphlistmembers
|
||||
|
||||
type
|
||||
GraphFollowers* = object
|
||||
data*: tuple[user: UserWrapper]
|
||||
|
||||
UserWrapper = object
|
||||
result*: UserResultWrapper
|
||||
|
||||
UserResultWrapper = object
|
||||
timeline*: tuple[timeline: graphlistmembers.Timeline]
|
||||
|
||||
# Hook to normalize snake_case field from API to camelCase used by shared types
|
||||
proc renameHook*(v: var Content; fieldName: var string) =
|
||||
if fieldName == "user_results":
|
||||
fieldName = "userResults"
|
||||
|
|
@ -7,10 +7,10 @@ type
|
|||
List = object
|
||||
membersTimeline*: tuple[timeline: Timeline]
|
||||
|
||||
Timeline = object
|
||||
Timeline* = object
|
||||
instructions*: seq[Instruction]
|
||||
|
||||
Instruction = object
|
||||
Instruction* = object
|
||||
kind*: string
|
||||
entries*: seq[tuple[content: Content]]
|
||||
|
||||
|
|
@ -18,7 +18,7 @@ type
|
|||
TimelineTimelineItem
|
||||
TimelineTimelineCursor
|
||||
|
||||
Content = object
|
||||
Content* = object
|
||||
case entryType*: ContentEntryType
|
||||
of TimelineTimelineItem:
|
||||
itemContent*: tuple[userResults: UserData]
|
||||
|
|
|
|||
Loading…
Reference in a new issue