Skip to content

Instantly share code, notes, and snippets.

@drikin
Created January 21, 2016 23:52
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 drikin/9beefc8b0882cda36ddb to your computer and use it in GitHub Desktop.
Save drikin/9beefc8b0882cda36ddb to your computer and use it in GitHub Desktop.
Link2Markdown.py
# 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