Skip to content

Instantly share code, notes, and snippets.

View alexwlchan's full-sized avatar

Alex Chan alexwlchan

View GitHub Profile
@alexwlchan
alexwlchan / flickypedia_bot_minimal_example.py
Last active April 10, 2024 11:45
Flickypedia bot help question
import json
import httpx
import keyring
# 1. Retrieve the Wikimedia API token from the system keychain
api_token = keyring.get_password("flickypedia_backfillr_bot", "api_token")
# 2. Create an HTTP client
client = httpx.Client(
@alexwlchan
alexwlchan / README.md
Created December 10, 2015 08:33
drangReader – Python scripts for a simple RSS reader

drangreader

This is a set of scripts for aggregating RSS feeds. It's based on a script originally written by Dr. Drang: http://leancrew.com/all-this/2015/11/simpler-syndication/

Installation

Download all the files from this Gist. Put them all in a directory, create a virtualenv and install requirements:

@alexwlchan
alexwlchan / safeutil.py
Last active July 18, 2023 07:39
Non-destructive file copying/moving in Python
#!/usr/bin/env python
"""
This is a script designed to be "safe" drop-in replacements for the
shutil move() and copyfile() functions.
These functions are safe because they should never overwrite an
existing file. In particular, if you try to move/copy to dst and
there's already a file at dst, these functions will attempt to copy to
a slightly different (but free) filename, to avoid accidental data loss.
@alexwlchan
alexwlchan / finduntaggedposts.py
Last active July 5, 2022 01:18
A Python script for finding untagged posts on Tumblr. See http://alexwlchan.net/2013/08/untagged-tumblr-posts/
#!/usr/bin/env python
import urllib2
import json
HOSTNAME = "example.tumblr.com"
API_KEY = "abcdefg"
URL = "http://api.tumblr.com/v2/blog/{host}/posts?api_key={key}".format(host=HOSTNAME, key=API_KEY)
@alexwlchan
alexwlchan / elapsed.py
Created December 22, 2014 20:36
Prints human-readable, friendly strings to measure elapsed time
#!/usr/bin/python
"""elapsed.py - a script for providing a human-readable string of how much time
has elapsed since a given date, implemented only using the standard library.
Modelled on the style of dates used on Stack Overflow posts.
"""
from datetime import datetime, timedelta
def print_date(date, incl_year=True, short_months=True):
"""Prints a datetime object as a full date, stripping off any leading
@alexwlchan
alexwlchan / example.tfstate.step1
Last active October 27, 2021 06:59
Terraform bug repro information
{
"version": 4,
"terraform_version": "1.0.9",
"serial": 1,
"lineage": "693cb572-091c-756e-8b64-65f51416d352",
"outputs": {},
"resources": [
{
"mode": "managed",
"type": "aws_s3_bucket",
@alexwlchan
alexwlchan / myurlparse.py
Created August 30, 2016 20:33
Helper functions for dealing with query strings in URLs
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
Utility functions for dealing with URL query strings in Python,
i.e., URLs of the form
http://example.net?field1=value1&field2=value2
This module includes a pair of helper functions: one for getting the values
associated with a particular field; another for setting the query string
@alexwlchan
alexwlchan / Screenshot 2019-09-22 at 18.04.32.png
Last active September 22, 2019 17:06
Script for an Alfred shortcut to open PyPI docs
Screenshot 2019-09-22 at 18.04.32.png
@alexwlchan
alexwlchan / keybase.md
Created October 12, 2017 13:42
keybase.md

Keybase proof

I hereby claim:

  • I am alexwlchan on github.
  • I am alexwlchan (https://keybase.io/alexwlchan) on keybase.
  • I have a public key whose fingerprint is 82FE A59D 07EE 6274 20D7 E85D F859 A49F A148 6C23

To claim this, I am signing this object:

#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""I have a TaskPaper file I keep in Dropbox that contains some tasks for my
daily routine.
This script runs once a day and resets every item on that list, removing
the @done tag and replacing the file.
"""