Пример #1
0
    def post(self):
        oauth_token = self.request.get('oauth_token')
        oauth_verifier = self.request.get('oauth_verifier')

        justOne = self.request.get('submitType') == 'Tweet this'
        linkThem = self.request.get('submitType') == 'Tweet this, and tweet future entries!'
        
        connector = Connection.gql("WHERE token_key=:key and verifier=:verifier", key=oauth_token, verifier=oauth_verifier).get()

        (title, link, id) = feedreader.getLatestEntry(connector.atomUrl)

        if justOne:
            if id not in connector.entryIdsThatHaveBeenTweeted:
                tweet = tweetwriter.makeTweet(title, link, connector.tweetTemplate)        

                # Rebuild the auth handler
                auth = tweepy.OAuthHandler(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET)
                auth.set_access_token(connector.access_token_key, connector.access_token_secret)

                api = tweepy.API(auth_handler=auth, secure=True, retry_count=3)
                api.update_status(tweet)
                
                self.response.out.write(template.render('templates/tweetingout.html', {'tweet' : tweet }))
            else:
                self.response.out.write(template.render('templates/alreadytweeted.html', {}))
        else:
            entryIds = feedreader.getAllEntryIds(connector.atomUrl)
            connector.entryIdsThatHaveBeenTweeted.extend(entryIds)
            connector.enabled = True
            connector.put()
            self.response.out.write(template.render('templates/setupcomplete.html', {}))
    
        connector.enabled = linkThem
        connector.put()
Пример #2
0
    def get(self):
        enabledConnections = models.Connection.gql('where enabled = True')
        logging.info('starting check for new entries')
        
        for connector in enabledConnections:
            if connector.access_token_key and connector.access_token_secret:
                try:
                    (title, link, id) = feedreader.getLatestEntry(connector.atomUrl)
                    logging.debug('latest entry for %s is %s (%s)' % (connector.atomUrl, id, title))
#                    logging.debug('entries that have been tweeted are: %s' % connector.entryIdsThatHaveBeenTweeted)
                    
                    if len(connector.entryIdsThatHaveBeenTweeted) == 0:
                        #if none have been done, mark all done -- don't want to blast
                        entryIds = feedreader.getAllEntryIds(connector.atomUrl)
                        connector.entryIdsThatHaveBeenTweeted.extend(entryIds)
                        connector.put()
                    else:
                        if id not in connector.entryIdsThatHaveBeenTweeted:
                            logging.info('Posting entry with id %s - %s' % (id, link))
                            tweet = tweetwriter.makeTweet(title, link, connector.tweetTemplate)
                            
                            auth = tweepy.OAuthHandler(TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET)
                            auth.set_access_token(connector.access_token_key, connector.access_token_secret)

                            api = tweepy.API(auth_handler=auth, secure=True, retry_count=3)
                            api.update_status(tweet)

                            connector.entryIdsThatHaveBeenTweeted.append(id)
                            connector.put()
                        else:
                            pass # the latest entry has been tweeted already
                except Exception, e:
                    logging.error(e)
            else:
                pass
                # no access/authorization yet
Пример #3
0
 def testMakeTweet(self): 
     (title, link) = ('My blog entry', 'http://www.blogspot.com')
     
     tweet = tweetwriter.makeTweet(title, link, 'New Blog Entry: "{title}" {link}', shortener=None)
     
     self.assertEquals('New Blog Entry: "%s" %s' % (title, link), tweet)
Пример #4
0
 def testMakeTweetWithShortener(self): 
     (title, link) = ('My blog entry', 'http://www.blogspot.com')
     
     tweet = tweetwriter.makeTweet(title, link, 'New Blog Entry: "{title}" {link}', shortener = lambda x: 'blahblah')
     
     self.assertEquals('New Blog Entry: "%s" blahblah' % title, tweet)