Example #1
0
 def __init__(self, cfgvalues, api, tweet):
     '''send the tweet'''
     self.cfgvalues = cfgvalues
     self.api = api
     hasnotretweethasthags = False
     hasonlyifhashtags = False
     self.twp = TweetWasPosted(self.cfgvalues)
     try:
         # test if it was retweeted enough to be retweeted by me
         if len(self.api.retweets(tweet)) >= self.cfgvalues['retweets']:
             # test if the tweet has a hashtag for not retweeting it
             if not self.notretweethashes(tweet):
                 # if the tweet does not have one of the stop hashtags, send it
                 hasnotretweethasthags = True
             if self.retweetonlyifhashtags(tweet):
                 # if the tweet has one of the tags which allows retweeting it, send it
                 hasonlyifhashtags = True
             # send the tweet if all checks are ok
             if hasnotretweethasthags and hasonlyifhashtags:
                 #self.api.retweet(tweet)
                 print("tweet {} sent!".format(tweet))
     except (tweepy.error.TweepError) as err:
         print("{}".format(err))
         print(
             "the tweet is probably retweeted already. Twitter does not allow to retweet 2 times"
         )
     finally:
         # now store the tweet
         if not self.twp.wasposted(tweet):
             self.twp.storetweet(tweet)
             WaitAMoment(self.cfgvalues['waitminsecs'],
                         self.cfgvalues['waitmaxsecs'])
Example #2
0
 def __init__(self, cfgvalues, args, api, tweet):
     '''send the tweet'''
     self.api = api
     self.args = args
     self.cfgvalues = cfgvalues
     self.storeit = False
     self.tweet = tweet
     self.twp = TweetWasPosted(self.cfgvalues)
     self.main()
Example #3
0
class Validate(object):
    '''Validate class'''
    def __init__(self, cfgvalues, api, tweet):
        '''send the tweet'''
        self.cfgvalues = cfgvalues
        self.api = api
        hasnotretweethasthags = False
        hasonlyifhashtags = False
        self.twp = TweetWasPosted(self.cfgvalues)
        try:
            # test if it was retweeted enough to be retweeted by me
            if len(self.api.retweets(tweet)) >= self.cfgvalues['retweets']:
                # test if the tweet has a hashtag for not retweeting it
                if not self.notretweethashes(tweet):
                    # if the tweet does not have one of the stop hashtags, send it
                    hasnotretweethasthags = True
                if self.retweetonlyifhashtags(tweet):
                    # if the tweet has one of the tags which allows retweeting it, send it
                    hasonlyifhashtags = True
                # send the tweet if all checks are ok
                if hasnotretweethasthags and hasonlyifhashtags:
                    #self.api.retweet(tweet)
                    print("tweet {} sent!".format(tweet))
        except (tweepy.error.TweepError) as err:
            print("{}".format(err))
            print(
                "the tweet is probably retweeted already. Twitter does not allow to retweet 2 times"
            )
        finally:
            # now store the tweet
            if not self.twp.wasposted(tweet):
                self.twp.storetweet(tweet)
                WaitAMoment(self.cfgvalues['waitminsecs'],
                            self.cfgvalues['waitmaxsecs'])

    def notretweethashes(self, tweet):
        '''check if the tweet has a hash for not retweeting'''
        found = False
        # check if the current tweet contains a do-not-retweet hash
        for i in self.cfgvalues['dontretweethashes']:
            if '#{}'.format(i) in self.api.get_status(tweet).text:
                found = True
        return found

    def retweetonlyifhashtags(self, tweet):
        '''retweet only if the tweet has the following hashtag'''
        found = False
        if self.cfgvalues['onlyifhashtags']:
            # check if the current tweet contains one of the hashtags to be retweeted
            for i in self.cfgvalues['onlyifhashtags']:
                if '#{}'.format(i) in self.api.get_status(tweet).text:
                    found = True
        else:
            found = True
        return found
