def getDataFromJsonFile():
    jsonFileReader = JSONReader()
    jsonData = jsonFileReader.read()
    path = jsonFileReader.getPath()
    returnData = {}
    returnData['jsonData'] = jsonData
    returnData['jsonPath'] = path
    return returnData
Beispiel #2
0
    def oneTweet(emptyTweet, tweetID, outputJSON):

        # Pull that one tweet's json file
        genericPath = Config.scriptPath + 'PullTweet.sh'
        os.system(genericPath + ' ' + tweetID + ' ' + KeyBank.getKey() + ' ' +
                  outputJSON)

        # Read in tweet, from file, and into empty tweet
        JSONReader.standardTweet(emptyTweet, outputJSON)
Beispiel #3
0
 def generateList(cls, scrapableSitesList):
     sites = JSONReader.readJSON(
         JSONReader.stringFromFile(Website.locationFile))
     for site in sites["Websites"]["scrapable"]:
         if(Website.checkDuplicateURL(site["url"], scrapableSitesList)):
             continue
         scrapableSitesList.append(ScrapableWebsite(
             site["name"], site["url"], site["searchFor"], site["group"], 1, site["subject"], site["message"]))
     scrapableSitesList = ScrapableWebsite.garbageCollection(
         scrapableSitesList)
     return scrapableSitesList
Beispiel #4
0
 def generateList(cls):
     sites = JSONReader.readJSON(
         JSONReader.stringFromFile(Website.locationFile))
     loginSitesList = list()
     for site in sites["Websites"]["login"]:
         if(Website.checkDuplicateURL(site["url"], loginSitesList)):
             continue
         loginSitesList.append(LoginWebsite(
             site["name"], site["url"], site["id"], site["payload"]))
     loginSitesList = LoginWebsite.garbageCollection(loginSitesList)
     return loginSitesList
 def generateSubscribersList(cls, wantedGroup):
     subscribersList = list()
     data = JSONReader.readJSON(
         JSONReader.stringFromFile(Subscriber.fileLocation))
     for group in data["Groups"]:
         if (group["Name"] == wantedGroup):
             for sub in group["Subscribers"]:
                 subscribersList.append(
                     Subscriber(sub['Name'], sub['Surname'], sub['Email']))
             break
     return subscribersList
Beispiel #6
0
 def garbageCollection(cls, loginSitesList):
     sites = JSONReader.readJSON(
         JSONReader.stringFromFile(Website.locationFile))
     sitesURL = list()
     for site in sites["Websites"]["login"]:
         sitesURL.append(site["url"])
     for site in loginSitesList:
         if(ScrapableWebsite.checkURLs(site.url, sitesURL)):
             continue
         else:
             loginSitesList.remove(site)
     return loginSitesList
Beispiel #7
0
    def buttonPushed(self):
        '''
        Function to execute when the submit button or return key is pushed
        '''

        IDnum = self.lineEdit.text()
        if IDnum == "":
            self.updateStatus("Please Enter an ASU ID", 3)
        else:
            self.updateStatus("Logging...", 0)
            self.lineEdit.setText("")
            if len(IDnum) == 10 and IDnum.isdigit():
                clubName = self.getSelectedRadio()
                self.setSelectedRadio(clubName)
                clubID = None
                for club in JSONReader().getClubList():
                    if JSONReader().getClubNameLong(club) == clubName:
                        clubID = club
                self.updateStatus(sheetReporter.Reporter().log(IDnum, clubID),
                                  3)
            else:
                self.updateStatus("Please Enter an ASU ID", 3)
Beispiel #8
0
    def postSetup(self):
        '''
        Function to be executed after window creation
        '''

        #Comment out this line to give the window a frame (and thus, a close button)
        self.setWindowFlags(Qt.FramelessWindowHint)
        #^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

        frameGeo = self.frameGeometry()
        frameGeo.moveCenter(QDesktopWidget().availableGeometry().center())
        self.move(frameGeo.topLeft())
        # attempt to center the window on screen

        i = 0
        for radio in self.findChildren(QRadioButton):
            #dynamically populate club radio-button list
            try:
                elem = JSONReader().getClubNameLong(
                    JSONReader().getClubList()[i])
                radio.setText(elem)
            except IndexError:
                radio.hide()
            i += 1
