Skip to content

Commit

Permalink
Formatting changes
Browse files Browse the repository at this point in the history
  • Loading branch information
prochy-exe committed Apr 25, 2024
1 parent 3cf5e4a commit d06303c
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 110 deletions.
46 changes: 23 additions & 23 deletions malfetcher/mal_config_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
def generate_mal_verifier():
def generate_random_string(length):
characters = string.ascii_letters + string.digits
random_string = ''.join(random.choice(characters) for _ in range(length))
random_string = "".join(random.choice(characters) for _ in range(length))
return random_string

# Generate a random code verifier between 43 and 128 characters
Expand All @@ -23,7 +23,7 @@ def generate_random_string(length):

is_ssh = 'SSH_CONNECTION' in os.environ
is_displayless = 'DISPLAY' not in os.environ
is_linux = platform.system() == 'Linux'
is_linux = platform.system() == "Linux"
headless_config = False
if is_linux:
if is_ssh or is_displayless:
Expand All @@ -32,7 +32,7 @@ def generate_random_string(length):
def generate_mal_verifier():
def generate_random_string(length):
characters = string.ascii_letters + string.digits
random_string = ''.join(random.choice(characters) for _ in range(length))
random_string = "".join(random.choice(characters) for _ in range(length))
return random_string

# Generate a random code verifier between 43 and 128 characters
Expand All @@ -46,28 +46,28 @@ def setup_webserver():
# Enable CORS for all routes
@app.after_request
def add_cors_headers(response):
response.headers['Access-Control-Allow-Origin'] = '*'
response.headers['Access-Control-Allow-Headers'] = 'Content-Type'
response.headers['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS'
response.headers['Access-Control-Allow-Origin'] = "*"
response.headers['Access-Control-Allow-Headers'] = "Content-Type"
response.headers['Access-Control-Allow-Methods'] = "GET, POST, OPTIONS"
return response

@app.route('/access_token') #Listen for token webhook
def receive_token():
def make_request(code):
global code_verifier
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
'Accept': 'application/json',
'Content-Type': "application/x-www-form-urlencoded",
'Accept': "application/json",
}
json = {
'client_id': global_id,
'client_secret': global_secret,
'grant_type': 'authorization_code',
'grant_type': "authorization_code",
'code': code,
'redirect_uri': f'http://localhost:8888/access_token',
'redirect_uri': f"http://localhost:8888/access_token",
'code_verifier': code_verifier
}
response = requests.post('https://myanimelist.net/v1/oauth2/token', data=json, headers=headers)
response = requests.post("https://myanimelist.net/v1/oauth2/token", data=json, headers=headers)
return response.json()

# Extracting query parameters from the request URL
Expand All @@ -81,25 +81,25 @@ def make_request(code):
global access_token
access_token = make_request(code)['access_token']
http_server.stop()
return redirect('https://myanimelist.net/')
return redirect("https://myanimelist.net/")

def start_webserver():
if headless_config:
print('Open this URL in your browser: ', global_tooltip)
print("Open this URL in your browser: ", global_tooltip)
else:
print('Authentificate in the opened tab')
print("Authentificate in the opened tab")
webbrowser.open(global_tooltip, 0)
http_server.serve_forever()

http_server = WSGIServer(('127.0.0.1', 8888), app, log=None)
http_server = WSGIServer(("127.0.0.1", 8888), app, log=None)

return start_webserver, http_server

def config_setup(print_only = False):
setup_function, _ = setup_webserver() # Setup the server function here

def gen_please(name, help):
return f'Please input your {name} here ({help}):\n'
return f"Please input your {name} here ({help}):\n"

def get_input(prompt, data_type = str):
while True:
Expand Down Expand Up @@ -135,14 +135,14 @@ def generate_api_key(client_id, client_secret):
print("Please create a new API client")
if headless_config:
if is_displayless:
print('The setup process cannot be continued on this machine')
print('Please SSH into this machine, set the access key as an env variable or import the config directly')
client_id = get_input(gen_please('MyAnimeList API Client ID',"https://myanimelist.net/apiconfig"))
client_secret = get_input(gen_please('MyAnimeList API Client Secret',f"https://myanimelist.net/apiconfig/edit/{client_id}"))
print("The setup process cannot be continued on this machine")
print("Please SSH into this machine, set the access key as an env variable or import the config directly")
client_id = get_input(gen_please("MyAnimeList API Client ID","https://myanimelist.net/apiconfig"))
client_secret = get_input(gen_please("MyAnimeList API Client Secret",f"https://myanimelist.net/apiconfig/edit/{client_id}"))
else:
webbrowser.open('https://myanimelist.net/apiconfig', 0)
client_id = get_input(gen_please('MyAnimeList API Client ID',"Paste the Client ID"))
client_secret = get_input(gen_please('MyAnimeList API Client Secret',"Paste the Client Secret"))
webbrowser.open("https://myanimelist.net/apiconfig", 0)
client_id = get_input(gen_please("MyAnimeList API Client ID","Paste the Client ID"))
client_secret = get_input(gen_please("MyAnimeList API Client Secret","Paste the Client Secret"))
config_dict['myanimelist_user_token'] = generate_api_key(client_id, client_secret)
if not print_only:
utils_save_json(config_path, config_dict)
Expand Down

0 comments on commit d06303c

Please sign in to comment.