Esempio n. 1
0
    def retrieve_users(self, target_hashtag_idx, the_hashtags):
        """
         #retrieve all users that have used the selected hashtags and that have not received tweets recently (last 24 hours)
        :return: the list of selected  users
        """
        now = datetime.datetime.now()

        now = datetime.datetime.now()
        pop_user = []
        final_list = []
        print(target_hashtag_idx)
        the_target_hashtag = the_hashtags[target_hashtag_idx - 1]
        # this query gets the user_ids of those users that tweeted the selected hashtag
        users = Hashtag.select(Hashtag.user_of_hashtag).where(
            Hashtag.hashtag_text == the_target_hashtag)
        users_list = []
        for item in users:
            users_list.append(item.user_of_hashtag_id)
        print(users_list)
        selected_user = []
        # this query selects the datetime of the users that where retrieved with the last query (users who tweeted certain hashtag)
        for item in users_list:
            selected_user = SentDate.select(
                SentDate.user_sent, SentDate.date_tweet_sent,
                SentDate.tweet_sent_message).where(SentDate.user_sent == item)
            # if the user has been sent a tweet in the last 24 hours skip it
            print("selected users")
            for item in selected_user:
                print(item.user_sent_id)
            for item in selected_user:
                # print("printing selected user")
                # print (item.date_tweet_sent)
                # print(item.tweet_sent_message)
                # print(item.user_sent_id)

                date_retrieved = datetime.datetime.strptime(
                    item.date_tweet_sent, '%Y-%m-%d %H:%M:%S.%f')
                print('sent', date_retrieved)
                print('48 hours', now - datetime.timedelta(hours=48))
                if (now - datetime.timedelta(hours=48)) < date_retrieved:
                    print('Not have passed 48 hours, cannot send tweet')

                    if item.user_sent_id not in pop_user:
                        pop_user.append(item.user_sent_id)

        print("user to pop: ", pop_user)
        # only keeps the users that who didn't receive a tweet in the last 48 hours
        print('user_list', users_list)
        for elem in pop_user:
            users_list = [value for value in users_list if value != elem]

        print("final list", users_list)
        return users_list
Esempio n. 2
0
    def get_hashtags(self):
        # Option 1: Retrieve the tweet to send from a previously filled table in the database
        # Option 2: Create the tweet to send on the fly (easier to do)
        """
         #retrieve all the hashtags from database
        :return: the lis of the hashtags
        """
        hashtag = Hashtag.select(Hashtag.hashtag_text).distinct()
        hashtag_list = []
        for item in hashtag:
            hashtag_list.append(item.hashtag_text)

        return hashtag_list
Esempio n. 3
0
    def get_hashtags(self):
        # Option 1: Retrieve the tweet to send from a previously filled table in the database
        # Option 2: Create the tweet to send on the fly (easier to do)

        """
         #retrieve all the hashtags from database
        :return: the lis of the hashtags
        """
        hashtag = Hashtag.select(Hashtag.hashtag_text).distinct()
        hashtag_list = []
        for item in hashtag:
            hashtag_list.append(item.hashtag_text)

        return hashtag_list
Esempio n. 4
0
    def retrieve_users(self, target_hashtag_idx, the_hashtags):
        """
         #retrieve all users that have used the selected hashtags and that have not received tweets recently (last 24 hours)
        :return: the list of selected  users
        """
        now = datetime.datetime.now()

        now = datetime.datetime.now()
        pop_user = []
        final_list = []
        print(target_hashtag_idx)
        the_target_hashtag = the_hashtags[target_hashtag_idx - 1]
        # this query gets the user_ids of those users that tweeted the selected hashtag
        users = Hashtag.select(Hashtag.user_of_hashtag).where(Hashtag.hashtag_text == the_target_hashtag)
        users_list = []
        for item in users:
            users_list.append(item.user_of_hashtag_id)
        print(users_list)
        selected_user = []
        # this query selects the datetime of the users that where retrieved with the last query (users who tweeted certain hashtag)
        for item in users_list:
            selected_user = SentDate.select(SentDate.user_sent, SentDate.date_tweet_sent, SentDate.tweet_sent_message).where(SentDate.user_sent == item)
            # if the user has been sent a tweet in the last 24 hours skip it
            print("selected users")
            for item in selected_user:
                print(item.user_sent_id)
            for item in selected_user:
                # print("printing selected user")
                # print (item.date_tweet_sent)
                # print(item.tweet_sent_message)
                # print(item.user_sent_id)

                date_retrieved = datetime.datetime.strptime(item.date_tweet_sent, '%Y-%m-%d %H:%M:%S.%f')
                print('sent', date_retrieved)
                print('48 hours', now - datetime.timedelta(hours=48))
                if (now - datetime.timedelta(hours=48)) < date_retrieved:
                    print('Not have passed 48 hours, cannot send tweet')

                    if item.user_sent_id not in pop_user:
                        pop_user.append(item.user_sent_id)

        print("user to pop: ", pop_user)
        # only keeps the users that who didn't receive a tweet in the last 48 hours
        print('user_list', users_list)
        for elem in pop_user:
            users_list = [value for value in users_list if value != elem]

        print("final list", users_list)
        return users_list