示例#1
0
 def quote(self):
     data = {}
     content = fetch_url("http://www.standardchartered.com.tw/check/inquiry-rate-foreign-exchange.asp")
     soup = BeautifulSoup(content, "lxml")
     for tr in soup.table.find_all(['tr'])[1:]:
         key = self.currency_table.get(tr.th.getText(), None)
         value = [None if x.getText() == '-' else float(x.getText()) for x in tr.find_all(['td'])]
         data[key] = value
     data = {'data': data}
     data['date'] = GenericBank.get_epoch()
     return data
示例#2
0
文件: twbank.py 项目: rbtchc/currency
    def quote(self):
        content = fetch_url("http://rate.bot.com.tw/Pages/Static/UIP003.en-US.htm")
        soup = BeautifulSoup(content, "lxml")
        tables = soup.find_all('table')

        quote_date_str = re.findall(ur'Quoted Date[\uff1a][\xa0](.*)\r', tables[4].find_all('td')[:][-1].text)
        if not quote_date_str:
            logging.error("Unable to parse quoted date from html!")
        # Hardcoded as GMT+8 (CST)
        quote_date = calendar.timegm(time.strptime(quote_date_str[0]+' CST', "%m/%d/%Y %H:%M CST"))

        data = {}
        # extract currency exchange data from sixth table
        for tr in tables[6].find_all('tr'):
            tds = [td.text for td in tr.find_all('td')]
            if not tds:
                continue
            data[self.currency_table[tds[0]]] = [float(x) if x != '-' else None for x in tds[1:5]]
        return {"date": quote_date, "data": data}