예제 #1
0
 def getValidSubreddits(self, startDownload=False):
     """
     Validate the subreddits in the subreddit list
     :param startDownload: Indicates whether or not the download should start when the validation is done
     :type startDownload: bool
     """
     model = self.subredditList.model()
     subreddits = set(model.lst)
     self.subredditValidatorThread = QThread()
     self.subredditValidator = Validator(self._rddtDataExtractor,
                                         self.queue, subreddits,
                                         ListType.SUBREDDIT)
     self.subredditValidator.moveToThread(self.subredditValidatorThread)
     self.subredditValidatorThread.started.connect(
         self.subredditValidator.run)
     self.subredditValidator.invalid.connect(self.notifyInvalidSubreddit)
     if startDownload:
         self.subredditValidator.download.connect(
             self.downloadValidUserOrSub)
     self.subredditValidator.finished.connect(
         self.subredditValidatorThread.quit)
     self.subredditValidator.finished.connect(
         self.subredditValidator.deleteLater)
     self.subredditValidatorThread.finished.connect(
         self.subredditValidatorThread.deleteLater)
     self.subredditValidator.stopped.connect(self.reactivateBtns)
     self.subredditValidatorThread.start()
예제 #2
0
def main():
    app = QApplication(sys.argv)
    rddtDataExtractor = loadState()
    if rddtDataExtractor is None:
        rddtDataExtractor = RedditDataExtractor()
    rddtDataExtractor.currentlyDownloading = False  # If something weird happened to cause currentlyDownloading to be saved as True, set it back to False

    queue = Queue()
    thread = QThread()
    recv = QueueMessageReceiver(queue)
    mainGUIWindow = RddtDataExtractorGUI(rddtDataExtractor, queue, recv)

    recv.queuePutSignal.connect(mainGUIWindow.append_text)
    recv.moveToThread(thread)
    thread.started.connect(recv.run)
    # Add clean up finished signals so the threads end appropriately when the program ends
    recv.finished.connect(thread.quit)
    recv.finished.connect(recv.deleteLater)
    thread.finished.connect(thread.deleteLater)

    # start the receiver
    thread.start()
    # show the GUI
    mainGUIWindow.show()
    # display Imgur API pop up if not hidden by user and client-id isn't set
    if rddtDataExtractor.showImgurAPINotification and rddtDataExtractor.imgurAPIClientID is None:
        mainGUIWindow.notifyImgurAPI()
    # and wait for the user to exit
    sys.exit(app.exec_())
예제 #3
0
 def getValidRedditors(self, startDownload=False):
     """
     Validate the users in the user list
     :param startDownload: Indicates whether or not the download should start when the validation is done
     :type startDownload: bool
     """
     model = self.userList.model()
     users = set(
         model.lst
     )  # create a new set so we don't change set size during iteration if we remove a user
     # These are class variables so that they don't get destroyed when we return from getValidRedditors()
     self.redditorValidatorThread = QThread()
     self.redditorValidator = Validator(self._rddtDataExtractor, self.queue,
                                        users, ListType.USER)
     self.redditorValidator.moveToThread(self.redditorValidatorThread)
     self.redditorValidatorThread.started.connect(
         self.redditorValidator.run)
     self.redditorValidator.invalid.connect(self.notifyInvalidRedditor)
     # When the validation finishes, start the downloading process on the validated users
     if startDownload:
         self.redditorValidator.download.connect(
             self.downloadValidUserOrSub)
     self.redditorValidator.finished.connect(
         self.redditorValidatorThread.quit)
     self.redditorValidator.finished.connect(
         self.redditorValidator.deleteLater)
     self.redditorValidatorThread.finished.connect(
         self.redditorValidatorThread.deleteLater)
     self.redditorValidator.stopped.connect(self.reactivateBtns)
     self.redditorValidatorThread.start()
 def downloadValidUserOrSub(self, validUsersOrSubs):
     """
     Begin the download process for the validated users or subreddits
     :type validUsersOrSubs: list
     """
     if self._rddtDataExtractor.downloadType is DownloadType.USER_SUBREDDIT_CONSTRAINED or self._rddtDataExtractor.downloadType is DownloadType.USER_SUBREDDIT_ALL:
         self.downloader = Downloader(self._rddtDataExtractor, validUsersOrSubs, self.queue, ListType.USER)
     elif self._rddtDataExtractor.downloadType is DownloadType.SUBREDDIT_CONTENT:
         self.downloader = Downloader(self._rddtDataExtractor, validUsersOrSubs, self.queue, ListType.SUBREDDIT)
     self.thread = QThread()
     self.downloader.moveToThread(self.thread)
     self.thread.started.connect(self.downloader.run)
     self.downloader.finished.connect(self.thread.quit)
     self.downloader.finished.connect(self.reactivateBtns)
     self.downloader.finished.connect(self.downloader.deleteLater)
     self.downloader.finished.connect(lambda: self.setUnsavedChanges(True))
     self.thread.finished.connect(self.thread.deleteLater)
     self.thread.start()
예제 #5
0
def main():
    app = QApplication(sys.argv)
    rddtDataExtractor = loadState()
    if rddtDataExtractor is None:
        rddtDataExtractor = RedditDataExtractor()
    else:
        # If something weird happened to cause currentlyDownloading to be saved as True, set it back to False
        rddtDataExtractor.currentlyDownloading = False
        # reinstantiate the praw instance because it doesn't shelve properly
        # praw shelve issue causes http.validate_certs to be uninstantiated
        rddtDataExtractor._r = praw.Reddit(
            user_agent='Data Extractor for reddit v1.1 by /u/VoidXC')
        rddtDataExtractor._r.http.validate_certs = 'RedditDataExtractor/cacert.pem'

    queue = Queue()
    thread = QThread()
    recv = QueueMessageReceiver(queue)
    mainGUIWindow = RddtDataExtractorGUI(rddtDataExtractor, queue, recv)

    recv.queuePutSignal.connect(mainGUIWindow.append_text)
    recv.moveToThread(thread)
    thread.started.connect(recv.run)
    # Add clean up finished signals so the threads end appropriately when the program ends
    recv.finished.connect(thread.quit)
    recv.finished.connect(recv.deleteLater)
    thread.finished.connect(thread.deleteLater)

    # start the receiver
    thread.start()
    # show the GUI
    mainGUIWindow.show()
    # display Imgur API pop up if not hidden by user and client-id isn't set
    if rddtDataExtractor.showImgurAPINotification and rddtDataExtractor.imgurAPIClientID is None:
        mainGUIWindow.notifyImgurAPI()
    # and wait for the user to exit
    sys.exit(app.exec_())