Skip to content

Instantly share code, notes, and snippets.

@khaerulumam42
Created December 18, 2018 15:06
Show Gist options
  • Save khaerulumam42/68f3e9550311527ea3d3a919c6c8841d to your computer and use it in GitHub Desktop.
Save khaerulumam42/68f3e9550311527ea3d3a919c6c8841d to your computer and use it in GitHub Desktop.
for continent_code in continent_codes:
home = 'https://www.exchange-rates.org/currentRates/{}/USD'.format(continent_code)
home = requests.get(home)
home = home.text
soup_home_raw = BeautifulSoup(home, 'html.parser')
soup_home = soup_home_raw.find_all('td', attrs={'class':'text-left convert-to'})
for i, x in enumerate(soup_home):
z = x.text
z = z.split(' ')
currency_code = list(z[-1])[-3:]
currency_code = "".join(currency_code)
country_name = "_".join(z[0:-1]) +"_" + "".join(list(z[-1])[:-3])
country_name = country_name.split('_')[1:]
country_name = "_".join(country_name)
country_codes[country_name] = currency_code
with open('country_codes.json', 'w') as f:
json.dump(country_codes, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment