This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests | |
| from bs4 import BeautifulSoup | |
| from tqdm import tqdm_notebook as tqdm | |
| import json | |
| import pandas as pd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| continent_codes = ['A', 'P', 'E', 'M', 'F'] | |
| country_names = [] | |
| country_codes = {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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:] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def is_number(s): | |
| try: | |
| float(s) | |
| return True | |
| except ValueError: | |
| pass | |
| try: | |
| import unicodedata | |
| unicodedata.numeric(s) | |
| return True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| results = {} | |
| print("Progress scrapping") | |
| for i, code in enumerate(tqdm(list(country_codes.values()))): | |
| tmp_data = {} | |
| webpage = 'https://www.exchange-rates.org/history/{}/USD/T'.format(code) | |
| webpage = requests.get(webpage) | |
| webpage = webpage.text | |
| soup = BeautifulSoup(webpage, 'html.parser') | |
| data = soup.find_all('div', attrs={'class':'table-responsive'}) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with open('results.json', 'r') as f: | |
| results = json.load(f) | |
| with open('country_codes.json', 'r') as f: | |
| country_codes = json.load(f) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import matplotlib | |
| #matplotlib.use('TkAgg') | |
| import matplotlib.pyplot as plt | |
| %matplotlib inline | |
| import seaborn as sns | |
| sns.set() | |
| for i, code in enumerate(list(results.keys())[0:4]): | |
| pd_data = pd.DataFrame.from_dict(results[code]) | |
| pd_data['date'] = pd.to_datetime(pd_data['date']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import pandas as pd | |
| import matplotlib | |
| #matplotlib.use('TkAgg') | |
| import matplotlib.pyplot as plt | |
| %matplotlib inline | |
| import seaborn as sns | |
| sns.set() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| with open('results.json', 'r') as f: | |
| results = json.load(f) | |
| with open('country_codes.json', 'r') as f: | |
| country_codes = json.load(f) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def dictkeys_from_value(dictio, value): | |
| idx_val = list(dictio.values()).index(value) | |
| return list(dictio.keys())[idx_val] | |
| diff = {} | |
| daftar_negara = [] | |
| daftar_perubahan = [] | |
| for i, code in enumerate(list(results.keys())): | |
| # proses ke dataframe supaya lebih mudah untuk ditampilkan ke data | |
| pd_data = pd.DataFrame.from_dict(results[code]) |
OlderNewer