Created
June 11, 2017 16:46
-
-
Save pkillnine/89536c1d627901cf023bc1c268e3de44 to your computer and use it in GitHub Desktop.
prototype url rewriter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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