import sys import re # local libs from commonimports import parse from util import importlocal, FIMFICTION, get_url, get_session, fail bs4 = importlocal('bs4') requests = importlocal('requests') usr = '' pas = '' logged_in = False def possibly_req_auth(username, password): global usr, pas, logged_in, localCookie if logged_in: return if not usr: usr = username or input('Username: '******'Password: '******'username': usr,'password': pas} ).encode('ascii') print('open', FIMFICTION + '/ajax/login.php', login_data) ret = get_session().post(FIMFICTION + '/ajax/login.php', data={'username': usr, 'password': pas}) print(type(ret.json())) if 'signing_key' not in ret.json(): fail('Login failed, check your username and password') logged_in = True return usr, pas
""" The common imports of this project, resolved against the right python version. Ignore any errors about missing modules in here. """ PYTHON_MAJOR = __import__('sys').version_info[0] py3 = PYTHON_MAJOR == 3 if py3: import urllib.parse as parse from http import cookiejar, cookies import urllib.request as request else: import urllib as parse import cookielib as cookiejar import Cookie as cookies import urllib2 as request import util bs4 = util.importlocal('bs4') __all__ = ['parse', 'cookiejar', 'cookies', 'request', 'bs4', 'py3', 'PYTHON_MAJOR']