Created
November 4, 2017 03:38
-
-
Save jianghu52/9f2cc38c40613dee22abe9fb14b7f828 to your computer and use it in GitHub Desktop.
获取汇率的脚本
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#python | |
import json,urllib | |
from urllib.parse import urlencode | |
import urllib.request | |
url = 'http://api.k780.com/' | |
params = { | |
'app' : 'finance.rate', | |
'scur' : 'USD', | |
'tcur' : 'CNY', | |
'appkey' : '10003', #需要注册https://www.nowapi.com获得 | |
'sign' : 'b59bc3ef6191eb9f747dd4e83c99f2a4', #需要注册https://www.nowapi.com获得 | |
'format' : 'json', | |
} | |
params = urllib.parse.urlencode(params) | |
f = urllib.request.urlopen('%s?%s' % (url, params)) | |
nowapi_call = f.read() | |
#print content | |
a_result = json.loads(nowapi_call) | |
if a_result: | |
if a_result['success'] != '0': | |
print(a_result['result']) | |
else: | |
print(a_result['msgid']+' '+a_result['msg']) | |
else: | |
print('Request nowapi fail.') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
从v2ex网站上的一个人的提问发现的一个小脚本,留着可能不知道哪天就能用得上