[PYTHON] The Like (LGTM) order has disappeared from My Page, so use the Qiita API to get it.

at first

I couldn't see the order of likes, so I decided to write the code. Wasn't there demand for it being erased?

Operating environment

code

If you change the USER_ID, you can get a list of posts by another user.

import http.client
import json
import math

CONN = http.client.HTTPSConnection('qiita.com', 443)
USER_ID = 'riekure'
PER_PAGE = 100

class Api:
    #Return request result in JSON format
    @staticmethod
    def request(http, url) :
        CONN.request(http, url)
        res = CONN.getresponse()
        data = res.read().decode('utf-8')
        return json.loads(data)

    #Calculate the page number from the number of posts
    @staticmethod
    def page_count(items_count) :
        return math.floor(items_count / PER_PAGE) + 1

#Get the number of posts
items_count = Api.request('GET', '/api/v2/users/' + USER_ID)['items_count']
page = Api.page_count(items_count)

#Get all posted articles
all_article = {}
for i in range(page) :
     article = Api.request('GET', '/api/v2/users/' + USER_ID + '/items?page=' + str(i+1) + '&per_page=' + str(PER_PAGE))
     for j in range(PER_PAGE) :
         try :
             all_article[article[j]['title']] = article[j]['likes_count']
         except IndexError :
             break


#Sort by likes (LGTM) in descending order
# items()Becomes a tuple because it uses
tuple_items = sorted(all_article.items(), key=lambda x:x[1], reverse=True)

#Display in markdown tabular format
print('|Article title|Like count|')
print('|------------|--------------|')
for title, likes_count in tuple_items:
    print('| ' + title + ' | ' + str(likes_count) + ' |')

Execution result

Results as of June 2, 2020

