Exemplo n.º 1
0
    def handle(self, *args, **kwargs):
        try:
            kbacon = Name.objects.get(name='Kevin Bacon')
        except Name.DoesNotExist:
            kbacon = Name(name='Kevin Bacon')
            kbacon.save()

        for ix, movie in enumerate(self.MOVIES, start=1):
            try:
                name = Name.objects.get(name=movie[0])
            except Name.DoesNotExist:
                name = Name(name=movie[0])
                name.save()

            try:
                duns = DUNS.objects.get(number=str(movie[1]))
            except DUNS.DoesNotExist:
                duns = DUNS(number=str(movie[1]))
                duns.save()

            if FPDS.objects.filter(company_name=name, duns=duns).count() == 0:
                fpds1 = FPDS(company_name=name, duns=duns, fiscal_year=movie[1], data_commons_id=-ix)
                fpds1.save()
                print "%s -> %s" % (movie[1], movie[0])

            if FPDS.objects.filter(company_name=kbacon, duns=duns).count() == 0:
                fpds2 = FPDS(company_name=kbacon, duns=duns, fiscal_year=movie[1], data_commons_id=-len(self.MOVIES)-ix)
                fpds2.save()
                print "Kevin Bacon -> %s" % movie[1]
Exemplo n.º 2
0
    def record(self, dbrow):
        """Transforms each raw table row into data model objects."""
        raw_vndr_name = (
            strip_plus4(dbrow["vendorlegalorganizationname"].strip() or dbrow["vendorname"].strip())
            .decode("utf8")
            .encode("utf8", "replace")
        )
        raw_duns = dbrow["dunsnumber"][:9].strip()
        raw_parent_duns = dbrow["parentdunsnumber"][:9].strip()

        if (
            len(raw_vndr_name) > 0
            and (len(raw_duns) > 0 or len(raw_parent_duns) > 0)
            and dbrow["fiscal_year"] is not None
        ):
            vndr_name = self._name(raw_vndr_name)
            duns = self._duns(raw_duns) if len(raw_duns) > 0 else None
            parent_duns = self._duns(raw_parent_duns) if len(raw_parent_duns) > 0 else None

            fpds = FPDS(data_commons_id=dbrow["id"])
            fpds.unique_transaction_id = dbrow["unique_transaction_id"]
            fpds.duns = duns
            fpds.duns_parent = parent_duns
            fpds.company_name = vndr_name
            fpds.fiscal_year = dbrow["fiscal_year"]
            fpds.piid = dbrow["piid"]
            fpds.psc = dbrow["productorservicecode"]
            fpds.psc_category = dbrow["psc_cat"]
            fpds.save()
Exemplo n.º 3
0
    def record(self, dbrow):
        """Transforms each raw table row into data model objects."""
        raw_vndr_name = strip_plus4(
            dbrow['vendorlegalorganizationname'].strip()
            or dbrow['vendorname'].strip()).decode('utf8').encode(
                'utf8', 'replace')
        raw_duns = dbrow['dunsnumber'][:9].strip()
        raw_parent_duns = dbrow['parentdunsnumber'][:9].strip()

        if len(raw_vndr_name) > 0 and (len(raw_duns) > 0
                                       or len(raw_parent_duns) > 0
                                       ) and dbrow['fiscal_year'] is not None:
            vndr_name = self._name(raw_vndr_name)
            duns = self._duns(raw_duns) if len(raw_duns) > 0 else None
            parent_duns = self._duns(
                raw_parent_duns) if len(raw_parent_duns) > 0 else None

            fpds = FPDS(data_commons_id=dbrow['id'])
            fpds.unique_transaction_id = dbrow['unique_transaction_id']
            fpds.duns = duns
            fpds.duns_parent = parent_duns
            fpds.company_name = vndr_name
            fpds.fiscal_year = dbrow['fiscal_year']
            fpds.piid = dbrow['piid']
            fpds.psc = dbrow['productorservicecode']
            fpds.psc_category = dbrow['psc_cat']
            fpds.save()