Word count of blogs

Let’s see how it’s going with writing words in blog posts.

I’ll use some code and a few packages to loop through all my blog posts so far and count the number of words in each blog post.

[26]:
1import requests
2from bs4 import BeautifulSoup
3import matplotlib.pyplot as plt
4from urllib.parse import urljoin

Data acquisition

I start by getting the archive page from my blog because all the blog posts are listed there in order. I’m running a local server of my blog just because it’s more convenient.

[61]:
1url = "http://localhost:8000/archive/"
2archive_rsp = requests.get(url)
3archive_soup = BeautifulSoup(archive_rsp.text)
4archive_html = archive_soup.find(id="archive")
5archive_links = archive_html.find_all("a")
6archive_links = [a for a in archive_links if "headerlink" not in a.get("class")]
7
8for a in archive_links:
9    print(a.get("href"))
../2026/faroe-islands-2020/
../2026/litli-hrutur-eruption-2023/
../2026/fzf-for-blogging/
../2026/dillo-the-web-browser/
../2026/my-least-favourite-button/
../2026/my-favourite-button/
../2026/a-few-rivers/
../2026/backup/
../2026/how-air-you/
../2026/pictures-of-puffins/
../2026/pixel-home-for-homeassistant/
../2026/pictures-and-thumbnails/
../2026/the-simplest-blog-post/
../2026/blogtober/
../2024/python-graphviz-flow-chart-simple-example/

Data processing

Now that I have all the pages, I loop through them and get the content. Then I find the text paragraphs that have no class because there are some other paragraphs there that are not part of the main text and I don’t want to count those. Only the paragraphs that I write as part of the main text have no class. It’s not something I did on purpose but I’ll use it now because why not.

Then I join the paragraphs and split them on space and check the length of the list.

[65]:
 1page_words = {}
 2for a in archive_links[::-1]:
 3    link = a.get("href")
 4    name = link.split("/")[2]
 5    page_rsp = requests.get(urljoin(url, link))
 6    page_soup = BeautifulSoup(page_rsp.text)
 7    pars = page_soup.find("main").find_all("p")
 8    pars = [p for p in pars if p.get("class") is None]
 9    pars = [p.text for p in pars]
10    words = len(" ".join(pars).split(" "))
11    page_words[name] = words

Results

I plot the results with matplolib. The blog posts are ordered by time with the first one furthest to the left.

[93]:
1plt.figure(dpi=150, figsize=(8, 3))
2plt.plot(page_words.values(), "-o")
3locs = list(range(len(page_words)))
4plt.xticks(locs, list(page_words.keys()), rotation=90)
5plt.ylabel("Number of words")
6plt.title("The number of words in a blog post over time");

Conclusion

The graph seems to confirm what I suspected; there appears to be a trend toward a decreasing word count over time. It is possible that this is because I am tired of blogging every day. However, more data is needed before I can draw any conclusive conclusion.