Lo-Fi Python

May 15, 2023

Wordpress to Pelican Blog Migration Complete

This blog is formerly known as "Python Marketer" from 2016 to 2023. In May 2023, I've begun the migration from Wordpress's "Personal" plan to a free, Pythonic Pelican static site. 100 posts are now hosted here exclusively on lofipython.com. I will be posting my projects, Python explorations and technical notes here going forward. Thank you for reading and I hope you enjoy these Python musings. If you want to keep up with my writing, I recommend using an RSS reader to follow the RSS or Atom feeds.

I've decided to continue blogging under a new Python moniker which is more fitting of who I am as a Pythonista in 2023. WordPress gave me my start as a blogger before I had the capabilities to make my own. Now, I've switched from their "Personal" plan to a Pelican + Cloudlare Pages free plan blog stack. It's going great so far and will save me $48 per year vs. WordPress. Not to mention, I have a hard backup of all my content and host it on Github! I'm no longer dependent on a paid blogging platform to serve my blog. Huge win all around. Here's to whatever Python projects are next!

The Next Chapter: Lo-Fi Python

Lo-fi (also typeset as lofi or low-fi; short for low fidelity) is a music or production quality in which elements usually regarded as imperfections in the context of a recording or performance are present, sometimes as a deliberate choice. Wikipedia

The Spirit of Low Fidelity

Lo-Fi Python aims to find the "lo-fi" spirit of Python. Doing more with less. Favoring the standard library. Lowest possible time to MVP (minimum viable product). Learning new libraries. Exploring the ecosystem with playful curiosity. Embrace helping others by helping yourself. This is the way.

Dec 04, 2022

An Example Pelican + Git Blog Post Workflow

In my Ubuntu Linux environment, I'm now publishing new blog posts following this Pelican + Python + git workflow.

  1. Activate the Python environment:
# Create with a virtual env with venv: python -m venv env_name
source env_name/bin/activate
  1. Clone your repo and go to the project folder:
git clone https://github.com/erickbytes/lofipython.git && cd lofipython && ls
  1. Run Python script to create new markdown or .rst file from a template:
python new_post.py
  1. Compile the new post with the Pelican content command:
pelican content
  1. Use the Pelican listen command to serve blog to the default port 8000:
pelican -l
  1. Preview your new post at localhost:8000 in Firefox:
firefox -new-tab http://127.0.0.1:8000
  1. Use git to stage, commit and push the files to a Github repo:
git add .
git commit -m "new post edits and fixes"
git push -u origin main

The new blog post is now live! This is my own workflow for my Pelican blog, this blog which is hosted for free with Cloudflare Pages. You can read more about connecting Pelican and Cloudflare in this past post I wrote.


Github SSH Required

You will need to create a SSH key and connect it to your Github account to get this working, as it's required by Github now. Make sure you write down your passphrase. I was able to create an ssh key with this command:

ssh-keygen -t ed25519 -C "yourname@example.com"

Scripting New Post Creation

Below is the short Python script I wrote for generating the markdown file for a new post, "new_post.py" in the above workflow.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from datetime import date


def post_name():
    """Ask for the new post's name."""
    name = input("Enter the new post's title:\n")
    return name


def post_template(title):
    """Return str, post draft"""
    post = f"Title: {title} \nDate: {date.today()} 4:20 \nCategory: Essay"
    return post


def save_draft(name, post):
    """Save new post draft to content folder."""
    content = "~/projects/lofipython/content"
    name = name.replace(" ", "-")
    md = f"{content}/{name}.md"
    with open(md, "w") as fhand:
        fhand.write(post)
    return None


name = post_name()
post = post_template(name)
save_draft(name, post)

I've enjoyed working this out on my new blog. I can easily edit, improve and fire off blog posts rapidly with this command line workflow.

Oct 08, 2022

Pelican Fix for "No valid files found in content"...

Pelican is a popular static site generator library in Python. I didn't know why my pelican blog was not working. I've used the "pelican content" command many times for my blog. This time, when attempting to write a new post on a new computer, I was getting this error where none of my posts were visible to Pelican:

1
2
3
4
5
WARNING  No valid files found in content for the active         log.py:91
         readers:
           | BaseReader (static)
           | HTMLReader (htm, html)
           | RstReader (rst)
no valid files found in pelican content

Solution

Install the markdown library, which is stated in the pelican docs. This Github issue also provides some background on this warning.

pip install markdown
python pip installing markdown

Now my "pelican content" command works!

pelican content
successful pelican content build