mirror of
https://github.com/zedeus/nitter
synced 2026-10-26 20:53:25 +00:00
Parse user counts/bio from modern GraphQL shape
This commit is contained in:
parent
fcaab5079e
commit
62aa2f2823
3 changed files with 44 additions and 7 deletions
|
|
@ -10,11 +10,16 @@ proc parseUserResult*(userResult: UserResult): User =
|
|||
result.verifiedType = blue
|
||||
|
||||
if result.username.len == 0 and userResult.core.screenName.len > 0:
|
||||
# Modern UserByRestId/UserByScreenName shape: `legacy` is empty and the data
|
||||
# lives in typed sub-objects (core/relationship_counts/tweet_counts/etc.).
|
||||
result.id = userResult.restId
|
||||
result.username = userResult.core.screenName
|
||||
result.fullname = userResult.core.name
|
||||
result.userPic = userResult.avatar.imageUrl.replace("_normal", "")
|
||||
|
||||
if userResult.banner.imageUrl.len > 0:
|
||||
result.banner = userResult.banner.imageUrl & "/1500x500"
|
||||
|
||||
if userResult.privacy.isSome:
|
||||
result.protected = userResult.privacy.get.protected
|
||||
|
||||
|
|
@ -29,8 +34,23 @@ proc parseUserResult*(userResult: UserResult): User =
|
|||
if v.verifiedType != VerifiedType.none:
|
||||
result.verifiedType = v.verifiedType
|
||||
|
||||
if userResult.profileBio.isSome and result.bio.len == 0:
|
||||
result.bio = userResult.profileBio.get.description
|
||||
if userResult.relationshipCounts.isSome:
|
||||
let rc = userResult.relationshipCounts.get
|
||||
result.followers = rc.followers
|
||||
result.following = rc.following
|
||||
|
||||
if userResult.tweetCounts.isSome:
|
||||
let tc = userResult.tweetCounts.get
|
||||
result.tweets = tc.tweets
|
||||
result.media = tc.mediaTweets
|
||||
|
||||
if userResult.actionCounts.isSome:
|
||||
result.likes = userResult.actionCounts.get.favoritesCount
|
||||
|
||||
if userResult.profileBio.isSome:
|
||||
let bio = userResult.profileBio.get
|
||||
result.bio = bio.description
|
||||
result.expandUserEntities(bio.entities)
|
||||
|
||||
proc parseGraphUser*(json: string): User =
|
||||
if json.len == 0 or json[0] != '{':
|
||||
|
|
|
|||
|
|
@ -11,10 +11,8 @@ let
|
|||
htRegex = nre.re"""(*U)(^|[^\w-_.?])([##$])([\w_]*+)(?!</a>|">|#)"""
|
||||
htReplace = "$1<a href=\"/search?f=tweets&q=%23$3\">$2$3</a>"
|
||||
|
||||
proc expandUserEntities(user: var User; raw: RawUser) =
|
||||
let
|
||||
orig = user.bio.toRunes
|
||||
ent = raw.entities
|
||||
proc expandUserEntities*(user: var User; ent: Entities) =
|
||||
let orig = user.bio.toRunes
|
||||
|
||||
if ent.url.urls.len > 0:
|
||||
user.website = ent.url.urls[0].expandedUrl
|
||||
|
|
@ -68,7 +66,7 @@ proc toUser*(raw: RawUser): User =
|
|||
if raw.pinnedTweetIdsStr.len > 0:
|
||||
result.pinnedTweet = parseBiggestInt(raw.pinnedTweetIdsStr[0])
|
||||
|
||||
result.expandUserEntities(raw)
|
||||
result.expandUserEntities(raw.entities)
|
||||
|
||||
proc parseHook*(s: string; i: var int; v: var User) =
|
||||
var u: RawUser
|
||||
|
|
|
|||
Loading…
Reference in a new issue