Python net worth data interface call example sharing, python net worth

Source: Internet
Author: User

Python net worth data interface call example sharing, python net worth

Code Description: Python-based net worth data interface call code instance
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 your applied 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} pa Rams = 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} pa Rams = 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 ()

Articles you may be interested in:
  • In linux, the python monitoring network interface is used to obtain the network input and output.
  • Tutorial on implementing restful interfaces for MySQL In the Python framework
  • Detailed description of the WSGI interface connecting the Python program to the server
  • In-depth parsing of WSGI interfaces in Python
  • Example of writing a simple service interface using the Python Bottle framework

Related Article

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.