Skip to content

Instantly share code, notes, and snippets.

@benaryorg
Created October 8, 2020 14:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benaryorg/bc5dafd58e31c9b7ff0a9ae87bce084c to your computer and use it in GitHub Desktop.
Save benaryorg/bc5dafd58e31c9b7ff0a9ae87bce084c to your computer and use it in GitHub Desktop.

How to use?

Call the script with .eml files as parameters and it'll print all the Patreon links on stdout, separated by newlines. On stderr it will print all the files which did not contain links to posts, e.g. direct message notifications from content creators.

If you want to read all your unread patreon posts without having to scroll down too far (which is really awful on patreon.com), you could save all your unread emails (e.g. in Thunderbird, note: in Thunderbird this will mark them as read) to a directory and then do that:

./this_script.py *.eml | xargs -n 1 xdg-open

If you're using Firefox (any version since Quantum, so pretty much anything from the past two years or so) even as much as 200 tabs will keep a semi-low memory profile (3-4G for me).

#!/usr/bin/env python
import email
import email.parser
import email.policy
import sys
import re
REGEX=re.compile(r'https://www\.patreon\.com/posts/[-a-z0-9]+\?')
links = set()
no_matches = set()
for filename in sys.argv[1:]:
with open(filename,"rb") as f:
message = email.parser.BytesParser(policy=email.policy.default).parse(f)
body = message.get_body("text/plain")
matches = REGEX.findall(body.get_content())
if len(matches) < 1:
no_matches.add(filename)
else:
for match in matches:
links.add(match[:-1])
for link in links:
print(link)
if no_matches:
print("no matches found in following files:",file=sys.stderr)
for filename in no_matches:
print(filename,file=sys.stderr)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment