Jump to content

I Need Help With A Python Script Because I'm Stupid

Go to solution Solved by codesidian,
for tweet_info in twt:
			
			if tweet_info != last_screen_name:
            
				user_d.write(last_screen_name)
				user_d.close()
				user_d = open('users_database.log','r')
				for user_sort in user_d:
					blah
					if user_sort != last_screen_name:
						 blah
                         
				user_d.close()
				user_d = open('users_database.log','w')
				last_screen_name = tweet_info.user.screen_name

What are the elements of 'twt' and 'user_d'? By the sounds of it you're either checking if the last username is equal to an element that doesn't even contain the current username or setting 'last_screen_name', 'twt' or 'user_d' incorrectly. 

So, I have a project in which I want a bot I'm working on (My first actual python program ever) to tweet a message or image to a user that uses its keyword (@bot_name_here - I still don't know the name of it yet.)

I'm using Python 2.7 I think (Whatever your stock Ubuntu 18.10 Distro comes with) and am fairly new to the language. I have installed Tweepy (Which works fine.) and the program goes fine until I try to make a loop that is supposed to make sure that the bot doesn't spam people. It is supposed to keep a record of the users it has tweeted to and then compare it to the list that was just received for any matches in the file and then them be skipped by the bot. My bot is from what I can tell reading both of them and then either accepting the matches and continuing the process or completely ignoring all of them at this point. If someone could tell me where I made a mistake, that would be great! Thanks a billion guys!

 

py-twitter-keyword-reply-bot.py

Link to comment
Share on other sites

Link to post
Share on other sites

for tweet_info in twt:
			
			if tweet_info != last_screen_name:
            
				user_d.write(last_screen_name)
				user_d.close()
				user_d = open('users_database.log','r')
				for user_sort in user_d:
					blah
					if user_sort != last_screen_name:
						 blah
                         
				user_d.close()
				user_d = open('users_database.log','w')
				last_screen_name = tweet_info.user.screen_name

What are the elements of 'twt' and 'user_d'? By the sounds of it you're either checking if the last username is equal to an element that doesn't even contain the current username or setting 'last_screen_name', 'twt' or 'user_d' incorrectly. 

Link to comment
Share on other sites

Link to post
Share on other sites

you have:

status = '0'

 

and then:

if status == 0:

 

The first is a string and the second is an integer so they will not be considered equal.

 

On line 18, I would suggest changing to:

status = 0

 

and on line 56, change to:

status = 1

 

Not sure if this will solve you issue but is certainly worth fixing.

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, codesidian said:

for tweet_info in twt:
			
			if tweet_info != last_screen_name:
            
				user_d.write(last_screen_name)
				user_d.close()
				user_d = open('users_database.log','r')
				for user_sort in user_d:
					blah
					if user_sort != last_screen_name:
						 blah
                         
				user_d.close()
				user_d = open('users_database.log','w')
				last_screen_name = tweet_info.user.screen_name

What are the elements of 'twt' and 'user_d'? By the sounds of it you're either checking if the last username is equal to an element that doesn't even contain the current username or setting 'last_screen_name', 'twt' or 'user_d' incorrectly. 

Yeah. I was doing some debugging while I was a school. So yeah I probably got that part wrong. Thanks for looking at it! I'll try doing what you said during lunch break.

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, Meic said:

you have:


status = '0'

 

and then:


if status == 0:

 

The first is a string and the second is an integer so they will not be considered equal.

 

On line 18, I would suggest changing to:


status = 0

 

and on line 56, change to:


status = 1

 

Not sure if this will solve you issue but is certainly worth fixing.

I'll check into that thanks a bunch!

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, Underfire17 said:

I'll check into that thanks a bunch!

Yeah in your example you set it to the word value of 0 and checked if it had the numerical value 0. 

You can’t do that because they’re not the same. 

Quotes make things strings or words. 

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×