def handle(self):
       
        consumer_key = get_config_value('consumer_key')
        consumer_secret = get_config_value('consumer_secret')
        token = get_config_value('token')
        token_secret = get_config_value('token_secret')

        if consumer_key and consumer_secret and token and token_secret:

            conf = db.stored_config()
            auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
            auth.set_access_token(token, token_secret)
            api = tweepy.API(auth)

            count_tweets = 0
            try:
                replies = api.direct_messages()
                #pdb.set_trace()
                
                tweet_published = db_published.stored_config()
                
                for i in range(len(replies),0,-1):
                    r = replies[i-1]
                    try:
                        value = tweet_published['tweet.%s.%s' %\
                                         (r.sender_screen_name, r.id)]
                    except KeyError:
                        value = None
                            
                    for k in [i for i in conf.keys() if 'dm.' in i]:    
                        if conf[k] == r.sender_screen_name:
                            if value is None:
                                tweet_published['tweet.%s.%s' %\
                                         (r.id, r.sender_screen_name)] =\
                                     'Published: %s' % time.asctime()
                                try:
                                    status = api.update_status(r.text)      
                            
                                    count_tweets += 1 
                                    message = RECEIVED_MESSAGE % ( r.id,
                                                      r.sender_screen_name,
                                                      r.created_at,
                                                      status.author.screen_name,
                                                      status.id )
                                    log.info(message)
                                except TweepError, e:
                                    log.error(e)
                        else:    
                            if value is None:
                                message = REJECTED_MESSAGE % ( r.id,
                                                           r.sender_screen_name,
                                                           r.created_at )
                                log.info(message)
                if count_tweets > 0:
                    log.info('Tweets direct messages: %s' % count_tweets)

            except TweepError, e:
                log.error(e)
Example #2
0
 def handle(self):
     
     conf = db.stored_config()
     try:
         for i in conf.items():
             print "%-15s= %-4s" % (i[0], i[1])
         print ''
     except Exception, error:
         raise CommandError("Could not complete command: %s" % error)
Example #3
0
 def handle(self):
     
     conf = db.stored_config()        
     value = self.args.get_value('--log-file')
     if value is None:
         try:
             del conf['log_file'] 
         except KeyError:
             pass
     else:
         conf['log_file'] = value
Example #4
0
 def handle(self):
    
     conf = db.stored_config()
     try:
         print "List of accounts registered:"
         print "----------------------------"            
         for k in [i for i in conf.keys() if 'dm.' in i]:
             print "%-15s = %-4s" % (k, conf[k])
         print ''
     except Exception, error:
         raise CommandError("Could not complete command: %s" % error)
Example #5
0
 def handle(self):
     
     conf = db.stored_config()        
     account = self.args.get_value('--account-add')
     if account is not None:
         for k in [i for i in conf.keys() if 'dm.' in i]:
             if conf[k] == account:
                 error("Account %s exist.\n" % account )
         conf['dm.%s' % str(uuid.uuid4())] = account
     else:
         raise CommandError("Please use options\n tweetmob %s" % self.usage)
Example #6
0
 def handle(self):
     
     conf = db.stored_config()
     filename = self.args.get_value('--config-export')
     if filename is not None:
         try:
             f = open(filename,'w+')
             for i in conf.items():
                 f.write("%-15s= %-4s\n" % (i[0], i[1]) )
             f.close()
         except Exception, error:
             print "Could not complete command: %s" % error
Example #7
0
 def handle(self):
    
     conf = db.stored_config()
     account = self.args.get_value('--account-del')
     if account is None:        
         print "Please use options\n tweetmob %s" % self.usage
     else:
         try:
             for k in [i for i in conf.keys() if 'dm.' in i]:
                 if conf[k] == account:
                     del conf[k]
         except Exception, error:
             raise CommandError("Could not complete command: %s" % error)
Example #8
0
 def handle(self):
     
     conf = db.stored_config()
     filename = self.args.get_value('--config-import')
     if filename is not None:
         try:
             f = open(filename,'r+')
             for l in f.readlines():
                 key, value = l.replace('\n','').split('=')
                 conf[key.replace(' ','')] = value.replace(' ','') 
             f.close()
         except Exception, error:
             print "Could not complete command: %s" % error
Example #9
0
    def handle(self):

        auth = tweepy.OAuthHandler(__consumer_key__, __consumer_secret__)

        # User pastes this into their browser to bring back a pin number        
        print("Please, copy & paste this URL to your web browser:\n")
        print(auth.get_authorization_url())
        print("\nYou'll have to authorize the 'tweetmob' app and then copy and paste the given PIN here.\n")

        # Get the pin # from the user and get our permanent credentials
        oauth_verifier = raw_input('What is the PIN? ')
        auth.get_access_token(oauth_verifier)

        conf = db.stored_config()
        conf['consumer_key']    = __consumer_key__
        conf['consumer_secret'] = __consumer_secret__
        conf['token']           = auth.access_token.key
        conf['token_secret']    = auth.access_token.secret

        print('Credentials added.')