Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Python 

Python Twitter updater

Hi, I want to be able to get somebodies tweets as soon as they tweet, but so far all I can do is make it so that when i manually ask for the tweets rather then it automatically updating for me.

Heres my code:

PHP Code

<?php 
import twitter
api 
= twitter.Api(consumer_key='', #im not showing you my tokens and keys
                  
consumer_secret='',
                  
access_token_key='',
                  
access_token_secret='')

statuses = api.GetUserTimeline(screen_name="USERNAME") #username of twitter profile
stats = ([s.text for s in statuses])
print(
stats[0]) 

So how do I get it to automatically update rather than rerunning the script?
Perhaps use some kind of a listener to listen for new tweets and instantly notify you when they are out?
(Nov 20, 2016 08:10 AM)Delysid Wrote:  Perhaps use some kind of a listener to listen for new tweets and instantly notify you when they are out?

Yeah I thought that but had no idea how to do it?

ok I have this so far

PHP Code

<?php 
@bot.command()
async def alerts():
    
consumer_key = ''
    
consumer_secret = ''
    
access_token = ''
    
access_token_secret = ''

    
class StdOutListener(tweepy.StreamListener):
        
async def on_data(self, data):
            
decoded = json.loads(data)
            print(
'@%s: %s' % (decoded['user']['screen_name'], decoded['text'].encode('ascii', 'ignore')))
            
msg = ('@%s: %s' % (decoded['user']['screen_name'], decoded['text'].encode('ascii', 'ignore')))
            
await bot.say(msg)
            return 
True

        def on_error
(self, status):
            print (
status)

    if 
__name__ == '__main__':
        
l = StdOutListener()
        
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
        
auth.set_access_token(access_token, access_token_secret)

        print (
"Showing all new tweets for #nmd:")
        
stream = tweepy.Stream(auth, l)
        
stream.filter(track=['tweets']) 

So im using this as a discord bot but I dont know how to make it write the new tweets in the chat, btw there is more to the program but i didnt include it. I can make it write the idle but not in the dicord - fyi the bot is fully working


Possibly Related Threads...
Thread / Author Replies Views Last Post
[Python] by Bass_ReevesAug 20, 2023 01:44 AM 9 630 Aug 20, 2023 01:44 AM
Last Post: Lucky4L
[.NET] by KyFuJan 10, 2019 07:35 AM 6 297 Jan 10, 2019 07:35 AM
Last Post: InterGalactic
[.NET] by SoldiercrimesDec 31, 2017 04:16 AM 10 633 Dec 31, 2017 04:16 AM
Last Post: Hopsin