Skip to content

Instantly share code, notes, and snippets.

Avatar

Alex Chan alexwlchan

View GitHub Profile
@alexwlchan
alexwlchan / settern_rss.py
Created Feb 14, 2016
Python script for creating a per-author RSS feed from iMore
View settern_rss.py
#!/usr/bin/env python
"""
This script can be used to get a per-author RSS feed on iMore.com. It will try to
cache the entries, so the last 40 entries from an author will show up, even if
they're no longer in the main feed.
To invoke, just call this script at the command line:
python settern_rss.py
@alexwlchan
alexwlchan / spoilerrific.js
Last active Jan 8, 2016
Opt-in to spoilers on SFF.SE questions with particular tags
View spoilerrific.js
// ==UserScript==
// @name SFF.SE Show spoilers on questions with particular tags
// @namespace http://tampermonkey.net/
// @version 1.0
// @description Show all spoilers on SFF.SE questions with specified tags
// @author alexwlchan
// @match *://scifi.stackexchange.com/questions/*
// @match *://meta.scifi.stackexchange.com/questions/*
// @grant none
// ==/UserScript==
@alexwlchan
alexwlchan / README.md
Created Dec 10, 2015
drangReader – Python scripts for a simple RSS reader
View README.md

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 / finduntaggedposts.py
Last active Mar 13, 2017
A Python script for finding untagged posts on Tumblr. See http://alexwlchan.net/2013/08/untagged-tumblr-posts/
View finduntaggedposts.py
#!/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 / safeutil.py
Last active Dec 3, 2020
Non-destructive file copying/moving in Python
View safeutil.py
#!/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 / parse_healthkit.py
Created May 26, 2015
A script for making the XML exports from the iOS Health app more human-friendly
View parse_healthkit.py
#!/usr/bin/env python
"""
A quick script for tidying up data from the HealthKit export file.
To get an export file:
1) Open the Health app on iOS
2) Under "Health Data", select "All"
3) Use the share button to get a copy of your data in XML format
This script allows you to get data for one particular value, and turn it into
@alexwlchan
alexwlchan / elapsed.py
Created Dec 22, 2014
Prints human-readable, friendly strings to measure elapsed time
View elapsed.py
#!/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 / acronyms.py
Last active Aug 29, 2015
A command-line tool for managing acronyms
View acronyms.py
#!/usr/bin/python
"""A script for managing a dictionary of acronyms. For context, see the
associated blog post: http://alexwlchan.net/2014/12/acronyms/
Invoke with the -h or --help flag for a usage message:
$ ./acronyms.py -h
Invoke with the -a or --add flag to add an acronym:
@alexwlchan
alexwlchan / curlparser.py
Created Nov 2, 2014
Unpack sets and ranges expressed in a string, using cURL syntax for multiple URLs
View curlparser.py
"""The cURL command line tool allows you to specify multiple URLs in a
single string. For example:
http://site.{one,two,three}.com
ftp://ftp.numericals.com/file[1-100].txt
ftp://ftp.numericals.com/file[001-100].txt (with leading zeros)
ftp://ftp.letters.com/file[a-z].txt
This module can take a string in this format, and return the list of strings
that it specifies. The exact syntax can be seen in the examples on the cURL man
@alexwlchan
alexwlchan / organize-photos.py
Last active Jan 2, 2016 — forked from cliss/organize-photos.py
My fork of @cliss’s photo management script. Tweaked to: * Get date from `os.path.getmtime(f)` (lifted from @jdmonaco’s fork) * Sort any format with a three-character extension (currently .JPG, .TIF, .PNG and .MOV). Edit the list in line 40 for more formats. It also normalises extensions to lowercase. * Tweaked some bits of the code * Moves file…
View organize-photos.py
#!/usr/bin/python
import sys
import os, shutil
import subprocess
import os.path
from datetime import datetime
######################## Functions #########################