Created
January 21, 2016 23:52
-
-
Save drikin/9beefc8b0882cda36ddb to your computer and use it in GitHub Desktop.
Link2Markdown.py
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
# coding: utf-8 | |
import appex, clipboard, urllib2, re, cookielib | |
def main(): | |
if not appex.is_running_extension(): | |
print 'This script is intended to be run from the sharing extension.' | |
return | |
url = appex.get_url() | |
if not url: | |
print 'No URL found.' | |
return | |
header = {'User-Agent':'Mozilla/5.0'} | |
request = urllib2.Request(url ,headers=header) | |
response = urllib2.urlopen(request) | |
html = response.read() | |
regex = re.compile('<title>(.*?)</title>', re.IGNORECASE|re.DOTALL) | |
title = regex.search(html).group(1).lstrip().rstrip() | |
text = '- [' + title + '](' + url +')\n' | |
print(text) | |
clipboard.set(text) | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment