Skip to content

Instantly share code, notes, and snippets.

@pkillnine
Created June 11, 2017 16:46
Show Gist options
  • Save pkillnine/89536c1d627901cf023bc1c268e3de44 to your computer and use it in GitHub Desktop.
Save pkillnine/89536c1d627901cf023bc1c268e3de44 to your computer and use it in GitHub Desktop.
prototype url rewriter
#!/usr/bin/env python
import re
import urllib.parse
from os import environ
from sys import argv
url = environ['QUTE_URL']
fifo_path = environ['QUTE_FIFO']
if 'l.facebook.com' in url:
regex = 'https:\/\/l\.facebook\.com\/l\.php\?u\=(?P<actual_url>.+)\&h\='
with open(fifo_path, 'w') as f:
f.write("message-info 'l.facebook.com detected'\n")
unquoted_url = urllib.parse.unquote(url)
converted_url = re.match(regex, unquoted_url).groupdict()['actual_url']
#need to remove &h= cos it's a code facebook assigns.
f.write("open --implicit {}\n".format(converted_url))
else:
with open(fifo_path, 'w') as f:
f.write("open --implicit {}\n".format(url))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment