Skip to content

Commit 020da33

Browse files
Add files via upload
1 parent 3ea7b87 commit 020da33

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

qiita_api_template.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import argparse
2+
import requests
3+
import json
4+
5+
# Initialize about argument
6+
parser = argparse.ArgumentParser()
7+
args = parser.parse_args()
8+
parser.add_argument('-all',action='store_true',help='All the item can be seen')
9+
10+
# Initialize for request
11+
api = "https://qiita.com/api/v2/items"
12+
token = "" #Write your Token getting by Qiita
13+
headers = {"Authorization":"Bearer"+" "+token}
14+
params = {
15+
"page":"1","per_page":"1","query":"python",
16+
"tags":[
17+
{
18+
"name": "python",
19+
}
20+
]
21+
}
22+
23+
# Execute using Qiita API
24+
def qiita_search():
25+
response = requests.get(api,params=params,headers=headers)
26+
if response.status_code<300: #"response.status_code.ok" is also good
27+
print("[API Request is successed]")
28+
data = json.loads(response.text)
29+
for item in data:
30+
info_print(item["id"],item["title"],item["updated_at"],item["likes_count"],item["stocks_count"])
31+
if args.all:
32+
info_print(item)
33+
else:
34+
print("[HTTPError]"+str(response.status_code))
35+
36+
def info_print(*args):
37+
print("-----------------")
38+
for i in args:
39+
print(str(i))
40+
print("-----------------")
41+
42+
if __name__ == "__main__":
43+
qiita_search()

0 commit comments

Comments
 (0)