Skip to content

Instantly share code, notes, and snippets.

@Hattshire
Created January 18, 2020 02:00
Show Gist options
  • Save Hattshire/4dcb1af68c818f20241a8c904876dac6 to your computer and use it in GitHub Desktop.
Save Hattshire/4dcb1af68c818f20241a8c904876dac6 to your computer and use it in GitHub Desktop.
Convert USD to CLP using current MultiCaja's paypal usd price.
# Unlicensed
# More licensing info at https://unlicense.org/
from requests_html import HTMLSession
URL_MC_PAYPAL_BASE = "https://paypal.tenpo.cl" # Originally "https://www.multicaja.cl/paypal"
URL_MC_PAYPAL_LOGIN = URL_MC_PAYPAL_BASE + "/login"
URL_MC_PAYPAL_CALCU = URL_MC_PAYPAL_BASE + "/ajax/agregar_calcula_montos_authenticated"
LOGIN_DATA = {
'utf8' : '✓',
'authenticity_token': 'extract_it',
'retorno' : 'full',
'rut' : '0.000.000-0',
'clave' : '000'
}
session = HTMLSession()
def login(rut, passwd):
''' Creates and registers a new token.
rut: str = National unique identifier (Nativelly dotted and dashed).
passwd: str = Four digit login pin.
~return: str = Registered token.
'''
authenticity_token = session.get(URL_MC_PAYPAL_LOGIN) \
.html \
.xpath("//meta[@name='csrf-token']", first=1).attrs['content']
LOGIN_DATA['authenticity_token'] = authenticity_token
LOGIN_DATA['rut'] = rut
LOGIN_DATA['clave'] = passwd
session.post(URL_MC_PAYPAL_LOGIN, data=LOGIN_DATA).raise_for_status()
return authenticity_token
def usdclp_rate(rut, passwd):
''' Retrieve current USD value in MultiCaja's paypal service.
rut: str = National unique identifier (Nativelly dotted and dashed).
passwd: str = Four digit login pin.
~return: int = Current USDMCP value in CLP.
'''
try:
rate_header = {"X-CSRF-Token": login(rut, passwd) }
except:
print("Can't login with the provided credentials.")
exit(-1)
clp100=session.post(URL_MC_PAYPAL_CALCU, headers=rate_header,
data={"monto": "100"}) \
.json()['total_transferencia']
return int(clp100)/100
if __name__ == "__main__":
import argparse
# As of 01/2020 they aren't checking credentials,
# so we skip them if not provided for simplicity.
parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('-r', action='store',
help='National unique identifier.')
parser.add_argument('-p', action='store', default=None,
help='Four digit login pin.', nargs=1)
args = parser.parse_args()
if args.p is None and args.r is not None:
args.p = input('Type in the pass: ')
elif args.r is None:
args.r = "0-0"
args.p = "0000"
# TODO: i18n?
print("$1USD Paypal-Multicaja = ${}CLP" \
.format(usdclp_rate(args.r, args.p)) )
@Hattshire
Copy link
Author

DONT BE EVIL ! DONT ABUSE

This is a useful script, not a "toy" for annoying kiddos.
I declare: I'm not responsible for things I've didn't do, continue your search.


Made this in 03/2019, the first rv published here is RV2.
Too useful to let it erase somewhere, even if I don't use it so often (usd*810 in honour to lazyness)
Maybe some1 would use it as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment