Recent ranking creation using Qiita API with Python

【environment】

windows8.1  python2.7

【Overview】

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.

[Preparation]

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)

【program】

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

【problem】

・ 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.

[Impression / future]

・ 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.

[Reference site]

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

Recent ranking creation using Qiita API with Python
Stock number ranking by Qiita tag with python
Try using ChatWork API and Qiita API in Python
Register a ticket with redmine API using python requests
[Python] Using Line API [1st Creation of Beauty Bot]
[Python] Get user information and article information with Qiita API
Use Trello API with python
Use Twitter API with Python
Using Quaternion with Python ~ numpy-quaternion ~
[Python] Using OpenCV with Python (Basic)
Web API with Python + Falcon
Play RocketChat with API / Python
Call the API with python3.
Use subsonic API with python3
Using OpenCV with Python @Mac
Qiita API Oauth with Django
Send using Python with Gmail
Get ranking with Rakuten API
Recent Ability of Image Recognition-MS State-of-the-art Research Results Using Computer Vision API with Python
Create API with Python, lambda, API Gateway quickly using AWS SAM
Play with YouTube Data API v3 using Google API Python Client
Complement python with emacs using company-jedi
Harmonic mean with Python Harmonic mean (using SciPy)
Create Awaitable with Python / C API
Data acquisition using python googlemap api
Using Rstan from Python with PypeR
Get reviews with python googlemap api
[Python] Using OpenCV with Python (Image transformation)
Run Rotrics DexArm with python API
[Python3] Google translate google translate without using api
[Python] Using OpenCV with Python (Edge Detection)
Try using Pleasant's API (python / FastAPI)
Hit the Etherpad-lite API with Python
[python] Read information with Redmine API
Get Qiita trends with Python scraping
Try using Python argparse's action API
Notes on using rstrip with python.
Create API using hug with mod_wsgi
Excel graph creation using python xlwings
Run Ansible from Python using API
When using MeCab with virtualenv python
Precautions when using six with Python 2.5
GUI creation in python using tkinter 2
Implementation of CRUD using REST API with Python + Django Rest framework + igGrid
Using Python with SPSS Modeler extension node (2) Model creation using Spark MLlib
Implement ranking processing with ties in Python using Redis Sorted Set
Collecting information from Twitter with Python (Twitter API)
Mouse operation using Windows API in Python
[AWS] Using ini files with Lambda [Python]
Try logging in to qiita with Python
Try using the Wunderlist API in Python
Automatically create Python API documentation with Sphinx
GUI creation in python using tkinter part 1
Try mathematical formulas using Σ with python
Behind the flyer: Using Docker with Python
Simple Slack API client made with Python
Bulk posting to Qiita: Team using Qiita API
Retrieving food data with Amazon API (Python)
Using Python and MeCab with Azure Databricks
Tweet using the Twitter API in Python
Try using Dropbox API v2 with Go