Added --oauth flag to authorize a bot for another account.
This commit is contained in:
parent
d5c325493e
commit
3a68965f11
13
package-lock.json
generated
13
package-lock.json
generated
@ -1273,6 +1273,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/number-is-nan/-/number-is-nan-1.0.1.tgz",
|
||||||
"integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0="
|
"integrity": "sha1-CXtgK1NCKlIsGvuHkDGDNpQaAR0="
|
||||||
},
|
},
|
||||||
|
"oauth": {
|
||||||
|
"version": "0.9.15",
|
||||||
|
"resolved": "https://registry.npmjs.org/oauth/-/oauth-0.9.15.tgz",
|
||||||
|
"integrity": "sha1-vR/vr2hslrdUda7VGWQS/2DPucE="
|
||||||
|
},
|
||||||
"oauth-sign": {
|
"oauth-sign": {
|
||||||
"version": "0.9.0",
|
"version": "0.9.0",
|
||||||
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
|
"resolved": "https://registry.npmjs.org/oauth-sign/-/oauth-sign-0.9.0.tgz",
|
||||||
@ -1923,6 +1928,14 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"twitter-pin": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/twitter-pin/-/twitter-pin-1.0.0.tgz",
|
||||||
|
"integrity": "sha1-nVnamDwASzLG/rCFvPE1781ZNQ4=",
|
||||||
|
"requires": {
|
||||||
|
"oauth": "^0.9.13"
|
||||||
|
}
|
||||||
|
},
|
||||||
"typedarray": {
|
"typedarray": {
|
||||||
"version": "0.0.6",
|
"version": "0.0.6",
|
||||||
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
|
"resolved": "https://registry.npmjs.org/typedarray/-/typedarray-0.0.6.tgz",
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
"sqlite": "^3.0.3",
|
"sqlite": "^3.0.3",
|
||||||
"tmp-promise": "^3.0.2",
|
"tmp-promise": "^3.0.2",
|
||||||
"twit": "^2.2.11",
|
"twit": "^2.2.11",
|
||||||
|
"twitter-pin": "^1.0.0",
|
||||||
"winston": "^3.3.3"
|
"winston": "^3.3.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,7 +17,8 @@
|
|||||||
[lemondronor.advisorycircular.pelias :as pelias]
|
[lemondronor.advisorycircular.pelias :as pelias]
|
||||||
[lemondronor.advisorycircular.twitter :as twitter]
|
[lemondronor.advisorycircular.twitter :as twitter]
|
||||||
[lemondronor.advisorycircular.util :as util]
|
[lemondronor.advisorycircular.util :as util]
|
||||||
["sqlite" :as sqlite]))
|
["sqlite" :as sqlite]
|
||||||
|
["twitter-pin" :as twitter-pin]))
|
||||||
|
|
||||||
(declare logger log-debug log-verbose log-info log-warn log-error)
|
(declare logger log-debug log-verbose log-info log-warn log-error)
|
||||||
(logging/deflog "advisorycircular" logger)
|
(logging/deflog "advisorycircular" logger)
|
||||||
@ -848,6 +849,50 @@
|
|||||||
(println (:num-followers stats) "Twitter followers"))
|
(println (:num-followers stats) "Twitter followers"))
|
||||||
|
|
||||||
|
|
||||||
|
(defn read-line []
|
||||||
|
(p/promise [resolve]
|
||||||
|
(.once js/process.stdin
|
||||||
|
"data"
|
||||||
|
#(resolve (.trim (str %))))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn twitter-pin-get-url [tp]
|
||||||
|
(p/promise [resolve reject]
|
||||||
|
(.getUrl tp (fn [err url]
|
||||||
|
(if err
|
||||||
|
(reject err)
|
||||||
|
(resolve url))))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn twitter-pin-authorize [tp pin]
|
||||||
|
(p/promise [resolve reject]
|
||||||
|
(.authorize tp pin (fn [err result]
|
||||||
|
(when err
|
||||||
|
(reject err))
|
||||||
|
(resolve
|
||||||
|
{:user-id (.-user_id result)
|
||||||
|
:screen-name (.-screen_name result)
|
||||||
|
:token (.-token result)
|
||||||
|
:secret (.-secret result)})))))
|
||||||
|
|
||||||
|
|
||||||
|
(defn do-oauth-authorization []
|
||||||
|
(p/let [_ (println "Enter the bot app's consumer key:")
|
||||||
|
consumer-key (read-line)
|
||||||
|
_ (println "Enter the bot app's consumer secret:")
|
||||||
|
consumer-secret (read-line)
|
||||||
|
_ (println consumer-key consumer-secret twitter-pin)
|
||||||
|
pin-getter (twitter-pin consumer-key consumer-secret)
|
||||||
|
auth-url (twitter-pin-get-url pin-getter)
|
||||||
|
_ (println "1. Open this URL and get the PIN:" auth-url)
|
||||||
|
_ (println "2. Enter the PIN you got from the URL above:")
|
||||||
|
pin (read-line)
|
||||||
|
authorization (twitter-pin-authorize pin-getter (.trim (str pin)))]
|
||||||
|
(println "Authorizing account:" (:screen-name authorization))
|
||||||
|
(println "Token:" (:token authorization))
|
||||||
|
(println "Secret:" (:secret authorization))))
|
||||||
|
|
||||||
|
|
||||||
(defn main [& args]
|
(defn main [& args]
|
||||||
(-> commander
|
(-> commander
|
||||||
(.option "--lat <lat>" "Latitude of the circle of region of interest" parse-number)
|
(.option "--lat <lat>" "Latitude of the circle of region of interest" parse-number)
|
||||||
@ -865,6 +910,7 @@
|
|||||||
(.option "--airport-geojson" "Generate airport GEOJSON and exit")
|
(.option "--airport-geojson" "Generate airport GEOJSON and exit")
|
||||||
(.option "--create-aircraft-info-db-from-json <json path>" "Generate aircraft info DB and exit")
|
(.option "--create-aircraft-info-db-from-json <json path>" "Generate aircraft info DB and exit")
|
||||||
(.option "--stats" "Show bot stats and exit")
|
(.option "--stats" "Show bot stats and exit")
|
||||||
|
(.option "--oauth" "Run the oauth authorization process for the bot and a twitter account")
|
||||||
(.parse (.-argv js/process)))
|
(.parse (.-argv js/process)))
|
||||||
(logging/set-log-prefix! (or (.-logPrefix commander) ""))
|
(logging/set-log-prefix! (or (.-logPrefix commander) ""))
|
||||||
(reset! log-prefix (or (.-logPrefix commander) ""))
|
(reset! log-prefix (or (.-logPrefix commander) ""))
|
||||||
@ -880,6 +926,8 @@
|
|||||||
(p/let [config (get-config commander)
|
(p/let [config (get-config commander)
|
||||||
stats (get-stats config)]
|
stats (get-stats config)]
|
||||||
(print-stats stats))
|
(print-stats stats))
|
||||||
|
(.-oauth commander)
|
||||||
|
(do-oauth-authorization)
|
||||||
:else
|
:else
|
||||||
(let [start-time (current-time)]
|
(let [start-time (current-time)]
|
||||||
;; If --config-path is specified, definitely try to read that
|
;; If --config-path is specified, definitely try to read that
|
||||||
|
Loading…
Reference in New Issue
Block a user