Example #4
0
class Validate(object):
    '''Validate class'''
    def __init__(self, cfgvalues, api, tweet):
        '''send the tweet'''
        self.cfgvalues = cfgvalues
        self.api = api
        hasnotretweethasthags = False
        hasonlyifhashtags = False
        self.twp = TweetWasPosted(self.cfgvalues)
        try:
            # test if it was retweeted enough to be retweeted by me
            if len(self.api.retweets(tweet)) >= self.cfgvalues['retweets']:
                # test if the tweet has a hashtag for not retweeting it
                if not self.notretweethashes(tweet):
                    # if the tweet does not have one of the stop hashtags, send it
                    hasnotretweethasthags = True
                if self.retweetonlyifhashtags(tweet):
                    # if the tweet has one of the tags which allows retweeting it, send it
                    hasonlyifhashtags = True
                # send the tweet if all checks are ok
                if hasnotretweethasthags and hasonlyifhashtags:
                    #self.api.retweet(tweet)
                    print("tweet {} sent!".format(tweet))
        except (tweepy.error.TweepError) as err:
            print("{}".format(err))
            print("the tweet is probably retweeted already. Twitter does not allow to retweet 2 times")
        finally:
            # now store the tweet
            if not self.twp.wasposted(tweet):
                self.twp.storetweet(tweet)
                WaitAMoment(self.cfgvalues['waitminsecs'], self.cfgvalues['waitmaxsecs'])

    def notretweethashes(self, tweet):
        '''check if the tweet has a hash for not retweeting'''
        found = False
        # check if the current tweet contains a do-not-retweet hash
        for i in self.cfgvalues['dontretweethashes']:
            if '#{}'.format(i) in self.api.get_status(tweet).text:
                found = True
        return found

    def retweetonlyifhashtags(self, tweet):
        '''retweet only if the tweet has the following hashtag'''
        found = False
        if self.cfgvalues['onlyifhashtags']:
            # check if the current tweet contains one of the hashtags to be retweeted
            for i in self.cfgvalues['onlyifhashtags']:
                if '#{}'.format(i) in self.api.get_status(tweet).text:
                    found = True
        else:
            found = True
        return found
Example #5
0
 def __init__(self, cfgvalues, api, tweet):
     '''send the tweet'''
     self.cfgvalues = cfgvalues
     self.api = api
     hasnotretweethasthags = False
     hasonlyifhashtags = False
     self.twp = TweetWasPosted(self.cfgvalues)
     try:
         # test if it was retweeted enough to be retweeted by me
         if len(self.api.retweets(tweet)) >= self.cfgvalues['retweets']:
             # test if the tweet has a hashtag for not retweeting it
             if not self.notretweethashes(tweet):
                 # if the tweet does not have one of the stop hashtags, send it
                 hasnotretweethasthags = True
             if self.retweetonlyifhashtags(tweet):
                 # if the tweet has one of the tags which allows retweeting it, send it
                 hasonlyifhashtags = True
             # send the tweet if all checks are ok
             if hasnotretweethasthags and hasonlyifhashtags:
                 #self.api.retweet(tweet)
                 print("tweet {} sent!".format(tweet))
     except (tweepy.error.TweepError) as err:
         print("{}".format(err))
         print("the tweet is probably retweeted already. Twitter does not allow to retweet 2 times")
     finally:
         # now store the tweet
         if not self.twp.wasposted(tweet):
             self.twp.storetweet(tweet)
             WaitAMoment(self.cfgvalues['waitminsecs'], self.cfgvalues['waitmaxsecs'])
