Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI command for generating tokens for extra twitter accounts #69

Merged
merged 4 commits into from
Apr 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 40 additions & 11 deletions diffengine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import readability
import unicodedata
import yaml
import argparse

from peewee import *
from playhouse.migrate import SqliteMigrator, migrate
Expand Down Expand Up @@ -374,6 +375,19 @@ def load_config(prompt=True):
return config


def get_auth_link_and_show_token():
global home
home = os.getcwd()
config = load_config(True)
twitter = config["twitter"]
token = request_pin_to_user_and_get_token(
twitter["consumer_key"], twitter["consumer_secret"]
)
print("\nThese are your access token and secret.\nDO NOT SHARE THEM WITH ANYONE!\n")
print("ACCESS_TOKEN\n%s\n" % token[0])
print("ACCESS_TOKEN_SECRET\n%s\n" % token[1])


def get_initial_config():
config = {"feeds": []}

Expand All @@ -385,20 +399,14 @@ def get_initial_config():
else:
config["feeds"].append({"url": url, "name": feed.feed.title})

answer = input("Would you like to set up tweeting edits? [Y/n] ")
answer = input("Would you like to set up tweeting edits? [Y/n] ") or "Y"
if answer.lower() == "y":
print("Go to https://apps.twitter.com and create an application.")
consumer_key = input("What is the consumer key? ")
consumer_secret = input("What is the consumer secret? ")
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.secure = True
auth_url = auth.get_authorization_url()
input(
"Log in to https://twitter.com as the user you want to tweet as and hit enter."
)
input("Visit %s in your browser and hit enter." % auth_url)
pin = input("What is your PIN: ")
token = auth.get_access_token(verifier=pin)

token = request_pin_to_user_and_get_token(consumer_key, consumer_secret)

config["twitter"] = {
"consumer_key": consumer_key,
"consumer_secret": consumer_secret,
Expand All @@ -414,6 +422,18 @@ def get_initial_config():
return config


def request_pin_to_user_and_get_token(consumer_key, consumer_secret):
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.secure = True
auth_url = auth.get_authorization_url()
input(
"Log in to https://twitter.com as the user you want to tweet as and hit enter."
)
input("Visit %s in your browser and hit enter." % auth_url)
pin = input("What is your PIN: ")
return auth.get_access_token(verifier=pin)


def home_path(rel_path):
return os.path.join(home, rel_path)

Expand Down Expand Up @@ -588,4 +608,13 @@ def _get(url, allow_redirects=True):


if __name__ == "__main__":
main()
# Cli options
parser = argparse.ArgumentParser()
parser.add_argument("--add", action="store_true")
options = parser.parse_args()

if options.add:
get_auth_link_and_show_token()
else:
main()
sys.exit("Finishing diffengine")