将日期插入 URL 并获取该日期的货币数据
Inserting date into URL and Getting currency data for that date
我正在尝试编写一个函数,该函数从 https://openexchangerates.org/ 和 return 的某个日期收集货币数据作为字典。我对如何在 url 中显示 YYYY-MM-DD 的地方插入日期有点困惑
然后还有如何把它放到 python.
任何帮助将不胜感激
我目前的代码如下:
def _fetch_exrates(date):
import json
import urllib.request
f = urllib.request.urlopen('http://openexchangerates.org/api/historical/YYYY-MM-DD.json?app_id=188bd7b8d2634e4cb0602ab5b3c223e7')
charset = f.info().get_param('charset', 'utf8')
data = f.read()
decoded = json.loads(data.decode(charset))
print(json.dumps(decoded, indent=4))
import datetime
print('Please but the year in the form of YYYY and the month as MM and day as DD')
a = int(input('choose a year :',))
b = int(input('choose a month :',))
c = int(input('choose a day :',))
date = datetime.date(a,b,c)
print(date)
def _fetch_exrates(year,month,day):
import json
import urllib.request
f = urllib.request.urlopen('http://openexchangerates.org/api/historical/'+year+'-'+month+'-'+day+'.json?app_id=188bd7b8d2634e4cb0602ab5b3c223e7')
charset = f.info().get_param('charset', 'utf8')
data = f.read()
decoded = json.loads(data.decode(charset))
print(json.dumps(decoded, indent=4))
print('Please but the year in the form of YYYY and the month as MM and day as DD')
year = raw_input('choose a year :',)
month = raw_input('choose a month :',)
day = raw_input('choose a day :',)
_fetch_exrates(year,month,day)
然后使用上面的字符串构造它。
我正在尝试编写一个函数,该函数从 https://openexchangerates.org/ 和 return 的某个日期收集货币数据作为字典。我对如何在 url 中显示 YYYY-MM-DD 的地方插入日期有点困惑 然后还有如何把它放到 python.
任何帮助将不胜感激
我目前的代码如下:
def _fetch_exrates(date):
import json
import urllib.request
f = urllib.request.urlopen('http://openexchangerates.org/api/historical/YYYY-MM-DD.json?app_id=188bd7b8d2634e4cb0602ab5b3c223e7')
charset = f.info().get_param('charset', 'utf8')
data = f.read()
decoded = json.loads(data.decode(charset))
print(json.dumps(decoded, indent=4))
import datetime
print('Please but the year in the form of YYYY and the month as MM and day as DD')
a = int(input('choose a year :',))
b = int(input('choose a month :',))
c = int(input('choose a day :',))
date = datetime.date(a,b,c)
print(date)
def _fetch_exrates(year,month,day):
import json
import urllib.request
f = urllib.request.urlopen('http://openexchangerates.org/api/historical/'+year+'-'+month+'-'+day+'.json?app_id=188bd7b8d2634e4cb0602ab5b3c223e7')
charset = f.info().get_param('charset', 'utf8')
data = f.read()
decoded = json.loads(data.decode(charset))
print(json.dumps(decoded, indent=4))
print('Please but the year in the form of YYYY and the month as MM and day as DD')
year = raw_input('choose a year :',)
month = raw_input('choose a month :',)
day = raw_input('choose a day :',)
_fetch_exrates(year,month,day)
然后使用上面的字符串构造它。