Esempio n. 1
0
class OutputWrapper(QtCore.QObject):
    """ to show all output in ui text edit"""
    outputWritten = QtCore.pyqtSignal(object, object)

    def __init__(self, parent, stdout=True):
        QtCore.QObject.__init__(self, parent)
        if stdout:
            self._stream = sys.stdout
            sys.stdout = self
        else:
            self._stream = sys.stderr
            sys.stderr = self
        self._stdout = stdout

    def write(self, text):
        self._stream.write(text)
        self.outputWritten.emit(text, self._stdout)

    def __getattr__(self, name):
        return getattr(self._stream, name)

    def __del__(self):
        try:
            if self._stdout:
                sys.stdout = self._stream
            else:
                sys.stderr = self._stream
        except AttributeError:
            pass
Esempio n. 2
0
class workThread(QtCore.QThread):
    my_signal = QtCore.pyqtSignal()

    def __init__(self,
                 groupBox_follow,
                 comboBox_follow,
                 lineEdit_follow,
                 spinBox_getfollowers,
                 spinBox_getfollowing,
                 groupBox_unfollow,
                 radioButton_nonfollowers,
                 radioButton_unfollowAll,
                 radioButton_restoreFollowing,
                 groupBox_like,
                 lineEdit_like,
                 comboBox_like,
                 spinBox_nlikes,
                 groupBox_comment,
                 comboBox_comment,
                 lineEdit_comment,
                 listWidget,
                 groupBox_combo,
                 spinBox_nlikes_combo,
                 comboBox_combo,
                 lineEdit_combo,
                 return_base_path,
                 parent=None):

        super(workThread, self).__init__(parent)
        # IMPORT UI OBJECT NAME FROM MAINWINDOW CLASS
        self.groupBox_follow = groupBox_follow
        self.comboBox_follow = comboBox_follow
        self.lineEdit_follow = lineEdit_follow
        self.spinBox_getfollowers = spinBox_getfollowers
        self.spinBox_getfollowing = spinBox_getfollowing

        self.groupBox_unfollow = groupBox_unfollow
        self.radioButton_nonfollowers = radioButton_nonfollowers
        self.radioButton_unfollowAll = radioButton_unfollowAll
        self.radioButton_restoreFollowing = radioButton_restoreFollowing

        self.groupBox_like = groupBox_like
        self.lineEdit_like = lineEdit_like
        self.comboBox_like = comboBox_like
        self.spinBox_nlikes = spinBox_nlikes

        self.groupBox_comment = groupBox_comment
        self.comboBox_comment = comboBox_comment
        self.lineEdit_comment = lineEdit_comment
        self.listWidget = listWidget

        self.groupBox_combo = groupBox_combo
        self.spinBox_nlikes_combo = spinBox_nlikes_combo
        self.comboBox_combo = comboBox_combo
        self.lineEdit_combo = lineEdit_combo

        self.return_base_path = return_base_path

    def follow(self):
        # IF THE GROUPBOX IS CHECK, FOLLOW USER WITH THAT #
        if self.groupBox_follow.isChecked():
            lineEdit = str(self.lineEdit_follow.text()).strip().split(",")

            if self.comboBox_follow.currentText() == "hashtags":
                for hashtag in lineEdit:
                    # print("Begin hahstag: " + hashtag)
                    users = bot.get_hashtag_users(hashtag)
                    bot.follow_users(users)

            if self.comboBox_follow.currentText() == "followers":
                for username in lineEdit:
                    # print("Begin followers: " + username)
                    bot.follow_followers(
                        username, nfollows=self.spinBox_getfollowers.value())

            if self.comboBox_follow.currentText() == "following":
                for username in lineEdit:
                    # print("Begin following: " + username)
                    bot.follow_following(
                        username, nfollows=self.spinBox_getfollowing.value())
        else:
            print("groupBox follow not check")
            pass

    def unfollow(self):
        if self.groupBox_unfollow.isChecked():
            if self.radioButton_nonfollowers.isChecked():
                bot.unfollow_non_followers()

            if self.radioButton_unfollowAll.isChecked():
                bot.unfollow_everyone()

            if self.radioButton_restoreFollowing.isChecked():
                friends = bot.read_list_from_file(
                    self.return_base_path +
                    "friends.txt")  # getting the list of friends
                your_following = bot.following
                unfollow = list(
                    set(your_following) - set(friends)
                )  # removing your friends from the list to unfollow
                bot.unfollow_users(unfollow)
        else:
            print("groupbox unfollow uncheck")

    def like(self):
        if self.groupBox_like.isChecked():
            lineEdit = str(self.lineEdit_like.text()).strip().split(",")

            if self.comboBox_like.currentText() == "hashtags":
                for hashtag in lineEdit:
                    # print("Begin like#: " + hashtag)
                    bot.like_hashtag(hashtag,
                                     amount=self.spinBox_nlikes.value())

            if self.comboBox_like.currentText() == "followers":
                for username in lineEdit:
                    # print("Begin likefollowers: " + username)
                    bot.like_followers(username,
                                       nlikes=self.spinBox_nlikes.value())

            if self.comboBox_like.currentText() == "following":
                for username in lineEdit:
                    # print("Begin following: " + username)
                    bot.like_following(username,
                                       nlikes=self.spinBox_nlikes.value())
        else:
            print("groupBox_like not check")
            pass

    def comment(self):
        if self.groupBox_comment.isChecked():
            comment_text = random.choice(self.comment_list())
            lineEdit = str(self.lineEdit_comment.text()).strip().split(",")

            if self.comboBox_comment.currentText() == "hashtags":
                for hashtag in lineEdit:
                    bot.comment_hashtag(hashtag, text=comment_text)

            if self.comboBox_comment.currentText() == "my timeline":
                bot.comment_medias(bot.get_timeline_medias(),
                                   text=comment_text)
        else:
            print("groupbox comment no check")

    def comment_list(self):
        list = []
        for i in range(self.listWidget.count()):
            text = self.listWidget.item(i).text()
            list.append(text)
        return list

    def like_follow(self):
        usernames = str(self.lineEdit_combo.text()).strip().split(",")
        for username in usernames:
            user_id = bot.get_user_id_from_username(username)

            if self.comboBox_combo.currentText() == "followers":
                # print("combo followers")
                followers_list_id = bot.get_user_followers(
                    user_id, nfollows=self.spinBox_getfollowers.value())
                for username_id in followers_list_id:
                    new_user_id = username_id.strip()
                    bot.like_user(new_user_id,
                                  amount=self.spinBox_nlikes_combo.value())
                    bot.follow(new_user_id)
                    time.sleep(30 + 20 * random.random())
                print("complete combo followers task")

            if self.comboBox_combo.currentText() == "following":
                # print("combo following")
                following_list_id = bot.get_user_following(
                    user_id, nfollows=self.spinBox_getfollowing.value())
                for username_id in following_list_id:
                    new_user_id = username_id.strip()
                    bot.like_user(new_user_id,
                                  amount=self.spinBox_nlikes_combo.value())
                    bot.follow(new_user_id)
                    time.sleep(30 + 20 * random.random())
                print("complete combo following task")

            if self.comboBox_combo.currentText() == "likers":
                # print("combo likers")
                for username in usernames:
                    medias = bot.get_user_medias(username, filtration=False)
                    if len(medias):
                        likers = bot.get_media_likers(medias)
                        for liker in tqdm(likers):
                            bot.like_user(
                                liker,
                                amount=self.spinBox_nlikes_combo.value())
                            bot.follow(liker)
                print("complete combo likers task")

    def run_threaded(self, job_func):
        job_thread = threading.Thread(target=job_func)
        job_thread.start()

    def jobs(self):
        self.follow()
        self.like()
        self.comment()
        self.unfollow()

    def check_job(self):
        start_time = datetime.now().strftime("%H:%M")
        if self.groupBox_combo.isChecked():
            # official
            self.run_threaded(self.like_follow)
            schedule.every().day.at(start_time).do(self.run_threaded,
                                                   self.unfollow)
        else:
            self.run_threaded(self.jobs)
            # schedule.every().day.at(start_time).do(self.run_threaded, self.jobs)

    def loop_job(self):
        try:
            self.check_job()
        except:
            self.loop_job()

    # ALL FUNCTION IN WORKTHREAD START HERE
    # if combo selected run combo
    # else run schedule


# official
#     @fuckit

    def run(self):
        # todo check expired date
        # OFFICIAl

        self.loop_job()
        while 1:
            schedule.run_pending()
            print("shchedule run pending")
            time.sleep(5 * 60)