Home / Blog Menu ↓

Blog: #python

24 posts / tag feed / about the blog / archive / tags

Momentum

I’m getting back into blogging about in-progress projects, because otherwise I hardly blog at all. Expect posts soon about the following coding projects, all at varying stages of completion:

  • Vinci (notebook app)
  • Bookshelf (successor to Bookkeeper)
  • Codex (successor to Unbindery)
  • Quill (successor to Codex, sort of)
  • Storybook (writing app)
  • Speed (desktop writing app)
  • Liszt (todo list app)
  • Endless (mindmapping app)
  • Botswana 2 (revamp of Botswana)

Brief sidenote: I switched a while back to Python/Django, and I’m very glad I did. I can often get to a working prototype within only an hour or two. Back in my younger days I wanted to write everything myself from the ground up, but I see now that I was foolish. Life is short. I’d rather focus on the interesting parts — the app itself — and let the framework handle the routine grunt work.

Momentum

Momentum is the app I’d like to introduce today. It’s a web app written in Django, started back in January to help me track my goals.

More specifically, I wanted something that would help me spend more time reading scriptures and writing fiction. I don’t always have a free half-hour, though, so I needed something to track little bits of time throughout the day, and Momentum was born. I’ve been using it pretty much every single day since then.

Here’s what it looks like on my phone (with dummy data):

momentum.png

Some quick notes:

  • It currently supports tracking minutes, times, or words per day.
  • When I reach a particular goal, it disappears from the list for the rest of the day so I can focus on the goals I haven’t yet reached. (This is a change I made last night, actually.)
  • If I don’t make any progress toward a goal at all within a set time period, the goal goes stale and turns red. (There’s a system-wide stale period setting and each goal can also have its own.) I started using this staleness idea in Bookshelf (more on that in a later post) and it’s been motivating enough that I ported it to Momentum.
  • It supports folders. I have Projects and Health folders, where I have specific projects (stories/apps I’m working on), and things like squats and pushups.
  • Right now you have to add/edit goals via the Django admin. It works but isn’t as nice as something in-app. I just need to get around to doing this, since this is the main thing keeping it from being releasable.
  • The code is on GitHub as usual. Again, this is unreleased, in-progress code, YMMV, grain of salt, etc.

Reply via email or office hours

Fledge

Introducing Fledge, a file processing language/shell written in Python. I wrote it for two reasons: first, as an experiment with an idea that I’ll explain in a moment, and second, because I can’t for the life of me ever remember how to do batch find-and-replace in text files on the command line. (And yes, I could have written a script to help me with the latter. In fact, I did. I just can’t ever remember what it’s called. I … may have issues.)

Anyway, the idea is that you select the files first, then execute one or more actions on them, rather than the normal way round. For example:

with my-book.text
split on /CHAPTER/ to chapter-%%.text
replace /CHAPTER/Chapter/
trim

That splits my-book.text out on a regex to chapter-01.text, chapter-02.text, etc., does a batch find-and-replace on all those chapter files, and then trims them of whitespace at the beginning and end of each file. The alternative would be something like this, assuming you had split, replace, and trim scripts:

$ split my-book.text "/CHAPTER/" "chapter-%%.text"
$ replace chapter-*.text "/CHAPTER/Chapter/"
$ trim chapter-*.text

So, instead of having to specify which files you’re working on at every step of the way, with Fledge you just do it at the beginning and that selection is used for whatever subsequent actions you perform.

Some more examples

with *.jpg where size != 0
rename page-%%%.text starting with 0

This gets all the non-zero image files in the directory and renames them sequentially to page-000.jpg, page-001.jpg, etc.

alias {mtp} ~/Documents/mtp
with **/*.jpg
convert to png
deselect DSC*
move to {mtp}

This finds all the JPEG files recursively under the current directory, converts them to PNG, deselects everything that starts with DSC, and moves the rest of the PNGs to ~/Documents/mtp.

More about Fledge

The fl script can either execute a script of Fledge actions contained in a file or, if you run it without arguments, it loads an interactive shell.

There are a number of built-in Fledge actions (listed in the README), mostly geared towards working with text and image files, but you can write custom actions (which live in ~/.fledge/actions) to do pretty much anything. (Keeping in mind that in general these would be things you want to do to a large number of files.)

How I’m using it

I use it to help prep image scans of journals and personal histories and stuff to upload to Unbindery for transcription (which, incidentally, I’ve been thinking about paring down to a much simpler, more focused app aimed at family history transcription). I also use it for ebook production (splitting Project Gutenberg files into chapters to be made into EPUBs, doing batch substitutions, etc.) and for Mormon Artist (resizing and renaming images, mostly).

So far, I like it. It’s still very much a work in progress (as I write this I’m realizing rename probably should be rename to for consistency), but I can actually remember these commands. And for situations where I’m doing a lot of sequential actions on multiple files (as in ebook production), it’s nice not having to re-specify everything every step.


Reply via email or office hours

Goodbye, PHP

Yesterday I came across an article on PHP’s bad design practices that woke me up a little. I started using Python a couple years ago on some projects and I’ve loved it. Pure delight. It’s not a perfect language, but it feels so good to me. Coding is more fun and things just come together. It’s uncanny.

I don’t know why I’ve put up with using PHP all this while. My sole reason for writing apps like Bookkeeper, Donne, and Unbindery in PHP instead of Python was that it’s easier for people to deploy PHP on shared hosting, but I don’t think that’s as much of an issue these days.

So, FYI, I’ll be using Python instead of PHP for coding projects going forward.


Reply via email or office hours

md2epub

An itch scratched: md2epub, a Python script for making an EPUB out of Markdown files.

All it takes is a simple book file, which gives the script some basic metadata about the book and then lists the files that need to be included. The script runs Markdown on the files and makes an EPUB.

# Sample book file for md2epub
# 9 Jun 2010

Title: My Sample Book
Author: John Doe
Language: en-US
URL: /books/my-sample-book/
CSS: content/style.css

# Chapters
Foreword | content/foreword.text
Chapter 1 | content/chapter_1.text
Chapter 2 | content/chapter_2.text
Chapter 3 | content/chapter_3.text

# Images to be included
Images: images/illustration1.jpg, images/illustration2.jpg
Image: images/illustration4.jpg

And then you just run “md2epub myfile.book” and voila, instant EPUB. I’ve already used it on my Pearl of Great Price reader’s edition (which I’ll be releasing shortly) and it works like a charm.

Last but not least, the code is based on my friend Matt’s script GetBook.py. (And, in fact, that’s where I got the idea for this script.)


Reply via email or office hours