-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqiita_api_template.py
43 lines (38 loc) · 1.17 KB
/
qiita_api_template.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
33
34
35
36
37
38
39
40
41
42
43
import argparse
import requests
import json
# Initialize about argument
parser = argparse.ArgumentParser()
args = parser.parse_args()
parser.add_argument('-all',action='store_true',help='All the item can be seen')
# Initialize for request
api = "https://qiita.com/api/v2/items"
token = "" #Write your Token getting by Qiita
headers = {"Authorization":"Bearer"+" "+token}
params = {
"page":"1","per_page":"1","query":"python",
"tags":[
{
"name": "python",
}
]
}
# Execute using Qiita API
def qiita_search():
response = requests.get(api,params=params,headers=headers)
if response.status_code<300: #"response.status_code.ok" is also good
print("[API Request is successed]")
data = json.loads(response.text)
for item in data:
info_print(item["id"],item["title"],item["updated_at"],item["likes_count"],item["stocks_count"])
if args.all:
info_print(item)
else:
print("[HTTPError]"+str(response.status_code))
def info_print(*args):
print("-----------------")
for i in args:
print(str(i))
print("-----------------")
if __name__ == "__main__":
qiita_search()