-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstock.py
32 lines (27 loc) · 962 Bytes
/
stock.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import urllib,sys
import urllib.request
import json
import numpy as np
host = 'http://stock.market.alicloudapi.com'
path = '/sz-sh-stock-history'
method = 'GET'
appcode = '6a611850fcc942939ec34411c37ffb3d'
querys = 'begin=2015-09-01&code=600004&end=2015-09-02'
bodys = {}
url = host + path + '?' + querys
request = urllib.request.Request(url)
request.add_header('Authorization', 'APPCODE ' + appcode)
response = urllib.request.urlopen(request)
content = response.read()
class MyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, np.ndarray):
return obj.tolist()
elif isinstance(obj, bytes):
return str(obj, encoding='utf-8')
return json.JSONEncoder.default(self, obj)
json_str = json.dumps(content,cls=MyEncoder)
if (content):
print(content)
print(" ")
print(json_str)