Esempio n. 1
0
from config import *

twitter = OAuthApi(consumer_key, consumer_secret)

# Get the temporary credentials for our next few calls
#temp_credentials = twitter.getRequestToken()

# User pastes this into their browser to bring back a pin number
#print(twitter.getAuthorizationURL(temp_credentials))

# Do a test API call using our new credentials
#twitter = OAuthApi(consumer_key, consumer_secret, access_token['oauth_token'], access_token['oauth_token_secret'])

user_timeline = twitter.GetUserTimeline({
    "trim_user": True,
    "screen_name": screen_name,
    "count": 200
})

tweets_list = []

now = datetime.datetime.utcnow()
d = datetime.timedelta(days=1)
since_time = now - d

for tweet in user_timeline:
    time = datetime.datetime.strptime(tweet['created_at'],
                                      '%a %b %d %H:%M:%S +0000 %Y')
    if time > since_time:
        tweets_list.append(tweet['created_at'])
        tweets_list.append('\n')
Esempio n. 2
0
class Bot:

    # its supposed that all bots will interact using twitter and
    # facebook apps

    #    tw_data={'mood':10,   # mood affects the behaviour
    #             'tuser':'',   # twitter username
    #             'tpass':'',   # twitter password
    #             'consumer_key':'',
    #             'consumer_secret':'',
    #             'atoken':'',
    #             'stoken':''}

    mood = 10.0  # mood affects the behaviour
    tuser = ''  # twitter username
    tpass = ''  # twitter password
    consumer_key = ''
    consumer_secret = ''
    atoken = ''
    stoken = ''

    tApi = OAuthApi(consumer_key, consumer_secret)  # Api

    email = ''  # respectable bots have a valid email
    # Should be a service providing an API
    emailpass = ''

    message = ''  # for messages construction

    def random_item(self, token):
        """Picks a random item from a list.        
        """
        return token[int(random.random() * len(token))]

    def twit_authenticate(self):
        """Begin a twitter session.
        """
        self.tApi = OAuthApi(self.consumer_key, self.consumer_secret,
                             self.atoken, self.stoken)

    def twit_deauthenticate(self):  #deprecated
        #self.tApi.ClearCredentials()
        """Deprecated. 
        Left for compatibility with older versions.
        """
        pass

    def twit_twit(self, token):
        """Post a new status.
        """
        self.tApi.UpdateStatus(token[0:140])

    def twit_get_user_updates(self, usrname, num):
        """Get the last updates from a specific user.
        """
        return self.tApi.GetUserTimeline(user=usrname, count=num)

    def Bot_sleep_random(self, ctime, sigtime):
        """ Sleep a randomized amount of time.
        """
        time.sleep(random.gauss(mu=ctime, sigma=sigtime))

    def Bot_sleep(self, token):
        """ Sleep a fixed amount of time
        """
        time.sleep(token)  # token in seconds