예제 #1
0
    def __init__(self, path):
        self.path = path

        i = 1
        with open(path) as f:
            for line in f:
                app.log('contrib: {}'.format(i), level=5)
                contribution_record = dict(
                    zip(self.keys, [x.strip() for x in line.split('|')]))

                if contribution_record['STATE'] == 'CA' and contribution_record[
                        'CITY'] == 'LONG BEACH':

                    try:
                        this_contrib = Contribution(**contribution_record)
                        this_committee = Committee.get(
                            CMTE_ID=this_contrib.CMTE_ID)
                        this_contrib.committee = this_committee

                        if i % app.BATCH_SIZE == 0:
                            app.log('commit!', level=3)
                            pony.commit()
                    except pony.core.CacheIndexError:
                        pass
                    except pony.core.TransactionIntegrityError:
                        pass

                i += 1

        try:
            pony.commit()
        except pony.core.CacheIndexError:
            pass
        except pony.core.TransactionIntegrityError:
            pass
예제 #2
0
def ingest(filepath):
    '''Ingest file into database'''

    print "Ingesting %s" % filepath
    rows_in_file = parse_fec_file(filepath)
    myfile = File.get_or_create(name=filepath)
    myfile_id = myfile.id

    with db.transaction(): # TODO: More sane error handling
        for idx in range(0, len(rows_in_file), 500):

            # Ingest 500 rows at a time
            print "Inserting row %d of %s" % (idx, filepath)
            rows_subset = rows_in_file[idx:idx+500]
            rows_to_insert = []

            for row in rows_subset:
                unsaved_new_contribution = Contribution(**row_to_dict(row))
                import pdb; pdb.set_trace()
                # If the row isn't already there, insert it
                if :
                    pass
                # If the row is there, check for modifications
                elif:
                    # If it has not been modified, simply add a ContributionHistory object
                    if:
                    # If it has been modified, create a new object and give the new object a contribution history
                    else:
                        pass

            Contribution.insert_many(rows_subset).execute()
예제 #3
0
def create_test_contribution(funder_id, land_listing_id, fund_id):
    contribution = Contribution(funder_id=funder_id,
                                land_listing_id=land_listing_id,
                                fund_id=fund_id,
                                date=datetime.date.today(),
                                amount=10.25)
    contribution.insert()

    return str(contribution.id)
예제 #4
0
    def __init__(self, filename, delimiter, field_names, field_idx):
        self.callbacks = None
        self.filename = filename
        self.field_names = field_names
        self.field_idx = field_idx
        self.delimiter = delimiter

        # creating contribution object
        self.contribution = Contribution(self.delimiter, self.field_names,
                                         self.field_idx)
예제 #5
0
 def post(self, title_id):
     try:
         args = self.parser.parse_args()
         edit_id = args['edit_id']
         title = args['title']
         year = args['year']
         description = args['description']
         plot = args['plot']
         user = parse_jwt(request.headers['Authorization'])
         print(args)
         m = Contribution(
             title_id=title_id,
             title=title,
             year=year,
             email=user['email'],
             description=description,
             plot=plot,
             edit_id=edit_id)
         m.save()
         return {"message": "Saved successfuly"}, 200
     except Exception as e:
         print(e)
         return {"message": "An error occured"}, 401
예제 #6
0
    def contribute_to_fund(land_listing_id, fund_id):
        body = request.get_json()
        amount = body.get('amount', None)
        funder_id = body.get('funder_id', None)

        try:
            amount = float(amount)
        except Exception:
            abort(422)

        land_listing = LandListing.query.get(land_listing_id)
        fund = Fund.query.get(fund_id)
        funder = Funder.query.get(funder_id)

        if (land_listing is None) or (fund is None) or (funder is None):
            abort(404)

        land_listing_fund_ids = [fund.id for fund in land_listing.funds]

        if fund_id not in land_listing_fund_ids:
            abort(422)

        try:
            new_contribution = Contribution(funder_id=funder.id,
                                            land_listing_id=land_listing.id,
                                            fund_id=fund.id,
                                            date=datetime.date.today(),
                                            amount=amount)
            new_contribution.insert()

            return jsonify({
                'success': True,
                'contribution': new_contribution.format(),
            }), 200

        except Exception:
            abort(422)