Example #6
0
class Main(object):
    """Main class"""

    def __init__(self):
        """Constructor of the Main class"""
        # parse the command line
        rtargs = CliParse()
        pathtoconf = rtargs.configfile
        # read the configuration file
        cfgparse = ConfParse(pathtoconf)
        self.cfgvalues = cfgparse.confvalues
        self.twp = TweetWasPosted(self.cfgvalues)

        # activate the twitter api
        self.auth = tweepy.OAuthHandler(self.cfgvalues["consumer_key"], self.cfgvalues["consumer_secret"])
        self.auth.secure = True
        self.auth.set_access_token(self.cfgvalues["access_token"], self.cfgvalues["access_token_secret"])
        self.api = tweepy.API(self.auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
        self.main()

    def main(self):
        """Main of the Main class"""
        # get the 20 last tweets
        lasttweets = self.api.user_timeline(self.cfgvalues["user_to_retweet"])
        # see if the last tweet of twitter api was sent already
        lasttweetid = lasttweets[-1].id
        # extract the last 20 tweet ids
        lasttweetids = [tweet.id for tweet in lasttweets]
        lasttweetids.reverse()
        tweetstosend = []
        # test if the last 20 tweets were posted
        for lasttweet in lasttweetids:
            if not self.twp.wasposted(lasttweet):
                Validate(self.cfgvalues, self.api, lasttweet)
        sys.exit(0)
Example #7
0
class Main(object):
    '''Main class'''
    def __init__(self):
        '''Constructor of the Main class'''
        # parse the command line
        rtargs = CliParse()
        self.args = rtargs.arguments
        # read the configuration file
        cfgparse = ConfParse(self.args.pathtoconf)
        self.cfgvalues = cfgparse.confvalues
        self.twp = TweetWasPosted(self.cfgvalues)

        # activate the twitter api
        self.auth = tweepy.OAuthHandler(self.cfgvalues['consumer_key'],
                                        self.cfgvalues['consumer_secret'])
        self.auth.secure = True
        self.auth.set_access_token(self.cfgvalues['access_token'],
                                    self.cfgvalues['access_token_secret'])
        self.api = tweepy.API(self.auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
        self.main()

    def main(self):
        '''Main of the Main class'''
        lasttweets = self.api.user_timeline(self.cfgvalues['user_to_retweet'])
        lasttweets.reverse()
        if self.args.limit:
            lasttweets = lasttweets[(len(lasttweets) - self.args.limit) :]
        tweetstosend = []
        # test if the last 20 tweets were posted
        for lasttweet in lasttweets:
            if not self.twp.wasposted(lasttweet.id):
                Validate(self.cfgvalues, self.args, self.api, lasttweet)
        sys.exit(0)
Example #8
0
class Main(object):
    '''Main class'''
    def __init__(self):
        '''Constructor of the Main class'''
        # parse the command line
        rtargs = CliParse()
        self.args = rtargs.arguments
        # read the configuration file
        cfgparse = ConfParse(self.args.pathtoconf)
        self.cfgvalues = cfgparse.confvalues
        self.twp = TweetWasPosted(self.cfgvalues)

        # activate the twitter api
        self.auth = tweepy.OAuthHandler(self.cfgvalues['consumer_key'],
                                        self.cfgvalues['consumer_secret'])
        self.auth.secure = True
        self.auth.set_access_token(self.cfgvalues['access_token'],
                                   self.cfgvalues['access_token_secret'])
        self.api = tweepy.API(self.auth,
                              wait_on_rate_limit=True,
                              wait_on_rate_limit_notify=True)
        self.main()

    def main(self):
        '''Main of the Main class'''
        lasttweets = self.api.user_timeline(self.cfgvalues['user_to_retweet'])
        lasttweets.reverse()
        if self.args.limit:
            lasttweets = lasttweets[(len(lasttweets) - self.args.limit):]
        tweetstosend = []
        # test if the last 20 tweets were posted
        for lasttweet in lasttweets:
            if not self.twp.wasposted(lasttweet.id):
                Validate(self.cfgvalues, self.args, self.api, lasttweet)
        sys.exit(0)
Example #9
0
 def __init__(self, cfgvalues, args, api, tweet):
     '''send the tweet'''
     self.api = api
     self.args = args
     self.cfgvalues = cfgvalues
     self.storeit = False
     self.tweet = tweet
     self.twp = TweetWasPosted(self.cfgvalues)
     self.main()
Example #10
0
    def __init__(self):
        '''Constructor of the Main class'''
        # parse the command line
        rtargs = CliParse()
        pathtoconf = rtargs.configfile
        # read the configuration file
        cfgparse = ConfParse(pathtoconf)
        self.cfgvalues = cfgparse.confvalues
        self.twp = TweetWasPosted(self.cfgvalues)

        # activate the twitter api
        self.auth = tweepy.OAuthHandler(self.cfgvalues['consumer_key'],
                                        self.cfgvalues['consumer_secret'])
        self.auth.secure = True
        self.auth.set_access_token(self.cfgvalues['access_token'],
                                   self.cfgvalues['access_token_secret'])
        self.api = tweepy.API(self.auth,
                              wait_on_rate_limit=True,
                              wait_on_rate_limit_notify=True)
        self.main()
Example #11
0
    def __init__(self):
        """Constructor of the Main class"""
        # parse the command line
        rtargs = CliParse()
        pathtoconf = rtargs.configfile
        # read the configuration file
        cfgparse = ConfParse(pathtoconf)
        self.cfgvalues = cfgparse.confvalues
        self.twp = TweetWasPosted(self.cfgvalues)

        # activate the twitter api
        self.auth = tweepy.OAuthHandler(self.cfgvalues["consumer_key"], self.cfgvalues["consumer_secret"])
        self.auth.secure = True
        self.auth.set_access_token(self.cfgvalues["access_token"], self.cfgvalues["access_token_secret"])
        self.api = tweepy.API(self.auth, wait_on_rate_limit=True, wait_on_rate_limit_notify=True)
        self.main()
Example #12
0
class Main(object):
    '''Main class'''
    def __init__(self):
        '''Constructor of the Main class'''
        # parse the command line
        rtargs = CliParse()
        pathtoconf = rtargs.configfile
        # read the configuration file
        cfgparse = ConfParse(pathtoconf)
        self.cfgvalues = cfgparse.confvalues
        self.twp = TweetWasPosted(self.cfgvalues)

        # activate the twitter api
        self.auth = tweepy.OAuthHandler(self.cfgvalues['consumer_key'],
                                        self.cfgvalues['consumer_secret'])
        self.auth.secure = True
        self.auth.set_access_token(self.cfgvalues['access_token'],
                                   self.cfgvalues['access_token_secret'])
        self.api = tweepy.API(self.auth,
                              wait_on_rate_limit=True,
                              wait_on_rate_limit_notify=True)
        self.main()

    def main(self):
        '''Main of the Main class'''
        # get the 20 last tweets
        lasttweets = self.api.user_timeline(self.cfgvalues['user_to_retweet'])
        # see if the last tweet of twitter api was sent already
        lasttweetid = lasttweets[-1].id
        # extract the last 20 tweet ids
        lasttweetids = [tweet.id for tweet in lasttweets]
        lasttweetids.reverse()
        tweetstosend = []
        # test if the last 20 tweets were posted
        for lasttweet in lasttweetids:
            if not self.twp.wasposted(lasttweet):
                Validate(self.cfgvalues, self.api, lasttweet)
        sys.exit(0)
Example #13
0
class Validate(object):
    '''Validate class'''
    def __init__(self, cfgvalues, args, api, tweet):
        '''send the tweet'''
        self.api = api
        self.args = args
        self.cfgvalues = cfgvalues
        self.storeit = False
        self.tweet = tweet
        self.twp = TweetWasPosted(self.cfgvalues)
        self.main()

    def main(self):
        '''Main of the Validate class'''
        try:
            # test if it was retweeted enough to be retweeted by me
            if self.tweet.retweet_count >= self.cfgvalues['retweets']:
                # send the tweet if all checks are ok
                if not self.notretweethashes() and self.retweetonlyifhashtags(
                ) and self.retweetonlyifolderthan(
                ) and self.retweetonlyifoyoungerthan(
                ) and self.retweetonlyifmatchingregex():
                    self.storeit = True
                    if self.args.dryrun:
                        print("tweet {} sent!".format(self.tweet.id))
                    else:
                        # at last retweet the tweet
                        self.api.retweet(self.tweet.id)
                        if self.cfgvalues['like']:
                            self.api.create_favorite(self.tweet.id)
                else:
                    self.storeit = False
        except (tweepy.error.TweepError) as err:
            print("{}".format(err))
            print(
                "the tweet is probably retweeted already. Twitter does not allow to retweet 2 times"
            )
        finally:
            # now store the tweet
            if not self.twp.wasposted(self.tweet.id) and self.storeit:
                if not self.args.dryrun:
                    self.twp.storetweet(self.tweet.id)
                WaitAMoment(self.cfgvalues['waitminsecs'],
                            self.cfgvalues['waitmaxsecs'])

    def notretweethashes(self):
        '''check if the tweet has a hash for not retweeting'''
        found = False
        # check if the current tweet contains a do-not-retweet hash
        for i in self.cfgvalues['dontretweethashes']:
            if '#{}'.format(i) in self.tweet.text:
                found = True
        return found

    def retweetonlyifhashtags(self):
        '''retweet only if the tweet has the following hashtag'''
        found = False
        if self.cfgvalues['onlyifhashtags']:
            # check if the current tweet contains one of the hashtags to be retweeted
            for i in self.cfgvalues['onlyifhashtags']:
                if '#{}'.format(i) in self.tweet.text:
                    found = True
        else:
            found = True
        return found

    def retweetonlyifolderthan(self):
        '''retweet only if the tweet is older than a number of minutes'''
        send = False
        if self.cfgvalues['olderthan']:
            # check if the tweet is older than a number of minutes
            now = datetime.datetime.utcnow()
            tweetbirth = self.tweet.created_at
            lapse = now - tweetbirth
            try:
                if (lapse.seconds / 60) > self.cfgvalues['olderthan']:
                    send = True
                else:
                    send = False
            except ValueError:
                send = False
        else:
            send = True
        return send

    def retweetonlyifoyoungerthan(self):
        '''retweet only if the tweet is younger than a number of minutes'''
        send = False
        if self.cfgvalues['youngerthan']:
            # check if the tweet is younger than a number of minutes
            now = datetime.datetime.utcnow()
            tweetbirth = self.tweet.created_at
            lapse = now - tweetbirth
            try:
                if (lapse.seconds / 60) < self.cfgvalues['youngerthan']:
                    send = True
                else:
                    send = False
            except ValueError:
                send = False
        else:
            send = True
        return send

    def retweetonlyifmatchingregex(self):
        '''retweet only if the tweet contains given regex'''
        match = True
        if self.cfgvalues['match_regex']:
            match = re.search(self.cfgvalues['match_regex'], self.tweet.text)

        return True if match else False
Example #14
0
class Validate(object):
    '''Validate class'''
    def __init__(self, cfgvalues, args, api, tweet):
        '''send the tweet'''
        self.api = api
        self.args = args
        self.cfgvalues = cfgvalues
        self.storeit = False
        self.tweet = tweet
        self.twp = TweetWasPosted(self.cfgvalues)
        self.main()

    def main(self):
        '''Main of the Validate class'''
        try:
            # test if it was retweeted enough to be retweeted by me
            if self.tweet.retweet_count >= self.cfgvalues['retweets']:
                # send the tweet if all checks are ok
                if not self.notretweethashes() and self.retweetonlyifhashtags() and self.retweetonlyifolderthan() and self.retweetonlyifoyoungerthan() and self.retweetonlyifmatchingregex():
                    self.storeit = True
                    if self.args.dryrun:
                        print("tweet {} sent!".format(self.tweet.id))
                    else:
                        # at last retweet the tweet
                        self.api.retweet(self.tweet.id)
                        if self.cfgvalues['like']:
                            self.api.create_favorite(self.tweet.id)
                else:
                    self.storeit = False
        except (tweepy.error.TweepError) as err:
            print("{}".format(err))
            print("the tweet is probably retweeted already. Twitter does not allow to retweet 2 times")
        finally:
            # now store the tweet
            if not self.twp.wasposted(self.tweet.id) and self.storeit:
                if not self.args.dryrun:
                    self.twp.storetweet(self.tweet.id)
                WaitAMoment(self.cfgvalues['waitminsecs'], self.cfgvalues['waitmaxsecs'])

    def notretweethashes(self):
        '''check if the tweet has a hash for not retweeting'''
        found = False
        # check if the current tweet contains a do-not-retweet hash
        for i in self.cfgvalues['dontretweethashes']:
            if '#{}'.format(i) in self.tweet.text:
                found = True
        return found

    def retweetonlyifhashtags(self):
        '''retweet only if the tweet has the following hashtag'''
        found = False
        if self.cfgvalues['onlyifhashtags']:
            # check if the current tweet contains one of the hashtags to be retweeted
            for i in self.cfgvalues['onlyifhashtags']:
                if '#{}'.format(i) in self.tweet.text:
                    found = True
        else:
            found = True
        return found

    def retweetonlyifolderthan(self):
        '''retweet only if the tweet is older than a number of minutes'''
        send = False
        if self.cfgvalues['olderthan']:
            # check if the tweet is older than a number of minutes
            now = datetime.datetime.utcnow()
            tweetbirth = self.tweet.created_at
            lapse = now - tweetbirth
            try:
                if (lapse.seconds / 60) > self.cfgvalues['olderthan']:
                    send = True
                else:
                    send = False
            except ValueError:
                send = False
        else:
            send = True
        return send

    def retweetonlyifoyoungerthan(self):
        '''retweet only if the tweet is younger than a number of minutes'''
        send = False
        if self.cfgvalues['youngerthan']:
            # check if the tweet is younger than a number of minutes
            now = datetime.datetime.utcnow()
            tweetbirth = self.tweet.created_at
            lapse = now - tweetbirth
            try:
                if (lapse.seconds / 60) < self.cfgvalues['youngerthan']:
                    send = True
                else:
                    send = False
            except ValueError:
                send = False
        else:
            send = True
        return send
        
    def retweetonlyifmatchingregex(self):
        '''retweet only if the tweet contains given regex'''
        match = True
        if self.cfgvalues['match_regex']:            
            match = re.search(self.cfgvalues['match_regex'], self.tweet.text)            
        
        return True if match else False