Skip to content

Instantly share code, notes, and snippets.

@beyondliu
Created March 29, 2017 02:10
Show Gist options
  • Save beyondliu/45fd4b8db520b925b0442ebb7976c8e9 to your computer and use it in GitHub Desktop.
Save beyondliu/45fd4b8db520b925b0442ebb7976c8e9 to your computer and use it in GitHub Desktop.
add_scrap.py
import appex
import webbrowser
import urllib
from bs4 import BeautifulSoup
def main():
if not appex.is_running_extension():
print('Running in Pythonista app, using test data...\n')
url = 'http://example.com'
else:
url = appex.get_url()
if url:
print('Input URL: %s' % (url,))
print('\nAdding scrap......\n')
soup = BeautifulSoup(urllib.urlopen(url))
title = u''+soup.title.string
success = webbrowser.open('http://3exps.org/user/scrapbook/scraps/addScrap/?url='+urllib.quote_plus(url)+'&title='+urllib.quote_plus(title.encode('utf8')),modal=True)
if success:
console.alert('Scrap created successfully!', button1='Ok', hide_cancel_button=True)
else:
console.alert('Error creating scrap!', button1='Ok', hide_cancel_button=True)
else:
print('No input URL found.')
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment