I'm hooking my solar panels up to Twitter! Installation Inverter Fronius provide a comprehensive API guide - I wish more companies did this. There are lots of unofficial libraries in a variety of different languages. I've written this code in Python3. This is a general tidy-up of the code I wrote several years ago. Here's how it works.... Every minute, the script runs from crontab. If it is after sunrise and before sunset, it takes a reading and writes it to today's CSV file. If it is…
Continue reading →
I write book reviews on my blog. I also want to syndicate them to Goodreads. Sadly, Goodreads doesn't natively read the Schema.org markup I so carefully craft. So here's the scrap of code I use to syndicate my reviews. Goodreads API Keys Get your Keys from https://www.goodreads.com/api/keys You will also need to get OAuth tokens For this documentation, I'll use the example keys - please substitute them with your own keys. from rauth.service import OAuth1Service, OAuth1Session # Get a…
Continue reading →
This is a quick and dirty way to turn a DOI (Digital Object Identifiers for academic papers) into an HTML & Microdata citation. I use this to power my Citations page. Schema.org is a Microdata standard which allows machines to read your HTML and create semantic relations between documents. Here's a minimum viable citation: <blockquote itemprop="citation" itemscope itemtype="http://schema.org/ScholarlyArticle"> <span itemprop="author" itemscope itemtype="http://schema.org/Person"> …
Continue reading →
One of my favourite works of art is The Great Bear by Simon Patterson. At first glance, it appears to be a normal London Tube map. But look closer... Cool! But there is something about it which has always bothered me. Each Tube line represents a theme - therefore, a station at the intersection of multiple lines should be represented by someone who matches all of those themes. For example, here's Baron's Court - the intersection of the Explorer line and the Saint line - represented by…
Continue reading →
Amazon encourages developers to use Flask-Ask - the handy Python library for working with Alexa. Sadly, the project has been abandoned. They no longer take pull requests, you can't raise bugs against it, and the documentation is incomplete. So this is how I solved an annoying problem - how to get the name of a custom slot. Here's the code, with a fuller explanation afterwards. from flask import Flask, render_template, request from flask_ask import Ask, statement, question, session app =…
Continue reading →
I rate every pint I taste using the Untappd app. Think of it like TripAdvisor for lager, stout, cider, bitter, and all manner of other beery goodness. Seriously, I've reviewed over 600 different drinks Recently, I decided to see if I could self-host my beer check-ins. The first step - extracting my own data from Untappd. Pay To Play If you become an Untappd Supporter for US$5 per month, you can extract your data in CSV or JSON. I feel like I ought to be able to GDPR that and get it for…
Continue reading →
I want to convert YouTube's auto-generated subtitles into a plain transcript. Why is this so hard? This blog post gives a more detailed explanation than my answer to this StackOverflow question. Here's what the subtitles look like when you view a video: And here's what the code which generates those subtitles looks like: 00:00:00.930 --> 00:00:03.080 align:start position:0% and<00:00:01.230><c> now</c><00:00:01.439><c> can</c><00:00:01.709><c> we</c><00:00:01.800><c>…
Continue reading →
Here's an interesting conundrum. My TV can automatically detect when 3D video is being played and offers to switch into 3D mode - but how does the detection work? This post will give you a few strategies for detecting 3D images using Python. Firstly, some terminology. 3D videos are usually saved either as Side-By-Side images, or Over-Under images. Colloquially known as H-SBS and H-OU. Here's an example. SBS OU Metadata? My first thought was that 3D video may contain metadata which…
Continue reading →
A quick tutorial in how to recover 3D information from your favourite 3D movies. In this example, we'll be using Star Wars - The Last Jedi. tl;dr? Here's the end result (this video is silent): https://shkspr.mobi/blog/wp-content/uploads/2018/04/walker-text.mp4 Grab the code on GitHub. Let's go! Take a screenshot of your favourite scene. Something with a clearly defined foreground and background. The brighter the image the better the results. Split the image in two: mogrify -crop…
Continue reading →
As ever, mostly notes to myself. I have a bunch of old images which don't have any timestamp associated with them. This quick Python script will add a DateTime EXIF metadata tag to an image. This uses piexif which can be installed using pip install piexif This simple script reads a photo, adds a timestamp, then saves a copy of the new photo. from PIL import Image from PIL.ExifTags import TAGS import piexif from datetime import datetime im = Image.open("test.jpg") exif_dict =…
Continue reading →
I read a Guardian article about an artist who set up an analogue camera in front of their TV, set it to long exposure, and set a movie playing. The result was a rather wonderful collection of images. You can see more of Jason Shulman's works Is there a way to automate this process? Yes! Here's my attempt at a "Long Exposure" of "Taxi Driver". It's not the same as Shulmans's process, but I think it is rather charming. Here's a timelapse of how it was constructed. I experimented with …
Continue reading →
I've grown to loath IFTTT. What started out as a cool way to plug internet things together has being an opaque an uncommunicative company with no real interest in customer service. That's not surprising, I suppose, its paying customers are the companies who can't be bothered to develop a proper API and so just shove some integrations up there. But it is annoying for those of us who want something simple - like debug logs or notifications when scripts fail. Or something complex like conditional …
Continue reading →