示例#1
0
    def add_name(self, name):
        """TODO."""
        name = name.replace(".", "").strip()
        if self.is_this_a_person(name):
            # people with Jr ect at the end of the name are people

            indb = (SESSION.query(Person).filter(Person.name == name).count())

            if indb == 0:
                SESSION.add(Person(name))
                SESSION.commit()
                return

            if indb == 1:
                SESSION.close()
                return

        if self._is_this_a_company(name):
            indb = (SESSION.query(Company).filter(
                Company.name == name).count())

            if indb == 0:
                SESSION.add(Company(name))
                SESSION.commit()
                return

            if indb == 1:
                SESSION.close()
                return

        log.info("Could not link %s", name)

        SESSION.close()
示例#2
0
    def _update_contract_from_document_cloud(self, document_cloud_id, fields):
        """
        Update an existing contract in the local database.

        TODO: compare to add_contract(), because this doesn't update. It adds.

        :param document_cloud_id: The unique ID in DocumentCloud.
        :type document_cloud_id: string
        :param fields: The metadata fields to add along with the contract?
        :type fields: dict
        """
        log.debug('Updating contract in database that has DocumentCloud ID %s',
                  document_cloud_id)

        contract = (SESSION.query(Contract).filter(
            Contract.doc_cloud_id == document_cloud_id).first())

        contract.contractnumber = fields['contractno']
        contract.vendorid = fields['vendor']
        contract.departmentid = fields['department']
        contract.dateadded = fields['dateadded']
        contract.title = fields['title']
        contract.purchaseordernumber = fields['purchaseno']
        contract.description = fields['description']

        SESSION.add(contract)
        SESSION.commit()
示例#3
0
    def _add_contract_to_local_database(self, contract):
        """
        Add a contract to the local database.

        :param contract: The contract to add to our database.
        :type contract: A ___ class instance.
        """
        SESSION.add(contract)
        SESSION.commit()
示例#4
0
    def add_vendor(self, vendor_name):
        """TODO."""
        indb = (SESSION.query(Vendor).filter(
            Vendor.name == vendor_name).count())

        if indb == 0:
            vendor = Vendor(vendor_name.replace(".", ""))
            SESSION.add(vendor)
            SESSION.commit()
        else:
            SESSION.close()
示例#5
0
    def _add_department(self, department):
        """
        Add department to the local database.

        :param meta_field: The department to add to local database.
        :type meta_field: string
        """
        log.debug('Adding department "%s" to database', department)

        SESSION.add(Department(department))
        SESSION.commit()
示例#6
0
    def add_vendor(self, vendor_name):
        """TODO."""
        indb = (SESSION.query(Vendor)
                .filter(Vendor.name == vendor_name)
                .count())

        if indb == 0:
            vendor = Vendor(vendor_name.replace(".", ""))
            SESSION.add(vendor)
            SESSION.commit()
        else:
            SESSION.close()
示例#7
0
    def _add_vendor(self, vendor, vendor_id_city=None):
        """
        Add vendor to the local database.

        :param vendor: The vendor to add to our database.
        :type vendor: string
        """
        log.debug('Adding vendor "%s" to database', vendor)

        vendor = Vendor(vendor, vendor_id_city)

        SESSION.add(vendor)
        SESSION.commit()
