Skip to content

Instantly share code, notes, and snippets.

@PattyAppier
Last active May 25, 2018 13:20
Show Gist options
  • Save PattyAppier/f0eba99af8ee56d213930472236a36a7 to your computer and use it in GitHub Desktop.
Save PattyAppier/f0eba99af8ee56d213930472236a36a7 to your computer and use it in GitHub Desktop.
ExchangeRate_Python
from flask import Flask
app = Flask(__name__)
@app.route("/")
def hello():
return "Wish Luck is with you today!"
#if _name_ == "_main_":
#app.run()
from typing import Dict, Any
import pandas
class Money(object):
def __init__(self, money_table, cash_buy, cash_sell, spot_buy, spot_sell):
self.money_table = money_table # self.fun = param name
self.cash_buy = cash_buy
self.cash_sell = cash_sell
self.spot_buy = spot_buy
self.spot_sell = spot_sell
def search_data():
data = pandas.read_html("http://rate.bot.com.tw/xrt?Lang=zh-TW")[0] # attr
money_table = data.ix[:, 0:5] # [rows,columns]
money_table.columns = ["Currency", "Cash Buy", "Cash Sell", "Spot Buy", "Spot Sell"]
money_table["Currency"] = money_table["Currency"].str.extract("\((\w+)\)", expand= True)
money_dic = {}
for i in range(0, 19):
dollar = money_table.values[i] # i means key
money_dic[i] = Money(dollar[0], dollar[1], dollar[2], dollar[3], dollar[4])
return (money_dic)
money_dic = Money.search_data()
for i in range(0, 19):
print(money_dic[i].money_table)
print(money_dic[i].cash_buy)
print(money_dic[i].cash_sell)
print(money_dic[i].spot_buy)
print(money_dic[i].spot_sell)
print(".........")
Flask==1.0.2
beautifulsoup4==4.6.0
html5lib==1.0.1
lxml==4.2.1
pandas==0.23.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment