forked from ab-anand/Automation-Bots
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exchange_rates.py
42 lines (28 loc) · 849 Bytes
/
exchange_rates.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import urllib.request
from datetime import datetime
from bs4 import BeautifulSoup
def get_page(url):
return urllib.request.urlopen(url).read()
def parse(html, currency):
soup = BeautifulSoup(html, 'html.parser')
table = soup.find('tbody')
projects = []
for row in table.find_all('tr'):
cols = row.find_all('td')
projects.append(
' ' +
cols[0].a.text + ' ' +
cols[2].text + ' ' +
cols[3].text)
print('Currency code| Units per ' + currency +
' | ' + currency + ' per Unit'
' ')
for project in projects:
print(project)
def main():
today_date = datetime.now().date()
currency = input('Enter currency code (ex. USD): ')
html = get_page('http://www.xe.com/currencytables/?from=' + currency + '&date=' + str(today_date))
parse(html, currency)
if __name__ == '__main__':
main()