Exemple #1
0
def main():
    armor = Armor(start_date_in_current_exhibition=Date(1, 1, 2001))
    vase = Vase(start_date_in_current_exhibition=Date(2, 1, 2003))
    crown = Crown(start_date_in_current_exhibition=Date(5, 3, 2007))
    painting = Painting(start_date_in_current_exhibition=Date(6, 9, 2011))

    list_of_exhibits = [painting, vase, crown, armor]
    manager = ExhibitManager(list_of_exhibits)

    manager.find_by_theme(Topic.ANCIENT_ROME)
    manager.print_exhibit_list_info()
    manager.sort_by_age()
    manager.print_exhibit_list_info()
    manager.sort_by_date_in_current_exhibition()
    manager.print_exhibit_list_info()
def get_date(properties):  # TODO : refactor this
    if len(properties) == 0:
        return None
    data_property = properties[0]
    if not 'datavalue' in data_property['mainsnak']:
        return None
    precision = data_property['mainsnak']['datavalue']['value']['precision']
    time = data_property['mainsnak']['datavalue']['value']['time']
    if precision < 9:
        return None
    return Date(time[1:5])
Exemple #3
0
 def __init__(self,
              name="some_exhibit",
              portable=True,
              century_of_creation=0,
              country_of_creation="Italy",
              size=3,
              popularity=InterestedPeople.TWO,
              theme=Topic.ANCIENT_GREECE,
              destroyed_in_persentage=20,
              start_date_in_current_exhibition=Date(1, 1, 2020),
              made_of_metal=True,
              pattern=False):
     super().__init__(name, portable, century_of_creation,
                      country_of_creation, size, popularity, theme,
                      destroyed_in_persentage,
                      start_date_in_current_exhibition)
     self.made_of_metal = made_of_metal
     self.pattern = pattern
Exemple #4
0
 def __init__(self,
              name="some_exhibit",
              portable=True,
              century_of_creation=0,
              country_of_creation="Italy",
              size=3,
              popularity=InterestedPeople.TWO,
              theme=Topic.ANCIENT_GREECE,
              destroyed_in_persentage=20,
              start_date_in_current_exhibition=Date(2, 1, 2050),
              insertion=True,
              number_of_diamonds=18):
     super().__init__(name, portable, century_of_creation,
                      country_of_creation, size, popularity, theme,
                      destroyed_in_persentage,
                      start_date_in_current_exhibition)
     self.insertion = insertion
     self.number_of_diamonds = number_of_diamonds
Exemple #5
0
 def __init__(self,
              name="some_exhibit",
              portable=True,
              century_of_creation=12,
              country_of_creation="Italy",
              size=3,
              popularity=InterestedPeople.TWO,
              theme=Topic.ANCIENT_ROME,
              destroyed_in_persentage=20,
              start_date_in_current_exhibition=Date(4, 1, 2007),
              material="metal",
              painted=True):
     super().__init__(name, portable, century_of_creation,
                      country_of_creation, size, popularity, theme,
                      destroyed_in_persentage,
                      start_date_in_current_exhibition)
     self.material = material
     self.painted = painted
Exemple #6
0
 def __init__(self,
              name="some_exhibit",
              portable=True,
              century_of_creation=0,
              country_of_creation="Italy",
              size=3,
              popularity=InterestedPeople.TWO,
              theme=Topic.ANCIENT_ROME,
              destroyed_in_persentage=20,
              start_date_in_current_exhibition=Date(3, 1, 2007),
              painting_style=Style.ABSTRACT_ART,
              frame=True):
     super().__init__(name, portable, century_of_creation,
                      country_of_creation, size, popularity, theme,
                      destroyed_in_persentage,
                      start_date_in_current_exhibition)
     self.painting_style = painting_style
     self.frame = frame
Exemple #7
0
 def __init__(self,
              name="some_exhibit",
              portable=True,
              century_of_creation=0,
              country_of_creation="Italy",
              size=3,
              popularity=InterestedPeople.TWO,
              theme=Topic.ANCIENT_ROME,
              destroyed_in_persentage=20,
              start_date_in_current_exhibition=Date()):
     self.name = name
     self.portable = portable
     self.century_of_creation = century_of_creation
     self.country_of_creation = country_of_creation
     self.size = size
     self.popularity = popularity
     self.theme = theme
     self.destroyed_in_persentage = destroyed_in_persentage
     self.start_date_in_current_exhibition = start_date_in_current_exhibition
