def login_to_qrz(session: requests.Session, call_sign: str, password: str) -> requests.Session: return chain( format_qrz_login_data, to(post(session=session, url='https://www.qrz.com/login'), kw='data'), to(return_session_if_login_verified(session=session), kw='response'))((call_sign, password))
def login_to_lotw_arrl(session: requests.Session, call_sign: str, password: str) -> requests.Session: return chain( format_arrl_login_data, to(post(session=session, url='https://lotw.arrl.org/lotwuser/login'), kw='data'), to(return_session_if_login_verified(session=session), kw='response'))(call_sign, password)
def setup(own_call_sign: str, arrl_pass: str, qrz_pass: str) -> (requests.Session, requests.Session): return chain( start_session, to(concurrently( login_to_lotw_arrl(password=arrl_pass, call_sign=own_call_sign), login_to_qrz(password=qrz_pass, call_sign=own_call_sign)), kw='session'))()
def handle_country(country: str, filter_func: callable, qrz_session: requests.Session) -> (str, list): return country[1], chain( filter_func, to(map(func=get_call_sign_data(qrz_session=qrz_session), kw='call_sign'), kw='iterable'), )(func=startswith(substring=country[0]))
__author__ = "Nicholas Logan" __copyright__ = "Copyright 2018, Nicholas Logan" __credits__ = ["Nicholas Logan", "Igor Dorovskoy"] __license__ = "GNU GPL3" __version__ = "0.2.0" __maintainer__ = "Nicholas Logan" __email__ = "*****@*****.**" __status__ = "Prototype" import requests from lxml import etree import re import pprint from functional import chain, concurrently, to, split_to, map, filterer, zipper, curry start_session = requests.session filter_empty_values = to(filterer(func=lambda item: item[1], kw='item'), kw='iterable') format_arrl_login_data = 'login={}&password={}&acct_sel=&thisForm=login'.format format_qrz_login_data = to(chain(zipper(iter1=('username', 'password')), dict), kw='iter2') @curry def post(session: requests.Session, url: str, data: str or dict) -> requests.Response: return session.post(url, data=data) @curry def startswith(string: str, substring: str) -> bool: return string.startswith(substring)