Date 将日期插入URL并获取该日期的货币数据
我正在尝试编写一个函数,从中收集特定日期的货币数据,并将其作为一个dictionary返回。我有点纠结于如何在url中显示YYYY-MM-DD的位置插入日期 还有如何把它放到python上 任何帮助都将不胜感激 我目前掌握的代码如下:Date 将日期插入URL并获取该日期的货币数据,date,python-3.x,currency,currency-exchange-rates,Date,Python 3.x,Currency,Currency Exchange Rates,我正在尝试编写一个函数,从中收集特定日期的货币数据,并将其作为一个dictionary返回。我有点纠结于如何在url中显示YYYY-MM-DD的位置插入日期 还有如何把它放到python上 任何帮助都将不胜感激 我目前掌握的代码如下: def _fetch_exrates(date): import json import urllib.request f = urllib.request.urlopen('http://openexchangerates.org/api
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)
然后使用上面的字符串来构造它。将其作为字符串输入。对不起,我对python非常陌生,请您详细说明如何将其输入URL,非常感谢您绝对的传奇非常感谢!欠你一大笔钱,没那么难。在遇到这样的问题之前,您最好先阅读文档:是的,我试过了,但编程对我来说并不是第二天性我是数学本科生而不是计算机科学专业的学生
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)