Python

Embedding robots.txt in WAV files

tl;dr: you can embed a robots.txt file into an audio file, and it can be both a valid robots.txt and a valid audio file. The robots.txt standard has a nifty feature: it will ignore anything that it doesn’t understand. Random text, ASCII art, and even other data can be added without making the robots.txt file invalid. You could do something simple. Roses are red Violets are blue user-agent: Googlebot disallow: /foo Or do something weird.

Midjourney / Discord to Lightroom automation - step by step - for 2023

Midjourney is fun, but the Discord-based interface is somewhat annoying, if you want to make a lot of images. To get all the images you generate, you have to upscale all 2x2 previews, and save them manually. It can get pretty tiring, so instead of making better images, I spent a bit of time to automate the download and import process. With this code, a Discord bot will monitor your server, watch for Midjourney messages, process all images, and upload them to your Lightroom CC cloud account. Run the script anywhere, a Raspberry Pi or a cheap cloud server, and keep making images.

A python curls up to touch the tip of its own tail with its nose, forming the shape of a circle.

A python curls up to touch the tip of its own tail with its nose, forming the shape of a circle. The python is 2.6 pi (2.6Ï€) meters long. What is the radius r of the circle that the python forms? – Obviously, this is not about the programming language. Someone was searching for this, well, lots of people were, so why not answer it? Snakes are scary. Instead of thinking of it as a snake, assume it’s just the circumference of a circle - the length of the line that draws the circle. Let’s find some formulas that connect the circumference with the radius!

Add rows to a Google Spreadsheet with Python, without API - for 2023

Sometimes it’s a hassle to track auth data for the Google Spreadsheet API. Here’s a quick hack using Google Forms to post data to a Spreadsheet (similar to the previous post that uses Curl). You can use it as a function in your code, or as a simple command-line tool. Note: updated in 2023 to support new Google Forms HTML. Gist (archive.org) #!/usr/bin/python """Posts to a Google Sheet using a Form""" import re import sys import urllib import urllib2 def get_field_ids(form_url): """Returns list of field IDs on the form.""" response = urllib2.urlopen(form_url) html = response.read() form_field_info = re.findall('(<input|<textarea)[^>]*id="([^"]*)"', html) if form_field_info: # depends on UI version fields = [x[1] for x in form_field_info if x[1].startswith("entry")] else: form_field_info = re.findall('\[\[([0-9]{3,30}),null,0\]\]', html) fields = ["entry."+x for x in form_field_info] fields = [x[1] for x in form_field_info if x[1].startswith("entry")] return fields def post_form_values(form_url, submit_values): """Posts list of values to the form.""" fields = get_field_ids(form_url) # these could be cached too. submit_url = form_url.replace("/viewform", "/formResponse") values = {} for counter in range(0, min(len(submit_values), len(fields))): values[fields[counter]] = submit_values[counter] data = urllib.urlencode(values) req = urllib2.Request(submit_url, data) response = urllib2.urlopen(req) the_page = response.read() # ignore response def main(): """Command-line usage possible too!""" if len(sys.argv)<3: print "Expected: form_url value1 [value2 ...]" return form_url = sys.argv[1] values = sys.argv[2:] post_form_values(form_url, values) if __name__ == "__main__": main()

How to use Google webmaster tools stats with Excel

Google’s webmaster tools (archive.org) has a neat feature that lets you download your query and click statistics (once you have verified ownership of your site). The data you can get from there is quite comprehensive, but hard to break down for use in Excel. As a fun exercise I put together a small Python-script that takes the CSV file downloaded from your webmaster tools account and turns it into new CSV files for queries and for clicks (both with the position numbers as well).