好文档就是一把金锄头!
欢迎来到金锄头文库![会员中心]
电子文档交易市场
安卓APP | ios版本
电子文档交易市场
安卓APP | ios版本

基于Python的实时汇率接口调用代码实例.doc

3页
  • 卖家[上传人]:ss****gk
  • 文档编号:236739493
  • 上传时间:2022-01-08
  • 文档格式:DOC
  • 文档大小:119KB
  • / 3 举报 版权申诉 马上下载
  • 文本预览
  • 下载提示
  • 常见问题
    • 基于Python的实时汇率接口调用代码实例代码描述:基于Python的实时汇率接口调用代码实例代码平台:聚合数据#!/usr/bin/python# coding: utf-8import json, urllibfrom urllib import urlencode# #汇率调用示例代码一聚合数据# 接口文档: s/80# def main ():#配置您中请的APPKeyappkey =#1 •常用汇率查询request1(appkey,"GET”)#2 •货币列表request 2(appkeyJ f,GE TH)#3 •实时汇率查询换算r equest3(appk ey「GET")#常用汇率查询def r equestl(appk ey^ m=,,GETfl):url = Hhttp://op< juhe>cn/o nebox/exchan ge/query params = {"key" : appkey, #应用APPKEY(应用详细页查询)}params =urlencode(pa rams)if m ==,IGETU:f = ur llib.urlopen (,,%s?%sf, % (url, params)) else:f = ur llib.urlopen (url, params )conten t= f.read()res = js on・loads(con tent)if res:error_code = res["error_code"]if error_c ode== 0:#成功请求print res["result"]else:pr int "%s:%s”% (res[nerro r_coden]^res ["reason"]) else:print Hr equest api er ror"#货币列表d ef request2(appkeyJ m=nG ET"):url = ,fhttp ://op. juhe.c n/onebox/exc hange/list1'params ={"key" : appkey,#应用APPKEY(应用详细页查询)}params = urlencode(params)if m —GET”:f =urllib.urlop en("%s?%su % (url, param s))else:f =urllib>urlop en(url, para ms)cont f. read ()res =jso n.loads(co ntent)i f res:error_code = res[Herro r_coden]if error _code== 0:#成功请求print re s["resultn]else:print ”%s:%s ” % (res[ner ro^code"]^ es["reason"]) else:print ffrequest api error11#实时汇率查询换算def req uest3(appkey , m=nGETn):url = "http://op. nge/currency ” params = {••from" : 转换汇率前的货币代码 ••to••: ••••, #转换汇率成的货币代码“key” : app key,#应用APPK EY(应用详细页査询)}par ams= urlenc ode(pa“ams)if m ==nG ETH:f = urllib.u rlopen(,,%s?%sH % (url, params))e Ise:f = urllib.u rlopen(url,params)content = f .readOre s= json.loads(content)if res:error_code= res[ "erro^code"]if e rror_code== 0:#成功请求prin t res[Nresul t”]e Ise:print "%s:%s” % (res [nerror_code H]onH])els e:pr int nrequest api error"if _name_ main ()mai n。

      点击阅读更多内容
      关于金锄头网 - 版权申诉 - 免责声明 - 诚邀英才 - 联系我们
      手机版 | 川公网安备 51140202000112号 | 经营许可证(蜀ICP备13022795号)
      ©2008-2016 by Sichuan Goldhoe Inc. All Rights Reserved.