TL;DR
If you look at the article you posted, the number of PV will be displayed.
It seems that you can only see the articles you posted.
That being said, I wondered if I could somehow get this all at once.
Qiita API v2
It seems that you can use the Qiita API to achieve this.
If you use the API related to "post", it seems that you can get it as page_views_count (views).
When I looked it up, there were some articles that did the same thing, but I would like to write it myself for studying.
The theme is Python.
The following two Qiita APIs are used.
First, get an access token.
Please issue an access token from "Settings" → "Applications".
The scope should have read_qiita
this time.
Remember the value of the token you got here.
You can check the created access token as a list.
This environment is here.
$ python3 -V
Python 3.6.8
For HTTP requests, we will use Requests.
$ pip3 install requests
Here is the version of Requests I used.
$ pip3 freeze
...
requests==2.22.0
...
Now, let's create the source code to get the number of PV.
I made it like this.
get_qiita_item_pv.py
from time import sleep
import requests
access_token = "[Created access token]"
item_list_base_url = "https://qiita.com/api/v2/authenticated_user/items"
headers = { "Authorization": f"Bearer {access_token}" }
page = 1
per_page = 100
sleep_time = 0.1
page_views = []
while True:
item_list_url = f"{item_list_base_url}?page={page}&per_page={per_page}"
items = requests.get(item_list_url, headers = headers)
items_body = items.json()
if not len(items_body):
break
for entry in items_body:
item_id = entry["id"]
item_url = f"https://qiita.com/api/v2/items/{item_id}"
item = requests.get(item_url, headers = headers)
item_body = item.json()
title = item_body["title"]
url = item_body["url"]
tags = item_body["tags"]
created_at = item_body["created_at"]
page_views_count = item_body["page_views_count"]
page_views.append({
"title": title,
"url": url,
"tags": [ tag["name"] for tag in tags ],
"created_at": created_at,
"page_views_count": page_views_count
})
sleep(sleep_time)
page += 1
sleep(sleep_time)
page_views.sort(key = lambda e: e["page_views_count"], reverse = True)
for page_view in page_views:
print(f"""page_view: {page_view['page_views_count']}
title: {page_view['title']}
url: {page_view['url']}
tags: {page_view['tags']}
created_at: {page_view['created_at']}""")
print()
The number of PV cannot be obtained by the API of the article list (although there is an atmosphere that seems to be obtained by looking at the API document ...), it is actually necessary to call the API of each article. At this time, you will need your credentials (in short, an access token).
Now let's run this script on our account.
The result is like this.
$ python3 get_qiita_item_pv.py
page_view: 6154
title: Ubuntu Linux 18.04 LTS / 18.I want to use OpenJDK 11 with 10
url: https://qiita.com/charon/items/af0f0de2ae9adbc03bfe
tags: ['Java', 'Linux', 'Ubuntu']
created_at: 2018-11-19T13:03:18+09:00
page_view: 3846
title:I want to do docker build under a proxy environment
url: https://qiita.com/charon/items/d8365d610343d64d598e
tags: ['Docker']
created_at: 2019-01-04T11:29:29+09:00
page_view: 1826
title:REQ with ZeroMQ (Python) for the first time-REP pattern
url: https://qiita.com/charon/items/bdbef40fca6fa89edb24
tags: ['Python', 'ZeroMQ']
created_at: 2019-04-09T16:32:42+09:00
page_view: 1735
title:Tail Apache access log with Fluentd and throw it into Elasticsearch
url: https://qiita.com/charon/items/86d12ac7ca2d7cf6c580
tags: ['Apache', 'Fluentd', 'Elasticsearch', 'Kibana']
created_at: 2018-12-12T09:09:26+09:00
page_view: 1613
title:QA site using Stack Overflow clone, Scoold
url: https://qiita.com/charon/items/cacc2cfac380d8ad46b9
tags: ['Java', 'AdventCalendar']
created_at: 2018-12-11T14:34:57+09:00
page_view: 1385
title:Send the log of the container started by Docker Compose to Amazon CloudWatch Logs
url: https://qiita.com/charon/items/7e2328e5abf7340d32b6
tags: ['Docker', 'CloudWatch-Logs']
created_at: 2019-05-07T12:49:04+09:00
~abridgement~
It might be interesting to see what you see in the articles you wrote from time to time. I think.
Recommended Posts