Beispiel #9
0
    def USBworker(self):
        '''
        Worker Thread function
        '''
        try:
            self._readerDevice = USBFunc.Reader(device_IDs[0], device_IDs[1])
            self._readerDevice.grabDevice()
        except USBFunc.Reader.InitError as e:
            self.Alert.emit('crit', e.message)
            self._finished.emit()
            return

        while True:
            # retrieve data from card scanner
            # this command will hold execution until data is returned from the  card reader
            keyEvents = self._readerDevice.readData()
            try:
                IDdata = self._readerDevice.interpretEvents(keyEvents)
            except KeyError as e:
                self.Alert.emit('warn', e.message)
            self.updateStatus.emit("Logging...", 0)

            # get ID from regex
            IDnum = self._readerDevice.extractID(IDdata, IDregex)
            if not IDnum:
                # ID was not returned, possibly not ASU ID.
                self.updateStatus.emit("Please Scan only an ASU ID.", 3)
            else:
                # get club Identifier from the Name on the RadioButton
                clubName = self._mainWindow.getSelectedRadio()
                self._mainWindow.setSelectedRadio(clubName)

                # get Long Club Name
                clubID = None
                for club in JSONReader().getClubList():
                    if JSONReader().getClubNameLong(club) == clubName:
                        clubID = club
                        break

                if not JSONReader().getClubAllowed(clubID):
                    # members of this clube are not allowed to sign in
                    self.Alert.emit(
                        'crit',
                        "This club is currently not allowed to register.\n" +
                        "Please see John Alden or your club officers about this."
                    )

                    # clear "Logging..." from the bottom of the window
                    self.updateStatus.emit('', 0)
                else:
                    # report ID and return update
                    try:
                        self.updateStatus.emit(
                            sheetReporter.Reporter().log(IDnum, clubID), 3)
                    except Exception as e:
                        # Theres like...a ton of things that can go wrong here...
                        # Until i can figure them all just throw all errors
                        self.Alert.emit('crit', e.message)
                        self.updateStatus.emit('Nothing logged due to Error',
                                               3)

            # ensure the ID isnt double logged
            IDnum = None
            IDdata = None

        # Should the loop ever exit, ungrab the device and call the worker finish function
        self._finished.emit()
Beispiel #10
0
    def log(self, IDnum, Club):
        '''
        Log the User's ID
        '''
        self._sheetName = "{0}-{1}".format(datetime.today().strftime('%B'),
                                           datetime.today().year)

        # get specific information related to club
        ClubShortName = JSONReader().getClubNameShort(Club)
        ClubRosterID = JSONReader().getRosterID(Club)
        ClubAccessID = JSONReader().getLogID(Club)
        ClubRosterSheet = JSONReader().getMemberSheet(Club)

        # get the next available cell for writing
        try:
            searchList = GAPIFunc.requestRange(self._service, ClubAccessID,
                                               self._sheetName, "A2:A")
            self.nextCell = len(searchList) + 2

            # if the last entry was on a different Day, skip a line
            lastDate = datetime.strptime(searchList[-1][0], _dateFormat)
            if datetime.today().day != lastDate.day:
                self.nextCell += 1

        except GAPIFunc.NoValueReturnedError:
            # No Data in sheet, start fresh, add headers
            GAPIFunc.updateRange(self._service, ClubAccessID, self._sheetName,
                                 _FirstRowDim, [_FirstRow])

            self.nextCell = 2
        except GAPIFunc.InvalidRangeError:
            #sheet doesn't exist, create it and populate it
            GAPIFunc.addSheet(self._service, ClubAccessID, self._sheetName)
            GAPIFunc.updateRange(self._service, ClubAccessID, self._sheetName,
                                 _FirstRowDim, [_FirstRow])

        # get Searchable List of User ID's
        IDlist = GAPIFunc.requestRange(self._service, ClubRosterID,
                                       ClubRosterSheet, _IDColumn)

        # get clocked time of the User
        clockedtime = datetime.now().strftime(_dateFormat)

        # Search IDlist for the user ID
        userRow = None
        for cell in range(0, len(IDlist)):
            # Null cell check to prevent crashing
            if not IDlist[cell]:
                continue
            #
            if IDlist[cell][0] == IDnum:
                userRow = cell + _IDColumnOffset
                break
        retval = None
        if userRow:
            #get user's info
            result = GAPIFunc.requestRange(
                self._service, ClubRosterID, ClubRosterSheet,
                "{0}{2}:{1}{2}".format(_relevantInfo[0], _relevantInfo[1],
                                       userRow))

            # log user to spreadsheet
            GAPIFunc.updateRange(
                self._service, ClubAccessID, self._sheetName,
                "{0}{2}:{1}{2}".format(_timeColumn, _relevantInfo[1],
                                       self.nextCell),
                [[clockedtime] + result[0]])

            retval = "{0} User {1} {2} clocked in at {3}".format(
                ClubShortName, result[0][0], result[0][1], clockedtime)

            if JSONReader().getLastLoginEnabled(Club):
                GAPIFunc.updateRange(
                    self._service, ClubRosterID, ClubRosterSheet,
                    "{0}{1}".format(JSONReader().getLastLoginColumn(Club),
                                    userRow), [[clockedtime]])
        else:
            # log unregistered user to spreadsheet
            GAPIFunc.updateRange(
                self._service, ClubAccessID, self._sheetName,
                "{0}{2}:{1}{2}".format(_timeColumn, _relevantInfo[1],
                                       self.nextCell),
                [[clockedtime, 'Unregistered', '', IDnum]])

            self.nextCell += 1
            retval = "Unregistered user {0} clocked in at {1}".format(
                IDnum, clockedtime)

        return retval
