Example #1
0
 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()
Example #2
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))
Example #3
0
def add_item(user='', password='', url=None,
             title=None, selection=None, jsonp=None,
             redirect=None, response_info=False):
    return Instapaper(user, password).add_item(url,title=title,
                                               selection=selection, jsonp=jsonp,
                                               redirect=redirect,
                                               response_info=response_info)
Example #4
0
 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()
Example #5
0
def auth(user='', password=''):
    return Instapaper(user, password).auth()
    try:
        config = open(os.path.expanduser('~') + '/.instapaperrc')
        for line in config:
            matches = login.match(line)
            if matches:
                args.username = matches.group(1).strip()
                args.password = matches.group(2).strip()
                break
        if '' == args.username:
            print >> sys.stderr, 'No username:password line found in ~/.instapaperrc'
            ap.exit(-1)
    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:
	except IOError:
		print 'File \'~/.readinglist2instapaper/.lastsyncdate\' not found. Using 1970-01-01 00:00:00 as synconize from date.'

# Storing our current time for syncing later.
# Doing it this way could mean a duplicate article is sync'ed, but I'd rather have a dup then loss an article.
print 'Updating ~/.readinglist2instapaper/.lastsyncdate file.'
lastsyncdate = parse(datetime.datetime.strftime(datetime.datetime.now(), '%Y-%m-%d %H:%M:%S'))
lastsyncdateFile = open(os.path.expanduser('~/.readinglist2instapaper') + '/.lastsyncdate', 'w+')
lastsyncdateFile.write(str(lastsyncdate))
# Paranoia..
lastsyncdateFile.seek(0)
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)
Example #8
0
from instapaperlib import Instapaper

config = {
    'CHANNEL': 'instapaper',
    'USERNAME': '',
    'PASSWORD': '',
}

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
Example #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 ''
Example #10
0
                filtered_urls.append(url)
    return filtered_urls

# Read latest tweet ID scanned from log
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:
Example #11
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 ""
Example #12
0
                  access_token_secret=ACCESS_TOKEN_SECRET)

# Read latest tweet ID scanned from log
F = open(os.path.join(os.path.dirname(__file__), HN_TWITTER) + '.txt', 'a+')
# the above will create the file if it does not exist
F.close()
F = open(os.path.join(os.path.dirname(__file__), 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 = 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