Exemplo n.º 1
0
def add_todays_entries(feed_title, entries):
    i = Instapaper(USERNAME, PASSWORD)
    
    for e in entries:
        pubdate = date.fromtimestamp(time.mktime(e.updated_parsed))
        if pubdate == date.today():
            title = u"{0} - {1}".format(e.title, feed_title)
            link = e.link
            ret = i.add_item(link, title, response_info=True)
            (statuscode, statusmessage, title, location) = ret
            logger.info("{0} :: {1}".format(title, statusmessage))
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
        ap.exit(-1)
(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')
    else:
        print >> sys.stderr, add_message
        ap.exit(-1)
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')
	else:
		print >> sys.stderr, add_message
		ap.exit(-1)
Exemplo n.º 5
0
}

print "Launching redis to instapaper component"

# take config items from environment where present
for configitem in config:
    if configitem in os.environ:
        config[configitem] = os.environ[configitem]

i = Instapaper(config['USERNAME'], config['PASSWORD'])

try:
    red = redis.StrictRedis("redis")
    red_pubsub = red.pubsub()
    red_pubsub.subscribe(config['CHANNEL'])
except:
    print "Failed to subscribe to channel"

try:
    while True:
        for item in red_pubsub.listen():
            if (str(item['data']).lower().split(":")[0] in ['http', 'https']) and validators.url(item['data']):
                print "Adding item: " , item['data']
                (statuscode, statusmessage) = i.add_item(item['data'])
                print "Instapaper response: ", statuscode, statusmessage
            else:
                print "Bad data: ", item['data']
except Exception as e:
    print traceback.format_exc()

Exemplo n.º 6
0
class Instayc:

    section = 'instayc'

    def __init__(self):
        self.insta = None
        self.config = self.loadConfig()

    def loadConfig(self):
        config = SafeConfigParser()
        filename = OPTIONS.get('config_filename')

        if os.path.exists(filename):
            config.read(filename)
        else:
            with open(filename, 'wb') as configfile:
                config.add_section(self.section)
                config.set(self.section, 'interests', '')
                config.write(configfile)
        return config

    def saveConfig(self):
        with open(OPTIONS.get('config_filename'), 'wb') as configfile:
            self.config.write(configfile)

    def requires_login(fn):
        def wrapped(self):
            try:
                self.authorize(self.config.get(self.section, 'email'),
                    self.config.get(self.section, 'password'))
            except NoOptionError:
                self.login()
            fn(self)
        return wrapped

    def authorize(self, email, password):
        self.insta = Instapaper(email , password)
        (code, message) = self.insta.auth()
        if code == 403:
            self.login()
        else:
            self.config.set(self.section, 'email', email)
            self.config.set(self.section, 'password', password)
            self.saveConfig()

    def login(self):
        email = raw_input('Instapaper email: ')
        password = getpass('Instapaper password: '******'interests')
        if current_interests == '':
            current_interests = interests
        else:
            current_interests = current_interests + ', ' + interests
        self.config.set(self.section, 'interests', current_interests)
        self.saveConfig()

    @requires_login
    def update(self):
        print "Updating..."
        posts = parse(OPTIONS['feeds']['yc']).entries
        interests = self.config.get(self.section, 'interests').split(',')

        def map(words):
            mapping = []
            for word in words:
                mapping.append((word.strip(), 1))
            return mapping

        def reduce(mapping):
            counted = {}
            for word, count in mapping:
                counted[word] = counted.get(word, 0) + count
            return counted

        found = []
        for post in posts:
            title = str(post['title'].encode('utf-8'))
            title_words = [word.lower() for word in title.split(' ')]
            title_words.extend(interests)
            counted = reduce(map(title_words))
            matches = [word for word, count in counted.items() if count > 1]
            if matches:
                found.append((post['link'], title))
                self.insta.add_item(post['link'], title)
        print "Added %d article(s) to Instapaper: \n" % len(found)
        for link, title in found:
            print title
        print ''
Exemplo n.º 7
0
f = open(HN_TWITTER + '.txt', 'a+') # so that it will create if file does not exist
f.close()
f = open(HN_TWITTER + '.txt', 'r+')
last_id = f.readline()

