From b87cd39bce146c3dd99d96d9703dde4ab63852b3 Mon Sep 17 00:00:00 2001 From: Zed Date: Wed, 22 Jan 2020 14:01:27 +0100 Subject: [PATCH] Remove failed guest ID experiment --- src/api/cookie.nim | 16 ---------------- src/api/list.nim | 2 +- src/api/profile.nim | 2 +- src/api/search.nim | 2 +- src/api/timeline.nim | 2 +- src/api/tweet.nim | 2 +- src/api/utils.nim | 11 ++++------- 7 files changed, 9 insertions(+), 28 deletions(-) delete mode 100644 src/api/cookie.nim diff --git a/src/api/cookie.nim b/src/api/cookie.nim deleted file mode 100644 index 6261a1d..0000000 --- a/src/api/cookie.nim +++ /dev/null @@ -1,16 +0,0 @@ -import httpclient, strutils - -proc getGuestId*(): string = - let client = newHttpClient() - for i in 0 .. 10: - try: - let req = client.get("https://twitter.com") - if "react-root" in req.body: continue - for k, v in req.headers: - if "guest_id" in v: - return v[v.find("=") + 1 .. v.find(";")] - except: - discard - finally: - try: client.close() - except: discard diff --git a/src/api/list.nim b/src/api/list.nim index a46efa0..c92fe6e 100644 --- a/src/api/list.nim +++ b/src/api/list.nim @@ -54,7 +54,7 @@ proc getListMembers*(username, list, after, agent: string): Future[Result[Profil let url = base / (listMembersUrl % [username, list]) - html = await fetchHtml(url, genHeaders(agent, url, guestId=true)) + html = await fetchHtml(url, genHeaders(agent, url)) result = Result[Profile]( minId: html.selectAttr(".stream-container", "data-min-position"), diff --git a/src/api/profile.nim b/src/api/profile.nim index 89f80f0..f66337f 100644 --- a/src/api/profile.nim +++ b/src/api/profile.nim @@ -34,7 +34,7 @@ proc getProfile*(username, agent: string): Future[Profile] {.async.} = proc getProfileFull*(username, agent: string): Future[Profile] {.async.} = let url = base / username - headers = genHeaders(agent, url, auth=true, guestId=true) + headers = genHeaders(agent, url, auth=true) html = await fetchHtml(url, headers) if html == nil: return diff --git a/src/api/search.nim b/src/api/search.nim index 7d1b20c..aadb728 100644 --- a/src/api/search.nim +++ b/src/api/search.nim @@ -23,7 +23,7 @@ proc getSearch*[T](query: Query; after, agent: string; encoded = encodeUrl(param, usePlus=false) referer = base / ("search?f=$1&q=$2&src=typd" % [kind, encoded]) - headers = genHeaders(agent, referer, auth=true, xml=true, guestId=true) + headers = genHeaders(agent, referer, auth=true, xml=true) params = { "f": kind, diff --git a/src/api/timeline.nim b/src/api/timeline.nim index 5aea170..cd10e56 100644 --- a/src/api/timeline.nim +++ b/src/api/timeline.nim @@ -30,7 +30,7 @@ proc getProfileAndTimeline*(username, after, agent: string; url = url ? {"max_position": after} let - headers = genHeaders(agent, base / username, auth=true, guestId=true) + headers = genHeaders(agent, base / username, auth=true) html = await fetchHtml(url, headers) timeline = parseTimeline(html.select("#timeline > .stream-container"), after) profile = parseTimelineProfile(html) diff --git a/src/api/tweet.nim b/src/api/tweet.nim index 028645c..8f5ff17 100644 --- a/src/api/tweet.nim +++ b/src/api/tweet.nim @@ -8,7 +8,7 @@ proc getTweet*(username, id, after, agent: string): Future[Conversation] {.async headers = genHeaders({ "pragma": "no-cache", "x-previous-page-name": "profile" - }, agent, base, xml=true, guestId=true) + }, agent, base, xml=true) url = base / username / tweetUrl / id ? {"max_position": after} html = await fetchHtml(url, headers) diff --git a/src/api/utils.nim b/src/api/utils.nim index 9c3873a..96dcec7 100644 --- a/src/api/utils.nim +++ b/src/api/utils.nim @@ -2,13 +2,11 @@ import httpclient, asyncdispatch, htmlparser, options import strutils, json, xmltree, uri import ../types -import consts, cookie - -var guestIdCookie = "guest_id=" & getGuestId() +import consts proc genHeaders*(headers: openArray[tuple[key: string, val: string]]; agent: string; referer: Uri; lang=true; - auth=false; xml=false; guestId=false): HttpHeaders = + auth=false; xml=false): HttpHeaders = result = newHttpHeaders({ "referer": $referer, "user-agent": agent, @@ -18,14 +16,13 @@ proc genHeaders*(headers: openArray[tuple[key: string, val: string]]; if auth: result["authority"] = "twitter.com" if lang: result["accept-language"] = consts.lang if xml: result["x-requested-with"] = "XMLHttpRequest" - # if guestId: result["cookie"] = guestIdCookie for (key, val) in headers: result[key] = val proc genHeaders*(agent: string; referer: Uri; lang=true; - auth=false; xml=false; guestId=false): HttpHeaders = - genHeaders([], agent, referer, lang, auth, xml, guestId) + auth=false; xml=false): HttpHeaders = + genHeaders([], agent, referer, lang, auth, xml) template newClient*() {.dirty.} = var client = newAsyncHttpClient()