def saveInmateProfile(browser):
    inmate = Inmate()  # inmate profile
    record = InmateRecord()  # inmate current record
    facility = Facility()

    # find inmate ID, will go in active record
    time.sleep(2)

    element = browser.find_elements_by_class_name("section_data")

    backgroundPersonInfo = BeautifulSoup(element[1].get_attribute('innerHTML'), 'html.parser').find("tbody").find("tbody")
    personInfoCells = backgroundPersonInfo.find_all("tr")

    for ind in range(len(personInfoCells)):
        cell = personInfoCells[ind]
        if not isinstance(cell, NavigableString):
            txt = " ".join(cell.text.strip().split())

            if "Name" in txt:
                fullName = txt.replace(",", "").split(" ")
                lastName = fullName[1]
                firstName = fullName[2]
                middleName = fullName[-1] if len(fullName) == 4 else None
                inmate.name = Name(firstName, middleName, lastName)
            elif "Age" in txt:
                inmate.age = txt.split(" ")[-1]
                inmate.DOB = Date(inmate.age, None, None, True)
            elif "Gender" in txt:
                inmate.sex = txt.split(" ")[-1]
            elif "Ethnicity" in txt:
                inmate.race = txt.split(" ")[-1]
            elif "Hair Color" in txt:
                inmate.hairColor = txt.split(" ")[-1]
            elif "Eye Color" in txt:
                inmate.eyeColor = txt.split(" ")[-1]
            elif "Height" in txt:
                inmate.height = txt.split(" ")[-2] + txt.split(" ")[-1]
            elif "Weight" in txt:
                inmate.weight = txt.split(" ")[-1]

    backgroundPersonPrisonInfo = backgroundPersonInfo.find_next("tbody")
    personPrisonInfoCells = backgroundPersonPrisonInfo.find_all("tr")

    for ind in range(len(personPrisonInfoCells)):
        cell = personPrisonInfoCells[ind]
        if not isinstance(cell, NavigableString):
            txt = " ".join(cell.text.strip().split())

            if "DOC Number" in txt:
                # inmate's id given by Colorado Department of Corrections
                record.recordNumber = txt.split(" ")[-1]
            elif "Est. Parole Eligibility Date" in txt:
                dateSplit = txt.split(" ")[-1].split("/")
                if len(dateSplit) > 1:
                    record.paroleEligibilityDate = Date(dateSplit[-1], dateSplit[0], dateSplit[1])
            elif "Next Parole Hearing Date" in txt:
                dateSplit = txt.split(":")
                if len(dateSplit) > 1:
                    record.nextParoleHearingDate = dateSplit[-1].strip()
            elif "Est. Sentence Discharge Date" in txt:
                dateSplit = txt.split(" ")[-1].split("/")
                if len(dateSplit) > 1:
                    record.estReleaseDate = Date(dateSplit[-1], dateSplit[0], dateSplit[1])
            elif "Current Facility Assignment" in txt:
                facility.name = txt.split(":")[-1].strip()

    # saves profile to the database
    writeToDB(inmate)
    browser.find_element_by_id("btn_search_txt").click()
    return inmate.name.first + " " + inmate.name.last
Exemple #9
0
def saveInmateProfile(soup, browser):
    inmate = Inmate()  # inmate profile
    record = InmateRecord()  # inmate current record
    record.state = "GA"
    facility = Facility()

    inmateID = soup.find(
        'h5', text=re.compile('GDC ID:.*')).get_text().strip().split()[
            -1]  # find inmate ID, will go in active record

    # find inmate name
    name = soup.find(
        'h4', text=re.compile('NAME:.*')).get_text().strip('NAME:').strip()
    # finds text that includes "NAME:", for example; regex
    lastName, firstNames = name.split(
        ',')  # only if "last, first" order; otherwise vice versa
    firstNames = firstNames.split()
    firstName = firstNames[0]
    middleName = "" if len(firstNames[1:]) == 0 else " ".join(firstNames[1:])
    inmate.name = Name(firstName, middleName, lastName)

    # find way to parse and collect rest of info; will vary with different crawlers

    info = soup.findAll('p')
    caseNumbers = [
        x.text.strip('CASE NO:').strip() for x in soup.findAll('h7')
    ]
    recordCounter = 0
    for row in info:
        if row and 'class="offender"' in str(row):
            data = row.text.split('\n')
            data = map(str.strip, data)
            data = list(filter(None, data))

            # past convictions
            if any("SENTENCE LENGTH" in s for s in data):

                for info in data:
                    try:
                        entry, value = info.split(': ')
                    except:
                        continue
                    if entry == 'OFFENSE':
                        past_record = InmateRecord()
                        past_record.inmateNumber = inmateID
                        past_record.status = RecordStatus.INACTIVE
                        past_record.state = "GA"
                        past_record.offense = value
                    elif entry == 'CRIME COMMIT DATE':
                        past_record.sentenceDate = Date(value)
                    elif entry == 'SENTENCE LENGTH':
                        past_record.estReleaseDate = past_record.sentenceDate
                        try:
                            (paramY, paramM, paramD) = [
                                int(x.strip().split()[0])
                                for x in value.split(",")
                            ]
                        except (ValueError):
                            (paramY, paramM, paramD) = (None, None, None)
                        past_record.estReleaseDate.addTime(
                            paramY, paramM, paramD)
                        past_record.estReleaseDate.estimated = True
                        past_record.recordNumber = caseNumbers[recordCounter]
                        inmate.addRecord(past_record)
                        recordCounter += 1

            # information about current conviction
            else:
                for trait in data:
                    try:
                        entry, value = trait.split(': ')
                    except:
                        continue
                    if entry == 'RACE':
                        inmate.race = value
                    elif entry == 'GENDER':
                        inmate.sex = value
                    elif entry == 'HEIGHT':
                        inmate.height = value
                    elif entry == 'EYE COLOR':
                        inmate.eyeColor = value
                    elif entry == 'YOB':
                        inmate.DOB = Date(value)
                    elif entry == 'WEIGHT':
                        inmate.weight = value
                    elif entry == 'HAIR COLOR':
                        inmate.hairColor = value
                    elif entry == 'MOST RECENT INSTITUTION':
                        facility.name = value
                        facility.state = record.state
                        facility.getGeneratedID()
                        record.addFacility(facility)
                    elif entry == 'MAX POSSIBLE RELEASE DATE':
                        record.maxReleaseDate = Date(value)
                        record.status = RecordStatus.ACTIVE
            record.recordNumber = caseNumbers[0]
            record.status = RecordStatus.ACTIVE
            record.inmateNumber = inmateID
            inmate.addRecord(record)

    # saves profile to the database
    writeToDB(inmate)

    # click back button
    browser.find_element_by_xpath(
        "//a[text()=' Return to previous screen']").click()

    return name