# GetUserTimeline(self, user_id=None, screen_name=None, since_id=None, max_id=None,
#                 count=None, include_rts=True, trim_user=None, exclude_replies=None)
statuses = api.GetUserTimeline(screen_name=HN_TWITTER, since_id=last_id, count=200)

if len(statuses) > 0:
    # Instapaper Library
    i = Instapaper(INSTAPAPER_UN, INSTAPAPER_PW)

    expander = URLExpander()

    urls = getUrls(statuses)
    urls = filterUrls(urls)

    for url in urls:
        print "added to Instapaper:", url
        i.add_item(url, '')

    # Log latest tweet
    f.seek(0, 0)
    f.write(str(statuses[0].id))

else:
    print "No new tweets since this script was last run."

f.close()
Exemplo n.º 8
0
(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
		ap.exit(-1)

########NEW FILE########
__FILENAME__ = readinglist2pinboard
#!/usr/bin/env python
Exemplo n.º 9
0
class Instayc:

    section = "instayc"

    def __init__(self):
        self.insta = None
        self.config = self.loadConfig()

    def loadConfig(self):
        config = SafeConfigParser()
        filename = OPTIONS.get("config_filename")

        if os.path.exists(filename):
            config.read(filename)
        else:
            with open(filename, "wb") as configfile:
                config.add_section(self.section)
                config.set(self.section, "interests", "")
                config.write(configfile)
        return config

    def saveConfig(self):
        with open(OPTIONS.get("config_filename"), "wb") as configfile:
            self.config.write(configfile)

    def requires_login(fn):
        def wrapped(self):
            try:
                self.authorize(self.config.get(self.section, "email"), self.config.get(self.section, "password"))
            except NoOptionError:
                self.login()
            fn(self)

        return wrapped

    def authorize(self, email, password):
        self.insta = Instapaper(email, password)
        (code, message) = self.insta.auth()
        if code == 403:
            self.login()
        else:
            self.config.set(self.section, "email", email)
            self.config.set(self.section, "password", password)
            self.saveConfig()

    def login(self):
        email = raw_input("Instapaper email: ")
        password = getpass("Instapaper password: "******"interests")
        if current_interests == "":
            current_interests = interests
        else:
            current_interests = current_interests + ", " + interests
        self.config.set(self.section, "interests", current_interests)
        self.saveConfig()

    @requires_login
    def update(self):
        print "Updating..."
        posts = parse(OPTIONS["feeds"]["yc"]).entries
        interests = self.config.get(self.section, "interests").split(",")

        def map(words):
            mapping = []
            for word in words:
                mapping.append((word.strip(), 1))
            return mapping

        def reduce(mapping):
            counted = {}
            for word, count in mapping:
                counted[word] = counted.get(word, 0) + count
            return counted

        found = []
        for post in posts:
            title = str(post["title"].encode("utf-8"))
            title_words = [word.lower() for word in title.split(" ")]
            title_words.extend(interests)
            counted = reduce(map(title_words))
            matches = [word for word, count in counted.items() if count > 1]
            if matches:
                found.append((post["link"], title))
                self.insta.add_item(post["link"], title)
        print "Added %d article(s) to Instapaper: \n" % len(found)
        for link, title in found:
            print title
        print ""
Exemplo n.º 10
0
# GetUserTimeline(self, user_id=None, screen_name=None, since_id=None, max_id=None,
#                 count=None, include_rts=True, trim_user=None, exclude_replies=None)
STATUSES = API.GetUserTimeline(screen_name=HN_TWITTER, since_id=LAST_ID, count=200)

if len(STATUSES) > 0:
    # Instapaper Library
    i = Instapaper(INSTAPAPER_UN, INSTAPAPER_PW)

    EXPANDER = URLExpander()

    URLS = get_urls(STATUSES)
    URLS = filter_urls(URLS)

    print ''

    for url in URLS:
        print "added to Instapaper:", url
        i.add_item(url, '')

    print 'Done!'

    # Log latest tweet
    F.seek(0, 0)
    F.write(str(STATUSES[0].id))

else:
    print "No new tweets since this script was last run."

F.close()