示例#8
0
    def link(self, name, vendor):
        """Link the vendor to the company."""
        name = name.strip("\n").replace(".", "").strip()

        # get the vendor:
        vendorindb = (SESSION.query(Vendor)
                      .filter(Vendor.name == vendor)
                      .first())

        # get the person:
        personindb = (SESSION.query(Person)
                      .filter(Person.name == name)
                      .first())

        co = (SESSION.query(Company)
              .filter(Company.name == name))

        companyindb = co.first()  # get the company
        if personindb is not None and companyindb is None:
            link = (SESSION.query(VendorOfficer)
                    .filter(VendorOfficer.vendorid == vendorindb.id)
                    .filter(VendorOfficer.personid == personindb.id)
                    .count())

            if vendorindb is not None and personindb is not None and link < 1:
                log.info("Linking {0} to {1}",
                         str(vendorindb.id), str(personindb.id))
                link = VendorOfficer(vendorindb.id, personindb.id)
                SESSION.add(link)
                SESSION.commit()
                return

        if companyindb is not None and personindb is None:
            link = (SESSION.query(VendorOfficerCompany)
                    .filter(VendorOfficerCompany.vendorid == vendorindb.id)
                    .filter(VendorOfficerCompany.companiesid == companyindb.id)
                    .count())

            if vendorindb is not None and companyindb is not None and link < 1:
                print("Linking {0} to {1}".format(
                    str(vendorindb.id), str(companyindb.id)
                ))
                link = VendorOfficerCompany(vendorindb.id, companyindb.id)
                SESSION.add(link)
                SESSION.commit()
                return

        SESSION.close()
示例#9
0
    def update_scrape_log(self, page):
        """TODO."""
        query = (SESSION.query(ScrapeLog).filter(ScrapeLog.page == page).all())

        if len(query) == 0:  # No row yet for this page (total number varies)
            # Add this page to database
            scrape_info = ScrapeLog(page, TODAY_DATE)
            SESSION.add(scrape_info)
            SESSION.commit()
        else:
            # Update this page in the database
            update_query = (SESSION.query(ScrapeLog).filter(
                ScrapeLog.page == page).one())

            update_query.last_scraped = TODAY_DATE
            SESSION.commit()
示例#10
0
    def link(self, name, vendor):
        """Link the vendor to the company."""
        name = name.strip("\n").replace(".", "").strip()

        # get the vendor:
        vendorindb = (SESSION.query(Vendor).filter(
            Vendor.name == vendor).first())

        # get the person:
        personindb = (SESSION.query(Person).filter(
            Person.name == name).first())

        co = (SESSION.query(Company).filter(Company.name == name))

        companyindb = co.first()  # get the company
        if personindb is not None and companyindb is None:
            link = (SESSION.query(VendorOfficer).filter(
                VendorOfficer.vendorid == vendorindb.id).filter(
                    VendorOfficer.personid == personindb.id).count())

            if vendorindb is not None and personindb is not None and link < 1:
                log.info("Linking {0} to {1}", str(vendorindb.id),
                         str(personindb.id))
                link = VendorOfficer(vendorindb.id, personindb.id)
                SESSION.add(link)
                SESSION.commit()
                return

        if companyindb is not None and personindb is None:
            link = (SESSION.query(VendorOfficerCompany).filter(
                VendorOfficerCompany.vendorid == vendorindb.id).filter(
                    VendorOfficerCompany.companiesid ==
                    companyindb.id).count())

            if vendorindb is not None and companyindb is not None and link < 1:
                print("Linking {0} to {1}".format(str(vendorindb.id),
                                                  str(companyindb.id)))
                link = VendorOfficerCompany(vendorindb.id, companyindb.id)
                SESSION.add(link)
                SESSION.commit()
                return

        SESSION.close()
示例#11
0
    def add_name(self, name):
        """TODO."""
        name = name.replace(".", "").strip()
        if self.is_this_a_person(name):
            # people with Jr ect at the end of the name are people

            indb = (SESSION.query(Person)
                    .filter(Person.name == name)
                    .count())

            if indb == 0:
                SESSION.add(Person(name))
                SESSION.commit()
                return

            if indb == 1:
                SESSION.close()
                return

        if self._is_this_a_company(name):
            indb = (SESSION.query(Company)
                    .filter(Company.name == name)
                    .count())

            if indb == 0:
                SESSION.add(Company(name))
                SESSION.commit()
                return

            if indb == 1:
                SESSION.close()
                return

        log.info("Could not link %s", name)

        SESSION.close()