【发布时间】:2016-02-29 14:23:57
【问题描述】:
我正在尝试将我的函数插入一些我从“日期时间”url API 中获得的“int”。 首先我从 API 导入 UNIX 时间戳,我得到的数据不是一个干净的数字,所以我需要用强制转换函数来划分它,所以我只会得到“数字”,我得到一个“1382310549”的 UNIX 并转换它到一个常规日期,然后我只要求“年”,我得到“2013”,问题是我的功能给我“无”而不是给我“2013”相等的东西,那就是“哇“…… 它看起来函数无法理解什么是 (value.strftime('%Y')...
import urllib.request
import datetime
response3 = urllib.request.urlopen("https://blockchain.info/q/addressfirstseen/1LuckyR1fFHEsXYyx5QK4UFzv3PEAepPMK").read()
def type_conversion(val, to_type, default=None):
try:
return to_type(val)
except ValueError:
return default
def FirstTransaction(c):
if c == 2013 :
return ('wow')
elif c == 2010 :
return ('yeaaaa')
timestamp = (type_conversion(response3, int))
value = datetime.datetime.fromtimestamp(timestamp)
print(FirstTransaction(value.strftime('%Y')))
Tnx 伙计们!
【问题讨论】:
标签: python api http python-3.x url