Advertisement
AeroTools

Untitled

Mar 22nd, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.98 KB | None | 0 0
  1. #BY AERO
  2. import json
  3. import tweepy
  4. from time import sleep
  5.  
  6. config = dict()
  7. with open('config.json') as CONFIG:
  8.     config = json.load(CONFIG)
  9.  
  10. #add your twitter keys here
  11.  
  12.  
  13. query = (
  14. """#cybersecurity OR #Cybersecurity #osint OR #OSINT OR #threatanalytics OR #InfoSec OR #infosec"""
  15.     )
  16.  
  17. class constant:
  18.     def __init__(self, query):
  19.         consumer = config['consumer']
  20.         consumer_s = config['consumer_s']
  21.         token = config['token']
  22.         token_s = config['token_s']
  23.         # Authenticate to Twitter
  24.         self.auth = tweepy.OAuthHandler(consumer, consumer_s)
  25.         self.auth.set_access_token(token, token_s)
  26.         self.api = tweepy.API(self.auth)
  27.         self.query = query
  28.  
  29.  
  30.                
  31.        
  32.     def retweetQuery(self):
  33.  
  34.         for tweet in tweepy.Cursor(self.api.search, q=(self.query + ' -filter:retweets'), lang='en').items(5):
  35.             try:
  36.                 print('\nTweet by: @' + tweet.user.screen_name)
  37.                 tweet.retweet()
  38.                 print('Retweeted the tweet')
  39.                 sleep(1)
  40.             except tweepy.TweepError as e:
  41.                 print(e.reason)
  42.            
  43.             except StopIteration:
  44.                 break
  45.  
  46.         c = 0
  47.         for tweet in tweepy.Cursor(self.api.search, q=(self.query + ' -filter:retweets'),lang='en').items(10):
  48.                     try:
  49.                         print('\nTweet by: @' + tweet.user.screen_name)
  50.                         tweet.favorite()
  51.                         print('Like the tweet')
  52.                         sleep(5)
  53.                     except tweepy.TweepError as e:
  54.                         print(e.reason)
  55.  
  56.                    
  57.                     except StopIteration:
  58.                         break
  59.                     c += 1
  60.                     if c == 15: break
  61.                    
  62.     def startBot(self):
  63.         while True:
  64.             self.retweetQuery()
  65.             sleep(1600)
  66.                        
  67. constant(query).startBot()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement