Exemplo n.º 1
0

import argparse
import sys

# Configure and consume command line arguments.
ap = argparse.ArgumentParser(description='This script adds your Safari Reading List articles to Pocket.')
ap.add_argument('-v', '--verbose', action='store_true', help='Print article URLs as they are added.')
args = ap.parse_args()

# Initialize Pocket API
pocket = Pocket()

if pocket.is_authed() is False:
    print 'You need to authorize this script through Pocket before using it'
    print 'Follow these steps:'
    pocket.auth()

# Get the Reading List items
rlr = ReadingListReader()
articles = rlr.read(show="unread")

for article in articles:
    (add_status, add_message) = pocket.add_item(article['url'].encode('utf-8'), title=article['title'].encode('utf-8'), tags='reading_list')
    if 200 == add_status:
        if args.verbose:
            print article['url'].encode('utf-8')
    else:
        print >> sys.stderr, add_message
        ap.exit(-1)
ap.add_argument(
    "--syncdate",
    action="store",
    default=None,
    help="Sync links on or after a desired date. Defaults to 1970-01-01 00:00:00",
)
args = ap.parse_args()

# Reinterpretation of fiddly options
if "tab" == args.separator:
    args.separator = "\t"

# Input
if not os.path.exists(args.input):
    raise SystemExit, "The input file does not exist: %s" % args.input
rlr = ReadingListReader(args.input)

bookmarks = rlr.read(
    show=None if "all" == args.show else args.show,
    sortfield=args.sortfield,
    ascending=True if "ascending" == args.sortorder else False,
    dateformat=args.timestamp,
    syncdate=args.syncdate,
)

if args.bookmarks:

    # Netscape Bookmarks File formatted output
    # eg http://msdn.microsoft.com/en-us/library/ie/aa753582(v=vs.85).aspx

    print >>args.output, '<!DOCTYPE NETSCAPE-Bookmark-file-1>\n<HTML>\n<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-8">\n<Title>Bookmarks</Title>\n<H1>Bookmarks</H1>\n<DT><H3 FOLDED>Reading List Bookmarks</H3>\n<DL>'
Exemplo n.º 3
0
#!/usr/bin/python

from readinglistlib import ReadingListReader

rlr = ReadingListReader()
bookmarks = rlr.read(ascending=False)

print '<!DOCTYPE html><html><head><meta charset="utf-8"><title>Reading List</title></head><body><h1>Reading List</h1><ul>'

for bookmark in bookmarks:
    print '<li><p><a href="%(url)s">%(title)s</a><br />%(url)s</p><blockquote>%(preview)s</blockquote></li>' % {
        'url': bookmark['url'].encode('utf-8'),
        'title': bookmark['title'].encode('utf-8'),
        'preview': bookmark['preview'].encode('utf-8')
    }

print '</ul></body></html>'
Exemplo n.º 4
0
ap.add_argument(
    '--syncdate',
    action='store',
    default=None,
    help=
    'Sync links on or after a desired date. Defaults to 1970-01-01 00:00:00')
args = ap.parse_args()

# Reinterpretation of fiddly options
if 'tab' == args.separator:
    args.separator = '\t'

# Input
if not os.path.exists(args.input):
    raise SystemExit, "The input file does not exist: %s" % args.input
rlr = ReadingListReader(args.input)

bookmarks = rlr.read(
    show=None if 'all' == args.show else args.show,
    sortfield=args.sortfield,
    ascending=True if 'ascending' == args.sortorder else False,
    dateformat=args.timestamp,
    syncdate=args.syncdate)

if args.bookmarks:

    # Netscape Bookmarks File formatted output
    # eg http://msdn.microsoft.com/en-us/library/ie/aa753582(v=vs.85).aspx

    print >> args.output, '<!DOCTYPE NETSCAPE-Bookmark-file-1>\n<HTML>\n<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=UTF-8">\n<Title>Bookmarks</Title>\n<H1>Bookmarks</H1>\n<DT><H3 FOLDED>Reading List Bookmarks</H3>\n<DL>'
    for bookmark in bookmarks:
lastsyncdate = lastsyncdateFile.readline()
print 'Using %s as the subsequent syncronized date.' % lastsyncdate

