forked from ramwin/python-reference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshanbay.py
More file actions
39 lines (37 loc) · 1012 Bytes
/
shanbay.py
File metadata and controls
39 lines (37 loc) · 1012 Bytes
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
33
34
35
36
37
38
39
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Xiang Wang @ 2016-10-16 15:30:58
import requests, click
import pprint, os, json, string, re
API_URL = "https://api.shanbay.com/"
APP_KEY = "88b23593fb4146a53337"
APP_SECRET = "672395382beb0c019d9762604fd98d046b602b17"
def result(r):
try: pprint.pprint(json.loads(r.text), indent=4)
except:
file = open('test.html','w')
file.write(r.text)
file.close()
os.system('open test.html')
def get_auth():
""" 获取token """
APP_URL = "oauth2/authorize/"
r = requests.get(
url=os.path.join(API_URL, APP_URL),
params={
"client_id": APP_KEY,
'client_secret': APP_SECRET,
"response_type": "token", }
)
result(r)
@click.command()
@click.argument('word')
def get_word(word):
APP_URL = 'bdc/search'
r = requests.get(
url=os.path.join(API_URL, APP_URL),
params={'word': word}
)
result(r)
if __name__ == '__main__':
get_word()