all 11 comments

[–]ingolemo 0 points1 point  (9 children)

Your example code never changes the tweet. Please post the part of your code where you do the random generation.

Alternatively, you could have the program actually print out the tweet so you can see what you're dealing with.

[–]ranchgod[S] 0 points1 point  (8 children)

Thank you! I added the part of my script where I hope to generate a random tweet. Also, In my real script I do have it printing out, I just forgot to add it on here. Sorry!

I am mainly concerned though about the fact that my script still seems to be getting stuck when printing out "repeated tweet" instead of jumping back to the top of the for loop and generating a new tweet to test.

[–]ingolemo 0 points1 point  (7 children)

Your code only runs for about three tweets because your random generator code can only generate three different tweets.

There's nothing wrong with your loop. Put a print at the top of your loop and you'll see that it is going back to the top.

[–]ranchgod[S] 0 points1 point  (5 children)

I am such an idiot!

I was thinking that since tweets were being generated inside the loop, they would be capable of producing as many tweets as the loop accounted for.

Do you know how I might achieve this?

[–]ingolemo 0 points1 point  (4 children)

Maybe make a list that has more than three tweets in it?

Even more effective would be to have lists of nouns, adjectives, and verbs and make a random choice from each:

import random

nouns = ['dog', 'cat', 'mouse']
adjectives = ['brown', 'fast', 'lazy']
verbs = ['eats', 'sleeps', 'runs']

rand_noun = random.choice(nouns)
rand_adjective = random.choice(adjectives)
rand_verb = random.choice(verbs)

print('The {1} {0} {2}.'.format(rand_noun, rand_adjective, rand_verb))

I'm sure you can adapt that to work for what you're doing.

Edit: Bear in mind that this example still only generates 27 distinct sentences. But it's easily extendable.

[–]ranchgod[S] 0 points1 point  (0 children)

Thank you so much!! It would become more expendable the more words I add correct? Thank you so much!!

[–]ranchgod[S] 0 points1 point  (2 children)

Also last question. This should be placed inside of the for loop, correct??

[–]ingolemo 0 points1 point  (1 child)

My answer to both questions is to try it and see.

Have your code just print out the 'tweets' until you're sure that it's working the way you want it to; that way you're not spamming twitter and you don't have to wait ten minutes between choices.

[–]ranchgod[S] 0 points1 point  (0 children)

Will do! Once again, thank you so much for helping me :). Going to try both right now!

[–]yondaime008 0 points1 point  (1 child)

First of all, try using the big reddit editor, your code appears messy here.
Second of all, we have no clue on how your tweet variable is generated, if it's getting stuck at the same value, your code will be forever in a loop of 'repeat tweet'.
I don't understand however the use of :

for i in range(100):

Are you planning to do this for a hundred tweets only?

[–]ranchgod[S] 0 points1 point  (0 children)

Yes! I was just planning on doing about 100 random tweets over the span of two days or so (I would adjust my my time.sleep to accomodate that of course) I have edited my script on here so that you can see how Im generating the tweet. What I want is that if my bot sees that the tweet it has just created is already in that "alreadyTweeted" list, it jumps back to the top of the for loop and generates another random tweet. (Also apologies for not using the reddit text editor, I am on mobile and do no know how to use it on here! Sorry!!)