def storeState(): """Inserts the state of the teapot into the database Args: - state (string) - The current state of the teapot - timestamp (string) - The time that this state happened - num_of_cups (int) - The number of cups left in the teapot Returns - 200 """ data = json.loads(request.data) State.create(state=data["state"], timestamp=datetime.strptime(data["timestamp"], "%Y-%m-%dT%H:%M:%S.%f"), num_of_cups=data["num_of_cups"], weight=data.get("weight", -1), temperature=data.get("temperature", 1)) return Response()
def bootstrap_president(): """ Creates/overwrites presidential state results with initial data. """ with open('initial_data/president_bootstrap.csv') as f: reader = csv.DictReader(f) for row in reader: for field in ['total_precincts', 'precincts_reporting', 'rep_vote_count', 'dem_vote_count']: if row[field] == '': row[field] = 0 try: state = State.select().where( State.id == row['id'] ).get() state.update(**row) except State.DoesNotExist: state = State.create(**row) state.save()
def bootstrap_president(): """ Creates/overwrites presidential state results with initial data. """ with open('initial_data/president_bootstrap.csv') as f: reader = csv.DictReader(f) for row in reader: for field in [ 'total_precincts', 'precincts_reporting', 'rep_vote_count', 'dem_vote_count' ]: if row[field] == '': row[field] = 0 try: state = State.select().where(State.id == row['id']).get() state.update(**row) except State.DoesNotExist: state = State.create(**row) state.save()