Skip to content

Commit

Permalink
Removed commented out code
Browse files Browse the repository at this point in the history
  • Loading branch information
revue-de-presse committed Jul 14, 2023
1 parent a1b746f commit 6cf3a5d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 37 deletions.
61 changes: 34 additions & 27 deletions src/twitter/api_client.clj
Original file line number Diff line number Diff line change
Expand Up @@ -99,32 +99,35 @@
[]
(let [bearer-token (str "Bearer " (:bearer-token env))
fallback-endpoint (str (:fallback-endpoint env))
response (http-client/post fallback-endpoint
{:content-type :json
:accept :json
:cookie-spec (fn [http-context]
(proxy [org.apache.http.impl.cookie.CookieSpecBase] []
;; Version and version header
(getVersion [] 0)
(getVersionHeader [] nil)
;; parse headers into cookie objects
(parse [header cookie-origin] (java.util.ArrayList.))
;; Validate a cookie, throwing MalformedCookieException if the
;; cookies isn't valid
(validate [cookie cookie-origin]
(println "validating:" cookie))
;; Determine if a cookie matches the target location
(match [cookie cookie-origin] true)
;; Format a list of cookies into a list of headers
(formatCookies [cookies] (java.util.ArrayList.))))
:headers {
:authorization bearer-token,
:accept-language "fr-FR,en;q=0.5",
:connection "keep-alive",
:x-guest-token "",
:x-twitter-active-user "yes",
:authority "api.twitter.com",
:DNT "1"}})
response (try
(http-client/post fallback-endpoint
{:content-type :json
:accept :json
:cookie-spec (fn [http-context]
(proxy [org.apache.http.impl.cookie.CookieSpecBase] []
;; Version and version header
(getVersion [] 0)
(getVersionHeader [] nil)
;; parse headers into cookie objects
(parse [header cookie-origin] (java.util.ArrayList.))
;; Validate a cookie, throwing MalformedCookieException if the
;; cookies isn't valid
(validate [cookie cookie-origin]
(println "validating:" cookie))
;; Determine if a cookie matches the target location
(match [cookie cookie-origin] true)
;; Format a list of cookies into a list of headers
(formatCookies [cookies] (java.util.ArrayList.))))
:headers {
:authorization bearer-token,
:accept-language "fr-FR,en;q=0.5",
:connection "keep-alive",
:x-guest-token "",
:x-twitter-active-user "yes",
:authority "api.twitter.com",
:DNT "1"}})
(catch Exception e
(error-handler/log-error e)))
parsed-body (json/read-str (:body response))
guest-token (get parsed-body "guest_token")]
guest-token))
Expand Down Expand Up @@ -414,7 +417,10 @@
(do
(try
(let [fallback-token @next-token
shall-retry (nil? retry)
props-or-status-id (if
(nil? (:status-id props))
(:status-id props)
props)
bearer-token (str "Bearer " (:bearer-token env))
variables (json/write-str {"focalTweetId" status-id
"with_rux_injections" false
Expand Down Expand Up @@ -529,6 +535,7 @@
(handle-rate-limit-exceeded-error "statuses/show/:id" token-model token-type-model)
(get-twitter-status-by-id props token-model token-type-model))
(string/includes? (.getMessage e) error-no-status) {:error error-no-status}
(string/includes? (.getMessage e) error-empty-body) {:error error-empty-body}
(string/includes? (.getMessage e) error-missing-status-id) {:error error-missing-status-id}
:else (do
(error-handler e)
Expand Down
11 changes: 1 addition & 10 deletions src/twitter/status.clj
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@
(defn fetch-statuses
[statuses token token-type]
(let [_ (find-next-token token token-type "statuses/show/:id" "trying to call \"statuses/show\" with an id")
;remaining-calls (how-many-remaining-calls-for-statuses token token-type)
filtered-statuses (remove #(nil? (:status-id %)) statuses)
total-statuses (count filtered-statuses)
pad (take 150 (iterate (constantly nil) nil))
Expand All @@ -235,12 +234,4 @@
(timbre/info (str "No need to find some status.")))
mapped-tweets (doall (map (pmap-by-id token token-type) filtered-statuses-chunk))
fmapped-tweets (flatten mapped-tweets)]
fmapped-tweets
;(if
; (and
; (not (nil? remaining-calls))
; (< total-statuses remaining-calls))
; (doall (pmap #(get-status-by-id % token token-type) filtered-statuses))
; (doall (map #(get-status-by-id % token token-type) filtered-statuses))))
)
)
fmapped-tweets))

0 comments on commit 6cf3a5d

Please sign in to comment.