Open web browser as prompting for imgur credentials

This commit is contained in:
Ali Parlakci
2018-07-30 13:22:30 +03:00
parent 2297e9ed86
commit 7ccf2fb7f9

View File

@@ -10,10 +10,11 @@ import logging
import os import os
import sys import sys
import time import time
import webbrowser
from io import StringIO from io import StringIO
from pathlib import Path, PurePath from pathlib import Path, PurePath
from src.downloader import Direct, Gfycat, Imgur, Self, Erome from src.downloader import Direct, Erome, Gfycat, Imgur, Self
from src.errors import * from src.errors import *
from src.parser import LinkDesigner from src.parser import LinkDesigner
from src.searcher import getPosts from src.searcher import getPosts
@@ -38,20 +39,34 @@ def getConfig(configFileName):
if "reddit_refresh_token" in content: if "reddit_refresh_token" in content:
if content["reddit_refresh_token"] == "": if content["reddit_refresh_token"] == "":
FILE.delete("reddit_refresh_token") FILE.delete("reddit_refresh_token")
if all(True if not content.get(key,"") == "" else False for key in keys):
print(
"Go to this URL and fill the form: " \
"https://api.imgur.com/oauth2/addclient\n" \
"Enter the client id and client secret here:"
)
webbrowser.open("https://api.imgur.com/oauth2/addclient",new=2)
for key in keys: for key in keys:
try: try:
if content[key] == "": if content[key] == "":
raise KeyError raise KeyError
except KeyError: except KeyError:
print(key,": ") FILE.add({key:input(" "+key+": ")})
FILE.add({key:input()})
return jsonFile(configFileName).read() return jsonFile(configFileName).read()
else: else:
FILE = jsonFile(configFileName) FILE = jsonFile(configFileName)
configDictionary = {} configDictionary = {}
print(
"Go to this URL and fill the form: " \
"https://api.imgur.com/oauth2/addclient\n" \
"Enter the client id and client secret here:"
)
webbrowser.open("https://api.imgur.com/oauth2/addclient",new=2)
for key in keys: for key in keys:
configDictionary[key] = input(key + ": ") configDictionary[key] = input(" "+key+": ")
FILE.add(configDictionary) FILE.add(configDictionary)
return FILE.read() return FILE.read()