# Log in to the Instapaper API.
instapaper = Instapaper(args.username, args.password)
(auth_status, auth_message) = instapaper.auth()

# 200: OK
# 403: Invalid username or password.
# 500: The service encountered an error.
if 200 != auth_status:
    print >> sys.stderr, auth_message
    ap.exit(-1)

# Get the Reading List items
rlr = ReadingListReader()
articles = rlr.read(show=all, syncdate=args.syncdate)

for article in articles:

    (add_status, add_message) = instapaper.add_item(
        article['url'].encode('utf-8'),
        title=article['title'].encode('utf-8'),
        selection=article['preview'].encode('utf-8'))

    # 201: Added
    # 400: Rejected (malformed request or exceeded rate limit; probably missing a parameter)
    # 403: Invalid username or password; in most cases probably should have been caught above.
    # 500: The service encountered an error.
    if 201 == add_status:
        if args.verbose:
Exemplo n.º 6
0
#!/usr/bin/env python
"""
Dumps the entire Safari Reading List into a CSV file for use in other ways. Kind of a master reset button."""

from readinglistlib import ReadingListReader
import csv

r = ReadingListReader()
articles = r.read()

with open('reading_list_dump.csv', 'wb') as csvfile:
    cwriter = csv.writer(csvfile,
                         delimiter=" ",
                         quotechar="|",
                         quoting=csv.QUOTE_MINIMAL)
    fieldnames = ['title', 'url', 'added', 'viewed']
    hwriter = csv.DictWriter(csvfile, fieldnames=fieldnames, dialect='excel')
    hwriter.writeheader()
    for a in articles:
        try:
            w = {
                'title': a['title'],
                'url': a['url'],
                'added': a['added'],
                'viewed': a['viewed']
            }
            hwriter.writerow(w)
        except UnicodeEncodeError:
            print "Couldnt save %s" % a['url']
#!/usr/bin/env python

# This script posts items from your Reading List to your Pinboard account as
# bookmarks marked 'to read'. Learn about Pinboard at https://pinboard.in/tour/

from readinglistlib import ReadingListReader
import urllib

#
# Find your Pinboard API Token at https://pinboard.in/settings/password
# It will look something like apitoken = 'username:5CABE73682AAA9856010'
#
auth_token = '';
api_url = 'https://api.pinboard.in/v1/posts/add?'

rlr = ReadingListReader()
bookmarks = rlr.read()
for bookmark in bookmarks:
  params = urllib.urlencode({
			'url': bookmark['url'],
			'description': bookmark['title'],
			'extended': bookmark['preview'],
			'toread': 'yes',
			'auth_token': auth_token})
	urllib.urlopen(api_url + params)
	# validation of response result_code is left as an exercise for the reader
Exemplo n.º 8
0
#!/usr/bin/python

from readinglistlib import ReadingListReader

rlr = ReadingListReader()
bookmarks = rlr.read(ascending=False)

print '<!DOCTYPE html><html><head><meta charset="utf-8"><title>Reading List</title></head><body><h1>Reading List</h1><ul>'

for bookmark in bookmarks:
	print '<li><p><a href="%(url)s">%(title)s</a><br />%(url)s</p><blockquote>%(preview)s</blockquote></li>' % {'url': bookmark['url'].encode('utf-8'), 'title': bookmark['title'].encode('utf-8'), 'preview': bookmark['preview'].encode('utf-8')}

print '</ul></body></html>'
lastsyncdate = lastsyncdateFile.readline()
print 'Using %s as the subsequent syncronized date.' % lastsyncdate

# Log in to the Instapaper API.
instapaper = Instapaper(args.username, args.password)
(auth_status, auth_message) = instapaper.auth()

# 200: OK
# 403: Invalid username or password.
# 500: The service encountered an error.
if 200 != auth_status:
	print >> sys.stderr, auth_message
	ap.exit(-1)

# Get the Reading List items
rlr = ReadingListReader()
articles = rlr.read(
		show = all,
		syncdate = args.syncdate)