Article title Like count
Steps to get Visual Studio Code available in Unity 61
[Windows 10]The engineer who stretches his finger to the arrow keys is Zako! Was ridiculed (introduction of Change Key and AutoHotkey) 54
AWS Certified Solutions Architect after 10 months of study-Associate-I can't pass, so I look back on how to study 42
AWS Certified Solutions Architect over a year-Associate-I passed the exam, so I look back on my study method 29
ESLint introduction story to eradicate fucking code mass production projects 29
Mysql on Amazon Linux 2-What to do if the server cannot be installed 27
Java 8 LocalDateTime type conversion(String, java.util.Date) 22
Use inequality comparison operators in MyBatis SQL 22
AWS Certified Solutions Architect to Address Table-Associate(SAA)* Updated from time to time 20
A Java programmer studied Python.(About the type) 19
Don't stop updating until you pass the AWS Certified Solutions Architect Associate! 19
AWS Certified Solutions Architect Associate(SAA)Failure experience 18
How to execute a command as a user who cannot log in + bonus 17
A confused story about a ternary operator with multiple conditional expressions 17
[Beginner]If you think that you are using AWS in the range of several hundred yen a month, you were charged about 2000 yen 15
Shortcut comparison for those migrating from Eclipse to IntelliJ IDEA(Windows) 15
How to convert a file to a byte array in Java 15
[Unity] What to do when Standard Assets is not displayed in the Import Package 14
Basic usage of git revert 14
(Java 7 or later only)Objects are Objects.I want you to compare with equals 12
【Unity】Unity-Chan!Investigation results and solutions when a CS0234 error occurs in (Unity-chan) 9
Bottom 10%As a result of solving puzzles that can only be solved by bad engineers, the bottom 10%Turned out to be a bad engineer 9
How to set Windows 10 notebook PC built-in keyboard to JIS layout, Bluetooth connection keyboard to US layout 9
A Java programmer studied Python.(for, if,while statement) 9
【Java】 (list == null list.size() == 0)I don't like the fact that I'm checking NULL / empty 8
[MyBatis]Use Cursor when mapping large amounts of data 8
[Java]What should I use to write a file? 7
A Java programmer studied Python.(function(Method)about) 7
What is the difference between SimpleDateFormat and DateTimeFormatter? ?? 7
I tried to implement a check process that makes errors other than alphanumeric symbols, hiragana, katakana, JIS 1st / 2nd level kanji in Java 6
[VS Code] Set the indent width, tab or space to use for each language 5
[Unity] open when git add("Temp/UnityLockfile"):Causes of Permission denied and remedies 5
[Java] Delete the specified number of characters from the end of StringBuilder 5
[Java 8]Until you convert standard input that can be used in coding tests into a list or array 5
[Java 8]Alphabetical order and character string length sorting method that can be used in coding tests 5
Oracle SQL(11g)I want to reproduce the MySQL LIMIT OFFSET clause in 5
[Unity] Summary of personally stuck things before building a project for Oculus Go 4
[Unity] When there is no response at startup in Windows 10 4
How to prevent certain files from being deleted with the rm command etc.(chattr, lsattr command) 4
How to find a process using a specific port number 4
[Unity] Understanding asynchronous processing-Coroutine- 3
【Unity】Application.LoadLevel was deprecated 3
Unity +C in Visual Studio Community#Debug and run 3
Be careful because the Oculus Rift can't be run on the Surface Book 2! 3
.bash_Wrong profile settings, any command"command not found"Solution when it becomes 3
A Java programmer studied Python.(About decorators) 3
【Git】fatal: protocol error: bad line length character:How to eliminate usag 2
[Ruby] Array methods that Ruby beginners often use 2
[Ruby] Can it be used in coding tests? How to receive values from standard input 2
AWS Innovate Online Conference "Test Preparation Session 5: Defining an Architecture with Operational Excellence" 2
AWS Innovate Online Conference "Test Preparation Session 4: Designing a Cost Optimization Architecture" 2
AWS Innovate Online Conference "Test Preparation Session 1: Designing a Recoverable Architecture" 2
[Python]Get a list of posts using the Qiita API+Looking back on 2018 2
Bottom 20%Solved a puzzle that only a bad engineer couldn't solve 2
[Java]Java the functions I created in the past.io.File to NIO.Rewrite in 2 2
Identifies and forcibly terminates the session during DB connection with Oracle SQL(KILL) 2
Aurora(MySQL)I got an error when I tried CREATE VIEW 2
[Unity] Component activation/Switch invalidation by pressing a button 1
[Ruby] I regret the reason why I made a mistake in the declaration of the 2D array and could not change the elements as expected. 1
[Unity] Separate processing by distinguishing between Unity Editor and actual smartphone 1
【Unity】UnityEditor.BuildPlayerWindow+What to do if you cannot build Android due to BuildMethodException 1
AWS Innovate Online Conference "Test Preparation Session 3: Defining Secure Applications and Architecture" 1
AWS Innovate Online Conference "Test Preparation Session 2: Defining a High Performance Architecture" 1
Most engineers couldn't solve Puzzle 3 1
[Unity]"Can't add script behavior XXXX.The script needs to derive from MonoBehaviour"4 ways to improve 1
[Unity] Understanding asynchronous processing ~ async/await edition ~ 0
[Unity] What to do if you get an "incomplete or corrupted download file" when installing Unity from Unity Hub 0
Scrum Development Glossary for those who don't have the time 0
[Slack] Procedures for skipping messages using the Slack API 0
[Katalon Studio] How to make a dark theme (black background) 0
[Katalon Studio] How to change the default browser 0
THETA Web API v2.How to run 1 with the curl command 0
What to do if you can't connect to AWS Cloud9 in Chrome 0
[Oracle] How to get table column information by SQL 0

At the end

Why can't I get LGTM for articles I wrote with a lot of energy, but I can get LGTM for articles I wrote roughly?

Recommended Posts

The Like (LGTM) order has disappeared from My Page, so use the Qiita API to get it.
From the introduction of GoogleCloudPlatform Natural Language API to how to use it
Use the MediaWiki API to get Wiki information
I tried to scrape YouTube, but I can use the API, so don't do it.
I tried to get various information from the codeforces API
How to get followers and followers from python using the Mastodon API
Use the Flickr API from Python
I tried to get the authentication code of Qiita API with Python.
Use twitter API to get the number of tweets related to a certain keyword
[Free] Hit the Clash Royale API from lambda and send it to LINE