def add_share(): json = request.get_json() share = Share() for field in json: setattr(share, field, json.get(field)) share.save() return jsonify(share=share.json), 201
def main(path): """ Reads all csv files in given path and creates `Share` entries in the database for them """ files = os.listdir(path) for file in files: fullpath = os.path.join(path, file) with open(fullpath) as infile: data = csv.reader(infile, delimiter=';') next(data) # skip header for line in data: value = line[-1] station = line[-2] name = " & ".join([name for name in line[:-2] if name]) db_station = Station.get_by_name(station) if db_station is None: new_station = Station(name=station) new_station.save() db_station = new_station share = Share(name=name, station=db_station, bet_value=float(value.replace(",", "."))) share.save() print(value, station, name)
def member_create(): json = request.get_json() share_id = json.get("share_id") if not share_id: share = Share() share.save() share_id = share.id member = Member(name=json.get("name"), email=json.get("email"), phone=json.get("phone"), share_id=share_id) member.save() return jsonify(member=member.json)
def shares_details(share_id): share = Share.get(share_id) dict_share = share.json dict_share['expected_today'] = share.expected_today dict_share['total_deposits'] = share.total_deposits or 0 dict_share['difference_today'] = - (Decimal(dict_share['expected_today']) - dict_share['total_deposits']) return jsonify(share=dict_share)
def post_shares_details(share_id): share = Share.get(share_id) json = request.get_json() for field in ["station_id", "note", "archived"]: if field in json: setattr(share, field, json.get(field)) share.save() resp = share.json return jsonify(share=resp)
def test_create_member(self): member1 = MemberFactory.create(name="Paul Wild / Paula Wilder") share = ShareFactory.create(members=[member1]) self.assertEqual(len(share.members), 1) new_member_json = {"name": "Paul Wild", "share_id": share.id} response: Response = self.app.post(f"/api/v1/members", json=new_member_json) updated_share = Share.get(share.id) self.assertEqual(response.status_code, 200) self.assertEqual(len(updated_share.members), 2)
def save_transaction(transaction): title = transaction.data.get('purpose') name = transaction.data.get('applicant_name') date = transaction.data.get('date') amount = transaction.data.get('amount') value = Decimal(amount.amount) if value > 0: person = Person.get_or_create(name) deposit = Deposit(amount=value, timestamp=date, person=person, title=clean_title(title)) deposit.save() if person.share_id is None: member = Member(name=name) member.save() share = Share() share.people.append(person) share.members.append(member) share.save()
def import_deposits(data): for line in data: value = float(line["Betrag"].replace(".", "").replace(",", ".")) date = datetime.strptime(line["Buchungstag"], "%d.%m.%Y") keys = ["VWZ%i" % i for i in range(1, 15)] title = "".join([line[key] for key in keys]) name = line["Auftraggeber/Empf\xe4nger"] if value > 0: person = Person.get_or_create(name) deposit = Deposit(amount=value, timestamp=date, person=person, title=title) deposit.save() if person.share_id is None: member = Member(name=name) member.save() share = Share() share.people.append(person) share.members.append(member) share.save()
def share_deposits(share_id): deposits = Share.get_deposits(share_id) return jsonify(deposits=deposits)
def share_email_list(share_id): share = Share.get(share_id) return jsonify(emails=[member.email for member in share.members])
def share_bets(share_id): bets = Share.get_bets(share_id) return jsonify(bets=bets)