Example of Python net worth data interface call

Source: Internet
Author: User
This article mainly introduces the Python net worth data interface call examples to share the relevant information, friends can refer to the following code Description: Python-based net worth data interface call code example
Associated data: net worth data
Interface address: https://www.juhe.cn/docs/api/id/25

#! /Usr/bin/python #-*-coding: UTF-8-*-import json, urllibfrom urllib import urlencode # ---------------------------- # sample code for calling net worth data-aggregate data # online interface documentation: http://www.juhe.cn/docs/25#----------------------------------def Main (): # configure the APPKey appkey = "*************************" #1. all open funds request1 (appkey, "GET") #2. equity Fund request2 (appkey, "GET") #3. request3 (appkey, "GET") #4. monetary Fund request4 (appkey, "GET") #5. closed Fund request5 (appkey, "GET") #6. innovation block request6 (appkey, "GET") # 7.LOF request7 (appkey, "GET") # 8.ETF request8 (appkey, "GET") #9. QDII request9 (appkey, "GET") # all open funds def request1 (appkey, m = "GET"): url =" http://web.juhe.cn:8080/fund/netdata/all "Params = {" key ": appkey, # APPKEY value} params = urlencode (params) if m =" GET ": f = urllib. urlopen (" % s? % S "% (url, params) else: f = urllib. urlopen (url, params) content = f. read () res = json. loads (content) if res: error_code = res ["error_code"] if error_code = 0: # successful request print res ["result"] else: print "% s: % s "% (res [" error_code "], res [" reason "]) else: print" request api error "# stock fund def request2 (appkey, m = "GET"): url =" http://web.juhe.cn:8080/fund/netdata/stock "Params = {" key ": appkey, # APPKEY value} params = urlencode (params) if m =" GET ": f = urllib. urlopen (" % s? % S "% (url, params) else: f = urllib. urlopen (url, params) content = f. read () res = json. loads (content) if res: error_code = res ["error_code"] if error_code = 0: # successful request print res ["result"] else: print "% s: % s "% (res [" error_code "], res [" reason "]) else: print" request api error "# def request3 (appkey, m = "GET"): url =" http://web.juhe.cn:8080/fund/netdata/bond "Params = {" key ": appkey, # APPKEY value} params = urlencode (params) if m =" GET ": f = urllib. urlopen (" % s? % S "% (url, params) else: f = urllib. urlopen (url, params) content = f. read () res = json. loads (content) if res: error_code = res ["error_code"] if error_code = 0: # successful request print res ["result"] else: print "% s: % s "% (res [" error_code "], res [" reason "]) else: print" request api error "# Monetary Fund def request4 (appkey, m = "GET"): url =" http://web.juhe.cn:8080/fund/netdata/monet "Params = {" key ": appkey, # APPKEY value} params = urlencode (params) if m =" GET ": f = urllib. urlopen (" % s? % S "% (url, params) else: f = urllib. urlopen (url, params) content = f. read () res = json. loads (content) if res: error_code = res ["error_code"] if error_code = 0: # successful request print res ["result"] else: print "% s: % s "% (res [" error_code "], res [" reason "]) else: print" request api error "# def request5 (appkey, m = "GET"): url =" http://web.juhe.cn:8080/fund/netdata/close "Params = {" key ": appkey, # APPKEY value} params = urlencode (params) if m =" GET ": f = urllib. urlopen (" % s? % S "% (url, params) else: f = urllib. urlopen (url, params) content = f. read () res = json. loads (content) if res: error_code = res ["error_code"] if error_code = 0: # successful request print res ["result"] else: print "% s: % s "% (res [" error_code "], res [" reason "]) else: print" request api error "# innovation block def request6 (appkey, m = "GET"): url =" http://web.juhe.cn:8080/fund/netdata/innov "Params = {" key ": appkey, # APPKEY value} params = urlencode (params) if m =" GET ": f = urllib. urlopen (" % s? % S "% (url, params) else: f = urllib. urlopen (url, params) content = f. read () res = json. loads (content) if res: error_code = res ["error_code"] if error_code = 0: # successful request print res ["result"] else: print "% s: % s "% (res [" error_code "], res [" reason "]) else: print" request api error "# LOFdef request7 (appkey, m =" GET "): url =" http://web.juhe.cn:8080/fund/netdata/lof "Params = {" key ": appkey, # APPKEY value} params = urlencode (params) if m =" GET ": f = urllib. urlopen (" % s? % S "% (url, params) else: f = urllib. urlopen (url, params) content = f. read () res = json. loads (content) if res: error_code = res ["error_code"] if error_code = 0: # successful request print res ["result"] else: print "% s: % s "% (res [" error_code "], res [" reason "]) else: print" request api error "# ETFdef request8 (appkey, m =" GET "): url =" http://web.juhe.cn:8080/fund/netdata/etf "Params = {" key ": appkey, # APPKEY value} params = urlencode (params) if m =" GET ": f = urllib. urlopen (" % s? % S "% (url, params) else: f = urllib. urlopen (url, params) content = f. read () res = json. loads (content) if res: error_code = res ["error_code"] if error_code = 0: # successful request print res ["result"] else: print "% s: % s "% (res [" error_code "], res [" reason "]) else: print" request api error "# QDIIdef request9 (appkey, m =" GET "): url =" http://web.juhe.cn:8080/fund/netdata/qdii "Params = {" key ": appkey, # APPKEY value} params = urlencode (params) if m =" GET ": f = urllib. urlopen (" % s? % S "% (url, params) else: f = urllib. urlopen (url, params) content = f. read () res = json. loads (content) if res: error_code = res ["error_code"] if error_code = 0: # successful request print res ["result"] else: print "% s: % s "% (res [" error_code "], res [" reason "]) else: print "request api error" if _ name _ = '_ main _': main ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.