Exemple #10
0
    def getDict(self):
        if (not isinstance(self.admissionDate, Date)
                and self.admissionDate is not None):
            self.admissionDate = Date(self.admissionDate.year,
                                      self.admissionDate.month,
                                      self.admissionDate.day)
        if (not isinstance(self.sentenceDate, Date)
                and self.sentenceDate is not None):
            self.sentenceDate = Date(self.sentenceDate.year,
                                     self.sentenceDate.month,
                                     self.sentenceDate.day)
        if (not isinstance(self.maxReleaseDate, Date)
                and self.maxReleaseDate is not None):
            self.maxReleaseDate = Date(self.maxReleaseDate.year,
                                       self.maxReleaseDate.month,
                                       self.maxReleaseDate.day)
        if (not isinstance(self.admissionDate, Date)
                and self.estReleaseDate is not None):
            self.estReleaseDate = Date(self.estReleaseDate.year,
                                       self.estReleaseDate.month,
                                       self.estReleaseDate.day)

        return {
            "_id":
            self.generatedID if self.generatedID is not None else
            generate_record_id(self.state, self.recordNumber),  # db key!
            "inmateID":
            self.inmateId,  # db key!
            "recordNumber":
            self.recordNumber,
            "admissionDate":
            self.admissionDate.getDict()
            if self.admissionDate is not None else None,
            "sentenceDate":
            self.sentenceDate.getDict()
            if self.sentenceDate is not None else None,
            "maxReleaseDate":
            self.maxReleaseDate.getDict()
            if self.maxReleaseDate is not None else None,
            "estReleaseDate":
            self.estReleaseDate.getDict()
            if self.estReleaseDate is not None else None,
            "paroleEligibilityDate":
            self.paroleEligibilityDate,
            "nextParoleHearingDate":
            self.nextParoleHearingDate,
            "facilityID":
            self.facility.getGeneratedID(),  # db key!
            "state":
            self.state,
            "county":
            self.county,
            "bondAmt":
            self.bondAmt,
            "status":
            self.status.value,
            "supervisionStatus":
            self.currentSupervisionStatus,
            "offense":
            self.offense,
        }
