Skip to content

Instantly share code, notes, and snippets.

@msoe
Created August 29, 2018 10:46
Show Gist options
  • Save msoe/9bb34873014d3fa868078e9240494274 to your computer and use it in GitHub Desktop.
Save msoe/9bb34873014d3fa868078e9240494274 to your computer and use it in GitHub Desktop.
#!/usr/local/bin/python3
## Just a concept to display the forex rates from Central Bank, KBZ Bank, AYA Bank and CB Bank of Myanmar
## TODO: clean the code
from bs4 import BeautifulSoup
import requests,re
import datetime
response = requests.get('http://forex.cbm.gov.mm/api/latest')
data = response.json()
print('\nCentral Bank\'s forex rates')
print('Dated: ' + datetime.datetime.fromtimestamp(int(data['timestamp'])).strftime('%Y-%m-%d %H:%M:%S'))
print('\n1 USD = ' + data['rates']['USD'] + ' Kyats')
print('1 SGD = ' + data['rates']['SGD'] + ' Kyats')
print('1 EUR = ' + data['rates']['EUR'] + ' Kyats')
url = 'https://www.kbzbank.com/en/'
soup = BeautifulSoup(requests.get(url).content, 'lxml')
rates = soup.body.find('div', attrs={'class':'exchange-rate'}).find_all('div')
kbz_usd = re.findall(r"\d{4}", rates[1].text)
kbz_sgd = re.findall(r"\d{4}", rates[2].text)
kbz_eur = re.findall(r"\d{4}", rates[4].text)
print('\nKBZ Bank Rates\n')
print('USD : ' + kbz_usd[0] + ' ' + kbz_usd[1])
print('SGD : ' + kbz_sgd[0] + ' ' + kbz_sgd[1])
print('EUR : ' + kbz_eur[0] + ' ' + kbz_eur[1])
url = 'https://www.ayabank.com/en_US/'
soup = BeautifulSoup(requests.get(url).content, 'lxml')
rates = soup.body.find('table', attrs={'id':'tablepress-1'}).find_all('td')
print('\nAYA Bank Rates\n')
print('USD : ' + rates[4].get_text() + ' ' + rates[5].get_text().strip())
print('SGD : ' + rates[10].get_text() + ' ' + rates[11].get_text())
print('EUR : ' + rates[7].get_text() + ' ' + rates[8].get_text())
url = 'http://www.cbbank.com.mm/exchange_rate.aspx'
soup = BeautifulSoup(requests.get(url).content, 'lxml')
rates = soup.body.find_all('td')
print('\nCB Bank Rates\n')
print('USD : ' + rates[1].get_text() + ' ' + rates[2].get_text())
print('SGD : ' + rates[7].get_text() + ' ' + rates[8].get_text())
print('EUR : ' + rates[4].get_text() + ' ' + rates[5].get_text())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment