Minor changes

This commit is contained in:
Nocturn9x 2022-03-10 11:07:23 +01:00
parent 92c36cb6e8
commit a0c17df7da
1 changed files with 73 additions and 64 deletions

View File

@ -207,8 +207,14 @@ async def main(arguments: argparse.Namespace) -> int:
if not arguments.tax_code: if not arguments.tax_code:
logger.info("You have not provided your tax/fiscal code, but I can get it for you. Please provide your GIA SSO" logger.info("You have not provided your tax/fiscal code, but I can get it for you. Please provide your GIA SSO"
" credentials below") " credentials below")
try:
username = input("Type your GIA SSO username: ") username = input("Type your GIA SSO username: ")
password = getpass("Type your GIA SSO password (hidden): ") password = getpass("Type your GIA SSO password (hidden): ")
except KeyboardInterrupt:
# Asyncio's signal handlers won't work
# when blocked in synchronous code like
# this
return
logger.info(f"Logging in as {username!r}") logger.info(f"Logging in as {username!r}")
if access_token := await login_with_gia(logger, username, password, arguments.verbose): if access_token := await login_with_gia(logger, username, password, arguments.verbose):
logger.debug(f"Access token is {access_token!r}") logger.debug(f"Access token is {access_token!r}")
@ -222,7 +228,7 @@ async def main(arguments: argparse.Namespace) -> int:
return -1 return -1
logger.info(f"Authenticating as '{arguments.tax_code}'") logger.info(f"Authenticating as '{arguments.tax_code}'")
async with httpx.AsyncClient( async with httpx.AsyncClient(
# We mimic the app's headers # We mimic the app's headers. Specifically, this is my Xiaomi Mi 11i, lol
headers={ headers={
"User-Agent": "Dalvik/2.1.0 (Linux; U; Android 11; M2012K11G Build/RKQ1.201112.002)", "User-Agent": "Dalvik/2.1.0 (Linux; U; Android 11; M2012K11G Build/RKQ1.201112.002)",
# I seriously have no idea what the app designers were thinking, but # I seriously have no idea what the app designers were thinking, but
@ -249,6 +255,7 @@ async def main(arguments: argparse.Namespace) -> int:
): ):
return 1 return 1
logger.debug(f"Request to {result.url} sent, status code is {result.status_code}") logger.debug(f"Request to {result.url} sent, status code is {result.status_code}")
try:
if json.loads(result.text) != {}: if json.loads(result.text) != {}:
# The API returns an empty JSON object to unauthenticated # The API returns an empty JSON object to unauthenticated
# requests # requests
@ -308,6 +315,8 @@ async def main(arguments: argparse.Namespace) -> int:
else: else:
logger.error(f"The provided tax code does not appear to be valid, please check for any typos and try again") logger.error(f"The provided tax code does not appear to be valid, please check for any typos and try again")
return -1 return -1
except json.decoder.JSONDecodeError as json_error:
logger.error(f"A fatal JSON decoding error occurred -> {type(json_error).__name__}: {json_error}")
if __name__ == "__main__": if __name__ == "__main__":