Exemple #11
0
class InmateRecord:
    status = RecordStatus

    def __init__(self):
        self.generatedID = ""
        self.recordNumber = None  # db key! This is the value (usually 6 characters) that is used by every database
        self.inmateId = None  # optional number that may be found on some databases
        self.admissionDate = None
        self.sentenceDate = None
        self.maxReleaseDate = None
        self.estReleaseDate = None
        self.paroleEligibilityDate = None
        self.nextParoleHearingDate = None
        self.facility = None
        self.state = None
        self.county = None
        self.bondAmt = None
        self.status = RecordStatus.UNDEFINED
        self.currentSupervisionStatus = None
        self.offense = ""

    def __str__(self):
        return str(self.getDict())

    def __setattr__(self, name, value):
        if name == 'status' and not isinstance(value, RecordStatus):
            raise TypeError('Status must be of type RecordStatus')
        super().__setattr__(name, value)

    def getGeneratedID(self):
        if (len(self.generatedID) == 0):
            self.generatedID = generate_record_id(self.state,
                                                  self.recordNumber)
        return self.generatedID

    def getDict(self):
        if (not isinstance(self.admissionDate, Date)
                and self.admissionDate is not None):
            self.admissionDate = Date(self.admissionDate.year,
                                      self.admissionDate.month,
                                      self.admissionDate.day)
        if (not isinstance(self.sentenceDate, Date)
                and self.sentenceDate is not None):
            self.sentenceDate = Date(self.sentenceDate.year,
                                     self.sentenceDate.month,
                                     self.sentenceDate.day)
        if (not isinstance(self.maxReleaseDate, Date)
                and self.maxReleaseDate is not None):
            self.maxReleaseDate = Date(self.maxReleaseDate.year,
                                       self.maxReleaseDate.month,
                                       self.maxReleaseDate.day)
        if (not isinstance(self.admissionDate, Date)
                and self.estReleaseDate is not None):
            self.estReleaseDate = Date(self.estReleaseDate.year,
                                       self.estReleaseDate.month,
                                       self.estReleaseDate.day)

        return {
            "_id":
            self.generatedID if self.generatedID is not None else
            generate_record_id(self.state, self.recordNumber),  # db key!
            "inmateID":
            self.inmateId,  # db key!
            "recordNumber":
            self.recordNumber,
            "admissionDate":
            self.admissionDate.getDict()
            if self.admissionDate is not None else None,
            "sentenceDate":
            self.sentenceDate.getDict()
            if self.sentenceDate is not None else None,
            "maxReleaseDate":
            self.maxReleaseDate.getDict()
            if self.maxReleaseDate is not None else None,
            "estReleaseDate":
            self.estReleaseDate.getDict()
            if self.estReleaseDate is not None else None,
            "paroleEligibilityDate":
            self.paroleEligibilityDate,
            "nextParoleHearingDate":
            self.nextParoleHearingDate,
            "facilityID":
            self.facility.getGeneratedID(),  # db key!
            "state":
            self.state,
            "county":
            self.county,
            "bondAmt":
            self.bondAmt,
            "status":
            self.status.value,
            "supervisionStatus":
            self.currentSupervisionStatus,
            "offense":
            self.offense,
        }

    def addFacility(self, facility):
        self.facility = facility
def saveInmateProfile(soup, browser):
    inmate = Inmate()  # inmate profile
    record = InmateRecord()  # inmate current record
    record.state = "Alabama"
    facility = Facility()  # current facility info

    # inmate id specific to alabama
    inmateID = soup.find(id="MainContent_DetailsView2_Label2").get_text()

    # find name element
    name = soup.find(id="MainContent_DetailsView2_Label1").get_text()
    lastName, firstNames = name.split(',')
    firstNames = firstNames.split()
    firstName = firstNames[0]
    middleName = "" if len(firstNames[1:]) == 0 else " ".join(firstNames[1:])

    # add name to inmate object
    inmate.name = Name(firstName, middleName, lastName)

    # get info off profile pages
    info = soup.findAll('table')

    # facility names
    facility.name = info[0].find(
        id="MainContent_DetailsView2_Label3").get_text()
    facility.state = record.state
    # record.facilityID = facility.generatedID

    # recordCounter = 0

    for i in range(1, len(info)):
        count = 0
        for row in info[i]:
            # skip first dummy row
            if count != 1:
                count += 1
            else:
                currentRecord = False
                for trait in row:
                    if i == 1:
                        try:
                            lines = trait.text.split("\n")
                            traits = lines[1].split(":")
                        except AttributeError:
                            continue
                        if traits[0] == "Race":
                            inmate.race = traits[1]
                        elif traits[0] == "Sex":
                            inmate.sex = traits[1]
                        elif traits[0] == "Hair Color":
                            inmate.hairColor = traits[1]
                        elif traits[0] == "Eye Color":
                            inmate.eyeColor = traits[1]
                        elif traits[0] == "Height":
                            inmate.height = traits[1]
                        elif traits[0] == "Birth Year":
                            inmate.DOB = Date(traits[1], None, None, True)
                        elif traits[0] == "Sex":
                            inmate.sex = traits[1]
                    elif i == 2:
                        # print('NEW ROW')
                        # print(trait)
                        try:
                            lines = trait.text.split("\n")
                            traits = lines[1].split(" ")
                            print(traits)
                        except AttributeError:
                            continue

    # save profile to the database
    writeToDB(inmate)

    browser.set_page_load_timeout(10)

    # need way to get back to original search list results
    # EX: browser.find_element_by_xpath("//a[text()=' Return to previous screen']").click()

    return name


# TESTS:
# baseCrawler("Adams", "")