windows8.1 python2.7
Create recent user rankings and tag rankings using the Qiita API. User ranking is based on the number of followers, and tag ranking is based on the number of items on that tag. I'm ranking.
To run the program, get the token from the qiita settings page. (Click the image on the upper right) → (Settings) → (Application) → (Issue a new token)
User ranking
user_rank.py
# -*- coding: utf-8 -*-
from qiita_v2.client import QiitaClient
#Get by inheriting QiitaClient_Override user
class child_QiitaClient(QiitaClient):
def get_user(self, id, params=None, headers=None):
'''Returns a specific user.
'''
return self.get("/users?page={}&per_page=100".format(id), params, headers)
TOKEN="Please enter the token you got"
client = child_QiitaClient(access_token=TOKEN)
#Initialize the array for ranking(For the number of people being followed)
rank_followers = []
i = 0
for i in xrange(10):
rank_followers.append(0)
#Initialize the array for ranking(For user name)
rank_user_name = []
i = 0
for i in xrange(10):
rank_user_name.append("")
i = 0
for i in xrange(1,101):
res = client.get_user(str(i))
json_data = res.to_json()
for j in xrange(0,100):
#Username assignment
user_name = json_data[j]["id"]
#Substitution of the number of people being followed
user_followers = json_data[j]["followers_count"]
#Ranking
for k in xrange(10):
if rank_followers[k] < user_followers:
rank_followers[k] = user_followers
rank_user_name[k] = user_name
break
print rank_followers
print rank_user_name
Tag ranking
tag_rank.py
from qiita_v2.client import QiitaClient
#Get by inheriting QiitaClient_Override tag
class child_QiitaClient(QiitaClient):
def get_tag(self, id, params=None, headers=None):
'''Returns a specific tag.
'''
return self.get("/tags?page={}&per_page=100".format(id), params, headers)
TOKEN="Please enter the token you got"
client = child_QiitaClient(access_token=TOKEN)
#Initialize the array for ranking(For the number of items in the tag)
rank_item = []
i = 0
for i in xrange(10):
rank_item.append(0)
#Initialize the array for ranking(For tag names)
rank_tag_name = []
i = 0
for i in xrange(10):
rank_tag_name.append("")
i = 0
for i in xrange(1,101):
res = client.get_tag(str(i))
json_data = res.to_json()
for j in xrange(0,100):
#Tag name assignment
tag_name = json_data[j]["id"]
#Substitution of the number of items in the tag
tag_item = json_data[j]["items_count"]
#Ranking
for k in xrange(10):
if rank_item[k] < tag_item:
rank_item[k] = tag_item
rank_tag_name[k] = tag_name
break
print rank_item
print rank_tag_name
・ Since only the latest 10,000 items can be acquired by both users and tags, all information can be ranked. could not. -Since the get_user function does not have a Contribution item, it has been ranked by the number of followers.
・ If you scrape the user information page of Qiita, you will be caught in the usage restrictions. It was interesting to think about how to get information. ・ If I have a chance, I would like to rank all Qiita users and tags.
Qiita API v2 documentation Python Wrapper for Qiita API v2 Matter that Qiita API does not change the number of contributions for some reason Inherit and override the class
Recommended Posts