-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetTWBExchange.py
38 lines (28 loc) · 1.19 KB
/
getTWBExchange.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
from getExchange import getExchange
from bs4 import BeautifulSoup
import re
class getTWBExchange(getExchange):
def __init__(self):
super().__init__()
self.getPage()
def getPage(self):
def parseStr(inputStr):
return re.sub('[\s*\r*\n*]' , '' , inputStr)
soup = BeautifulSoup(super().getPage('https://rate.bot.com.tw/xrt?Lang=zh-TW') , 'html.parser')
currencyTr = soup.find('table').find('tbody').find_all('tr')
for i in currencyTr:
currencySellingRate = i.find('td' , {'data-table' : '本行即期賣出'}).getText()
if not re.search('\-+' , currencySellingRate):
self.exchangeDict[parseStr(i.find('div' , {'class' , 'hidden-phone print_show'}).getText())] = currencySellingRate
def calculate(self , currency , value):
rst = super().calculate(currency , value)
if rst:
return 'NTD : %f' % (rst)
else:
return 'No Corrency found'
@staticmethod
def getWarrngMessige():
return '(This exchange rate using \"Bank of Taiwan\" sight selling rate)'
if __name__ == '__main__':
a = getTWBExchange()
print(a.calculate('USD' , 10))