Beispiel #11
0
        output.append("Searches: %s" % (", ".join(searches)))

        for key, value in self.keywords.items():
            output.append("\n %s Results (%d)" % (key, value["freq"]))
            output.append(dashes)
            while not value["posts"].empty():
                q = value["posts"].get()
                output.append("%-70s %s" % (q.title, q.url_ext))
            output.append(dashes)

        return "\n".join(output)


if __name__ == "__main__":
    start = time.time()
    p = initArgParse()

    if len(sys.argv) < 2 or p.num_pages:
        j = JSONReader("data.json")
        c = CraigsList(j.get_region(), j.get_category(), j.get_keywords())

        if p.num_pages:
            c.begin_queries(int(p.num_pages))
        else:
            c.begin_queries()

        print(c)

    end = time.time()
    print("Runtime: %f Seconds" % (end - start))
Beispiel #12
0
    def replyTweets(rootTweet, outputJSON, replyList):

        # With the rootTweet, should be able to get replies
        # Parse rootTweet for the accountName and the tweetID
        rootAccountName = rootTweet.userName
        rootTweetID = rootTweet.tweetID
        rootDate = rootTweet.creationDate

        # pull the data and parse into the various tweets
        currentTweetList = []

        amountOfTweets = 100
        maxID = -1
        genericPath = Config.scriptPath + 'PullReplies.sh'

        # Make sure to start the timer
        stopwatch = Stopwatch()
        stopwatch.startTime()

        iteration = 0
        while (amountOfTweets == 100):

            # Now Pull for tweeets
            os.system(genericPath + ' ' + rootAccountName + ' ' + str(maxID) +
                      ' ' + str(rootTweetID) + ' ' + KeyBank.getKey() + ' ' +
                      outputJSON)

            # Read in the tweets, aka run through the replies proposed
            jsonOutputList = []
            jsonOutputList = JSONReader.setOfReplies(rootTweetID, outputJSON,
                                                     currentTweetList)
            replyList += currentTweetList

            # Determine the amount of tweets
            maxID = jsonOutputList[0] - 1
            amountOfTweets = jsonOutputList[1]

            # check the elapsed time and the iterations
            print("Iteration: " + str(iteration) + ", (Elapsed Time: " +
                  str(stopwatch.elapsedTime()) + ")")
            if ((iteration >= 448 and KeyBank.bankIndex == 0)
                    or iteration >= 449):

                # stop the program until 15 minutes has passed or switch the keys used to access
                KeyBank.changeKeys()

                # might have wrapped around the keybank
                if (stopwatch.elapsedTime() < (15.0 * 60.0)
                        and KeyBank.bankIndex == 0):

                    # If so just sleep the last part of the 15 min
                    fifteen_min = (15 * 60.0) + 30
                    time.sleep(fifteen_min - stopwatch.elapsedTime())

                    # reset the clock
                    stopwatch.startTime()

                # reset the iterations for the next key
                iteration = 0

            # increments and resets
            currentTweetList = []
            iteration += 1
from JSONReader import JSONReader
from PictureSorter import PictureSorter


reader= JSONReader()
jsonData=reader.read()

sorter=PictureSorter(jsonData, reader.getPath())
sorter.sort()



Beispiel #14
0
def MailInfo(path):
    data = JSONReader.stringFromFile(path)
    jsonData = JSONReader.readJSON(data)
    return jsonData["username"], jsonData["password"]