Esempio n. 1
0
def parse_fara_date(date_str):
    try:
        return parse_date(date_str[0:10])
    except ValueError:
        if date_str in ('None', 'None*'):
            return None
        else:
            raise ValueError
Esempio n. 2
0
def parse_fara_date(date_str):
    try:
        return parse_date(date_str[0:10])
    except ValueError:
        if date_str in ('None', 'None*'):
            return None
        else:
            raise ValueError
Esempio n. 3
0
    def make_salt(self, record):
        """
            Return a new salt entry, based on the passed record
        """

        stmt = """SELECT id, contributor as contributor_name, city as contributor_city,
                         state as contributor_state, zipcode as contributor_zipcode
                  FROM salts
                  WHERE nimsp_id = '' AND contributor_state = ?
                  LIMIT 1"""
        self._saltcur.execute(stmt, (record.get('contributor_state', ''), ))
        row = self._saltcur.fetchone()

        if not row:
            #raise ValueError('no more unused salt entries in the database')
            return

        salt = record.copy()
        for f in [
                'contributor_name', 'contributor_city', 'contributor_state',
                'contributor_zipcode'
        ]:
            salt[f] = row[f]
        salt['contributionid'] = 0 - record['contributionid']

        # calculate amount alloted to the new salt
        portion = ensure(Decimal(str(round(record['amount'] / 100))), 10, 500)
        record['amount'] -= portion
        salt['amount'] = portion

        if 'date' in record and record['date'] != "":
            salt['date'] = str(
                parse_date(record['date']) - timedelta(random.randint(15, 45)))
        else:
            salt['date'] = None

        #assign catcode
        salt['contributor_category'] = 'Y0000'  #uncoded

        record_hash = self._dcid_filter.encode(record['contributionid'])
        salt_hash = self._dcid_filter.encode(salt['contributionid'])

        stmt = """UPDATE salts SET nimsp_id = ?, salt_key = ?, record_hash = ?, salt_hash = ?, amount = ?, date = ?, catcode = ? WHERE id = ?"""
        self._saltcur.execute(
            stmt, (record['contributionid'], self._dcid_filter._salt_key,
                   record_hash, salt_hash, str(salt['amount']), salt['date'],
                   salt['contributor_category'], row['id']))
        self._saltcon.commit()

        return salt
Esempio n. 4
0
    def make_salt(self, record):        
        """
            Return a new salt entry, based on the passed record
        """
        
        stmt = """SELECT id, contributor as contributor_name, city as contributor_city,
                         state as contributor_state, zipcode as contributor_zipcode
                  FROM salts
                  WHERE nimsp_id = '' AND contributor_state = ?
                  LIMIT 1"""
        self._saltcur.execute(stmt, (record.get('contributor_state', ''),))
        row = self._saltcur.fetchone()
        
        if not row:
            #raise ValueError('no more unused salt entries in the database')
            return
        
        salt = record.copy()    
        for f in ['contributor_name','contributor_city', 'contributor_state', 'contributor_zipcode']:
            salt[f] = row[f]
        salt['contributionid'] = 0 - record['contributionid']
    
        # calculate amount alloted to the new salt
        portion = ensure(Decimal(str(round(record['amount'] / 100))), 10, 500)
        record['amount'] -= portion
        salt['amount'] = portion
            
        if 'date' in record and record['date'] != "":
            salt['date'] = str(parse_date(record['date']) - timedelta(random.randint(15, 45)))
        else:
            salt['date'] = None
        
        #assign catcode
        salt['contributor_category'] = 'Y0000' #uncoded

        record_hash = self._dcid_filter.encode(record['contributionid'])
        salt_hash = self._dcid_filter.encode(salt['contributionid'])

        stmt = """UPDATE salts SET nimsp_id = ?, salt_key = ?, record_hash = ?, salt_hash = ?, amount = ?, date = ?, catcode = ? WHERE id = ?"""
        self._saltcur.execute(stmt, (record['contributionid'], self._dcid_filter._salt_key, record_hash, salt_hash, str(salt['amount']),  salt['date'], salt['contributor_category'], row['id']))
        self._saltcon.commit()
        
        return salt