Likho’s microblog.py

Updated 2024 Jan 10 by Likho (licho@firemail.cc)

microblog.py is a simple microblog generator written in under 500 600 lines of Python.

If you use it, let me know. I can also add you to my webring.

git:https://notabug.org/likho/microblog.py

example: https://likho.neocities.org/microblog/

Features:

Perks over social media platforms.

Usage

microblog.py assumes the user has a basic understanding of HTML and CSS. There is no code specific to an operating system, but Linux users would have the least trouble running it.

See also https://notabug.org/likho/microblog.py#usage.

Getting Started

These are the sequence of commands to get started.

git clone https://notabug.org/likho/microblog.py microblog
cd microblog
cp example/Makefile .
make

This means to:

  1. download the program using a git client into a folder called microblog
  2. enter the folder microblog
  3. copy and paste the file example/Makefile into the current folder.
  4. invoke make

This should generate an example page named result.html which can be opened in a web browser for preview. It should also avail the files template.tpl, timeline.css, settings.toml, and content.txt.

To help discern which elements are which, some borders in result.html are color-coded in red, blue, and green.

If you don’t want to use Gnu Make…

make is only there for convenience. If you want to use another interface, this is the page generation command:

python microblog.py ./template.tpl ./content.txt >  result.html

You can rename the files content.txt, template.tpl, and result.html however you wish. These are only names provided by example.

Posting images

Images are inserted into posts automatically. For example if content.txt contains the following

Thu Mar 16 2:22:22 PM EDT 2022
I took these pictures.
/images/1.jpg /images/2.jpg /images/3.jpg

In this case, the images are rendered within the gallery and panel elements as

<a href="/images/1.jpg"><img src="/images/1.jpg" class="embed"></a>

and so on.

However, this is only adequate for images of small sizes such as screenshots of old cartoons, books, or web pages. Note, relative paths (e.g ./images/1.jpg) may break on paginated posts or tags.

Images with Thumbnails

See [post.gallery] in settings.toml

microblog.py requires a thumbnail image and the full-sized image to be of the same name but in different folders.

An example:

Thu Mar 16 2:22:22 PM EDT 2022
I took these pictures.
1.jpg 2.jpg 3.jpg

If there is no symbol such as ‘.’ or ‘/’ that specifies a directory, a path based on user preferences will be prepended to the image file names, presumably for thumbnail and full-sized images.

Accepted Images

See [post] in settings.toml

accepted_images is a list of strings containing recognized file extensions for images. By default, jpg and png are provided.

Other Notes

microblog.py does not manage or resize images for the user.

The functionality can be added as a make recipe. Given three folders, import (contains new, raw, or uncompressed images), images and thumbs,

# for each images in import 
# resize to 720p or 140p and put it in a folder
SOURCE=$(shell ls import)
TOOL=magick
images: 
    for image in $(SOURCE) ; do \
        $(TOOL) import/$$image -resize 1280x720 images/$$image;\
        $(TOOL) import/$$image -resize 256x140 thumbs/$$image;\
    done

Enable webring

See [webring] in settings.toml

Webring is disabled by default in settings.toml. It can be enabled by setting false to true.

Adding to webring

The followers list is an array of strings.1

list= ["https://likho.neocities.org/microblog/meta.json"]

An array can also be broken into multiple lines.

list = [
    "https://likho.neocities.org/microblog/meta.json",
    "https://somewhere.else/microblog/meta.json"
]

See https://toml.io/en/v1.0.0#array for acceptable syntax.

You can add someone on an alternate DNS root like OpenNIC as long as your computer resolves the URL. Just don’t expect that same URL to resolve for everyone else visiting your page.

HTML Detection

Multiple lines of HTML can be included in notes without triggering automatic markup.

A few caveats:

Good Practice

Keep content simple and maintainable.

Sat Nov 25 10:19:03 AM PST 2023
Test code block
<div style="overflow-x:scroll">
    <pre>
    <code>
    #include <stdio.h>
    int main(void) {
        printf("Hello world! I am a C program.\n");
        return 0;
    }
    </code>
    </pre>
</div>

In this example, a code block has a long sentence which may trail off to the sides on phones or other small devices. overflow-x adds a horizontal scroll bar so all text remains within its containers. Ideally, don’t use <div> or <span> unless necessary. In most cases, overflow-x:scroll is good enough.

The following may lead to bad results, more effort than necessary, or unmaintainability of the microblog or website. Generally, anything complex or fancy is better off as its own blog or page.

Disclosures

The project uses pycurl and urllib for web requests.2

neouploader.py, to upload files in bulk to neocities, handles password using getpass.3

microblog.py on the branch syndication uses HTTP connections only to fetch data.4`

Proxy Behavior

microblog.py supports proxied connections since the branch syndication had been merged to master.

Tor support can be enabled by setting either

As a result, the full script invocation will look like:

https_proxy=socks://127.0.0.1:9050 python microblog.py

The proxy resolves domain regardless of whether socks:// or socks5h://is specified.5

Common Errors

A key may be missing from your settings file (KeyError)

This most likely occurs after an update that added new configuration options. The differences between the reference settings.toml and a user copy can be reviewed by the following command.

diff example/settings.toml my/settings.toml

Why I’m not using the Fediverse

The foremost alternative to Twitter or Tumblr was the Fediverse, and I lost interest in the Fediverse for reasons as complex as the Fediverse is. But an approximation is that it is very easy to find poor administration or overbearing moderation in the Fediverse. The visibility of content is also subject to arbitrary white/blacklisting set by the administrator.6

I originally had profiles on gnusocial.no and sendero.social. Both sites are offline now. However, I also found myself a misfit in a culture of people who want information delivered on a timeline.


  1. https://notabug.org/likho/microblog.py/src/syndication/example/settings.toml#L44↩︎

  2. https://notabug.org/likho/microblog.py/src/v0.1.0/neouploader.py#L2↩︎

  3. https://notabug.org/likho/microblog.py/src/v0.1.0/neouploader.py#L39↩︎

  4. https://notabug.org/likho/microblog.py/src/syndication/microblog.py#L378↩︎

  5. https://notabug.org/likho/microblog.py/src/3bf37386fcd40d61ac529dc03e00db3085238ce9/microblog.py#L396↩︎

  6. https://fediverse.wiki/wiki/Fediblock↩︎