Python - Twitter bot that retweets based on 'x' number of retweets
so I'm working on my first ever code for a simple Twitter bot that retweets based on hashtags. What I want to do is add a bit of code which will still allow the bot to retweet tweets that have one the hashtags specified but also ensure that the tweets have an X number of retweets already, to stop the bot tweeting small personal accounts that have little to no interactions.
Here is the code I've got so far which is working, just retweeting everyone and anyone that uses one of the hashtags:
import tweepy
from time import sleep
from keys import *
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
for tweet in tweepy.Cursor(api.search, q='#bcafc OR #hcafc OR #rufc OR #lufc OR #mot OR #alaw OR #twitterblades OR #sufc OR #forgedinsteel OR #swfc OR #swfcLIVE OR #notjustagame OR #youreds OR #utb OR #boro OR #htafc OR #drfc').items():
try:
print('Yorkshire Footy Bot found tweet by @' + tweet.user.screen_name + '. ' + 'Attempting to retweet.')
tweet.retweet()
print('Retweet published successfully.')
sleep(20)
except tweepy.TweepError as error:
print('nError. Retweet not successful. Reason: ')
print(error.reason)
except StopIteration:
break
If there is no way to do this would it be possible to only retweet from accounts the bot follows? Even that would help limit the random tweets it's sending out.
python twitter
add a comment |
so I'm working on my first ever code for a simple Twitter bot that retweets based on hashtags. What I want to do is add a bit of code which will still allow the bot to retweet tweets that have one the hashtags specified but also ensure that the tweets have an X number of retweets already, to stop the bot tweeting small personal accounts that have little to no interactions.
Here is the code I've got so far which is working, just retweeting everyone and anyone that uses one of the hashtags:
import tweepy
from time import sleep
from keys import *
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
for tweet in tweepy.Cursor(api.search, q='#bcafc OR #hcafc OR #rufc OR #lufc OR #mot OR #alaw OR #twitterblades OR #sufc OR #forgedinsteel OR #swfc OR #swfcLIVE OR #notjustagame OR #youreds OR #utb OR #boro OR #htafc OR #drfc').items():
try:
print('Yorkshire Footy Bot found tweet by @' + tweet.user.screen_name + '. ' + 'Attempting to retweet.')
tweet.retweet()
print('Retweet published successfully.')
sleep(20)
except tweepy.TweepError as error:
print('nError. Retweet not successful. Reason: ')
print(error.reason)
except StopIteration:
break
If there is no way to do this would it be possible to only retweet from accounts the bot follows? Even that would help limit the random tweets it's sending out.
python twitter
There are specific rules around what content you should retweet, and how, in the developer policy -> help.twitter.com/en/rules-and-policies/twitter-automation
– Andy Piper
Nov 22 at 20:43
Cheers mate, we’re already familiar with this I promise. The bot is only going to run for around ten minutes on Monday afternoon for a presentation then it will be gracefully retired.
– Jamie Wilkinson
Nov 23 at 21:32
add a comment |
so I'm working on my first ever code for a simple Twitter bot that retweets based on hashtags. What I want to do is add a bit of code which will still allow the bot to retweet tweets that have one the hashtags specified but also ensure that the tweets have an X number of retweets already, to stop the bot tweeting small personal accounts that have little to no interactions.
Here is the code I've got so far which is working, just retweeting everyone and anyone that uses one of the hashtags:
import tweepy
from time import sleep
from keys import *
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
for tweet in tweepy.Cursor(api.search, q='#bcafc OR #hcafc OR #rufc OR #lufc OR #mot OR #alaw OR #twitterblades OR #sufc OR #forgedinsteel OR #swfc OR #swfcLIVE OR #notjustagame OR #youreds OR #utb OR #boro OR #htafc OR #drfc').items():
try:
print('Yorkshire Footy Bot found tweet by @' + tweet.user.screen_name + '. ' + 'Attempting to retweet.')
tweet.retweet()
print('Retweet published successfully.')
sleep(20)
except tweepy.TweepError as error:
print('nError. Retweet not successful. Reason: ')
print(error.reason)
except StopIteration:
break
If there is no way to do this would it be possible to only retweet from accounts the bot follows? Even that would help limit the random tweets it's sending out.
python twitter
so I'm working on my first ever code for a simple Twitter bot that retweets based on hashtags. What I want to do is add a bit of code which will still allow the bot to retweet tweets that have one the hashtags specified but also ensure that the tweets have an X number of retweets already, to stop the bot tweeting small personal accounts that have little to no interactions.
Here is the code I've got so far which is working, just retweeting everyone and anyone that uses one of the hashtags:
import tweepy
from time import sleep
from keys import *
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = tweepy.API(auth)
for tweet in tweepy.Cursor(api.search, q='#bcafc OR #hcafc OR #rufc OR #lufc OR #mot OR #alaw OR #twitterblades OR #sufc OR #forgedinsteel OR #swfc OR #swfcLIVE OR #notjustagame OR #youreds OR #utb OR #boro OR #htafc OR #drfc').items():
try:
print('Yorkshire Footy Bot found tweet by @' + tweet.user.screen_name + '. ' + 'Attempting to retweet.')
tweet.retweet()
print('Retweet published successfully.')
sleep(20)
except tweepy.TweepError as error:
print('nError. Retweet not successful. Reason: ')
print(error.reason)
except StopIteration:
break
If there is no way to do this would it be possible to only retweet from accounts the bot follows? Even that would help limit the random tweets it's sending out.
python twitter
python twitter
edited Nov 22 at 19:35
sirandy
1,51931623
1,51931623
asked Nov 22 at 17:39
Jamie Wilkinson
11
11
There are specific rules around what content you should retweet, and how, in the developer policy -> help.twitter.com/en/rules-and-policies/twitter-automation
– Andy Piper
Nov 22 at 20:43
Cheers mate, we’re already familiar with this I promise. The bot is only going to run for around ten minutes on Monday afternoon for a presentation then it will be gracefully retired.
– Jamie Wilkinson
Nov 23 at 21:32
add a comment |
There are specific rules around what content you should retweet, and how, in the developer policy -> help.twitter.com/en/rules-and-policies/twitter-automation
– Andy Piper
Nov 22 at 20:43
Cheers mate, we’re already familiar with this I promise. The bot is only going to run for around ten minutes on Monday afternoon for a presentation then it will be gracefully retired.
– Jamie Wilkinson
Nov 23 at 21:32
There are specific rules around what content you should retweet, and how, in the developer policy -> help.twitter.com/en/rules-and-policies/twitter-automation
– Andy Piper
Nov 22 at 20:43
There are specific rules around what content you should retweet, and how, in the developer policy -> help.twitter.com/en/rules-and-policies/twitter-automation
– Andy Piper
Nov 22 at 20:43
Cheers mate, we’re already familiar with this I promise. The bot is only going to run for around ten minutes on Monday afternoon for a presentation then it will be gracefully retired.
– Jamie Wilkinson
Nov 23 at 21:32
Cheers mate, we’re already familiar with this I promise. The bot is only going to run for around ten minutes on Monday afternoon for a presentation then it will be gracefully retired.
– Jamie Wilkinson
Nov 23 at 21:32
add a comment |
1 Answer
1
active
oldest
votes
If you take a look at the documentation you'll see that Twitter gives you a lot of metadata about a Tweet.
You've correctly identified that tweet.user.screen_name
gives you the user's name.
In a similar fashion, you can use tweet.retweet_count
to see how many times a Tweet has been retweeted.
You could use
for tweet in tweepy.Cursor(api.search, q='#....').items():
if tweet.retweet_count > 10:
...
But, as Andy has said, please don't build a bot which just mindlessly retweets others.
Thanks for the help mate, it’s only going to run for a short time during a presentation on Monday, just to prove it works, then it will be gracefully retired. I can assure you it’s not to spam, we just had to build a business case around ‘something we made’.
– Jamie Wilkinson
Nov 23 at 21:31
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435992%2fpython-twitter-bot-that-retweets-based-on-x-number-of-retweets%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
If you take a look at the documentation you'll see that Twitter gives you a lot of metadata about a Tweet.
You've correctly identified that tweet.user.screen_name
gives you the user's name.
In a similar fashion, you can use tweet.retweet_count
to see how many times a Tweet has been retweeted.
You could use
for tweet in tweepy.Cursor(api.search, q='#....').items():
if tweet.retweet_count > 10:
...
But, as Andy has said, please don't build a bot which just mindlessly retweets others.
Thanks for the help mate, it’s only going to run for a short time during a presentation on Monday, just to prove it works, then it will be gracefully retired. I can assure you it’s not to spam, we just had to build a business case around ‘something we made’.
– Jamie Wilkinson
Nov 23 at 21:31
add a comment |
If you take a look at the documentation you'll see that Twitter gives you a lot of metadata about a Tweet.
You've correctly identified that tweet.user.screen_name
gives you the user's name.
In a similar fashion, you can use tweet.retweet_count
to see how many times a Tweet has been retweeted.
You could use
for tweet in tweepy.Cursor(api.search, q='#....').items():
if tweet.retweet_count > 10:
...
But, as Andy has said, please don't build a bot which just mindlessly retweets others.
Thanks for the help mate, it’s only going to run for a short time during a presentation on Monday, just to prove it works, then it will be gracefully retired. I can assure you it’s not to spam, we just had to build a business case around ‘something we made’.
– Jamie Wilkinson
Nov 23 at 21:31
add a comment |
If you take a look at the documentation you'll see that Twitter gives you a lot of metadata about a Tweet.
You've correctly identified that tweet.user.screen_name
gives you the user's name.
In a similar fashion, you can use tweet.retweet_count
to see how many times a Tweet has been retweeted.
You could use
for tweet in tweepy.Cursor(api.search, q='#....').items():
if tweet.retweet_count > 10:
...
But, as Andy has said, please don't build a bot which just mindlessly retweets others.
If you take a look at the documentation you'll see that Twitter gives you a lot of metadata about a Tweet.
You've correctly identified that tweet.user.screen_name
gives you the user's name.
In a similar fashion, you can use tweet.retweet_count
to see how many times a Tweet has been retweeted.
You could use
for tweet in tweepy.Cursor(api.search, q='#....').items():
if tweet.retweet_count > 10:
...
But, as Andy has said, please don't build a bot which just mindlessly retweets others.
answered Nov 22 at 21:11
Terence Eden
9,77912662
9,77912662
Thanks for the help mate, it’s only going to run for a short time during a presentation on Monday, just to prove it works, then it will be gracefully retired. I can assure you it’s not to spam, we just had to build a business case around ‘something we made’.
– Jamie Wilkinson
Nov 23 at 21:31
add a comment |
Thanks for the help mate, it’s only going to run for a short time during a presentation on Monday, just to prove it works, then it will be gracefully retired. I can assure you it’s not to spam, we just had to build a business case around ‘something we made’.
– Jamie Wilkinson
Nov 23 at 21:31
Thanks for the help mate, it’s only going to run for a short time during a presentation on Monday, just to prove it works, then it will be gracefully retired. I can assure you it’s not to spam, we just had to build a business case around ‘something we made’.
– Jamie Wilkinson
Nov 23 at 21:31
Thanks for the help mate, it’s only going to run for a short time during a presentation on Monday, just to prove it works, then it will be gracefully retired. I can assure you it’s not to spam, we just had to build a business case around ‘something we made’.
– Jamie Wilkinson
Nov 23 at 21:31
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435992%2fpython-twitter-bot-that-retweets-based-on-x-number-of-retweets%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
There are specific rules around what content you should retweet, and how, in the developer policy -> help.twitter.com/en/rules-and-policies/twitter-automation
– Andy Piper
Nov 22 at 20:43
Cheers mate, we’re already familiar with this I promise. The bot is only going to run for around ten minutes on Monday afternoon for a presentation then it will be gracefully retired.
– Jamie Wilkinson
Nov 23 at 21:32