for article in articles:

	(add_status, add_message) = instapaper.add_item(article['url'].encode('utf-8'), title=article['title'].encode('utf-8'), selection=article['preview'].encode('utf-8'))
	
	# 201: Added
	# 400: Rejected (malformed request or exceeded rate limit; probably missing a parameter)
	# 403: Invalid username or password; in most cases probably should have been caught above.
	# 500: The service encountered an error.
	if 201 == add_status:
		if args.verbose:
			print article['url'].encode('utf-8')
Exemplo n.º 10
0
#!/usr/bin/env python
"""
Dumps the entire Safari Reading List into a CSV file for use in other ways. Kind of a master reset button."""

from readinglistlib import ReadingListReader
import csv


r = ReadingListReader()
articles = r.read()

with open('reading_list_dump.csv', 'wb') as csvfile:
    cwriter = csv.writer(csvfile, delimiter=" ", quotechar="|", quoting=csv.QUOTE_MINIMAL)
    fieldnames = ['title', 'url', 'added', 'viewed']
    hwriter = csv.DictWriter(csvfile, fieldnames=fieldnames, dialect='excel')
    hwriter.writeheader()
    for a in articles:
        try:
            w = {
                'title': a['title'],
                'url': a['url'],
                'added': a['added'],
                'viewed': a['viewed']
            }
            hwriter.writerow(w)
        except UnicodeEncodeError:
            print "Couldnt save %s" % a['url']
Exemplo n.º 11
0
# Configure and consume command line arguments.
ap = argparse.ArgumentParser(
    description='This script adds your Safari Reading List articles to Pocket.'
)
ap.add_argument('-v',
                '--verbose',
                action='store_true',
                help='Print article URLs as they are added.')
args = ap.parse_args()

consumer_key = ""  # Insert your consumer key here (https://getpocket.com/developer/apps/)
redirect_uri = ""  # TODO: Currently obselete/phishing threat in this version

# Manually trigger pocket authentication
access_token = Pocket.auth(consumer_key=consumer_key,
                           redirect_uri=redirect_uri)
pocket_instance = Pocket(consumer_key, access_token)

# Get the Reading List items
rlr = ReadingListReader()
articles = rlr.read(show="unread")

for article in articles:
    print pocket_instance.bulk_add(url=article['url'].encode('utf-8'),
                                   tags='reading_list')
    print "Added:", article['url']

# commit bulk_add changes
pocket_instance.commit()
Exemplo n.º 12
0
__FILENAME__ = readinglist2csv
#!/usr/bin/env python
"""
Dumps the entire Safari Reading List into a CSV file for use in other ways. Kind of a master reset button."""

from readinglistlib import ReadingListReader
import csv


r = ReadingListReader()
articles = r.read()

with open('reading_list_dump.csv', 'wb') as csvfile:
    cwriter = csv.writer(csvfile, delimiter=" ", quotechar="|", quoting=csv.QUOTE_MINIMAL)
    fieldnames = ['title', 'url', 'added', 'viewed']
    hwriter = csv.DictWriter(csvfile, fieldnames=fieldnames, dialect='excel')
    hwriter.writeheader()
    for a in articles:
        try:
            w = {
                'title': a['title'],
                'url': a['url'],
                'added': a['added'],
                'viewed': a['viewed']
            }
            hwriter.writerow(w)
        except UnicodeEncodeError:
            print "Couldnt save %s" % a['url']

########NEW FILE########
__FILENAME__ = readinglist2html
	except IOError:
		ap.error('Please specify a username with -u/--username.')

# Log in to the Instapaper API.
instapaper = Instapaper(args.username, args.password)
(auth_status, auth_message) = instapaper.auth()

# 200: OK
# 403: Invalid username or password.
# 500: The service encountered an error.
if 200 != auth_status:
	print >> sys.stderr, auth_message
	ap.exit(-1)

# Get the Reading List items
rlr = ReadingListReader()
articles = rlr.read()

for article in articles:

	(add_status, add_message) = instapaper.add_item(article['url'].encode('utf-8'), title=article['title'].encode('utf-8'))
	
	# 201: Added
	# 400: Rejected (malformed request or exceeded rate limit; probably missing a parameter)
	# 403: Invalid username or password; in most cases probably should have been caught above.
	# 500: The service encountered an error.
	if 201 == add_status:
		if args.verbose:
			print article['url'].encode('utf-8')
	else:
		print >> sys.stderr, add_message