def calendar_events(): d1 = datetime.date(2020, 2, 1) d2 = datetime.date(2020, 2, 1) e1 = models.Event('event 1', d1, d2, 'location 1') d1 = datetime.date(2019, 12, 1) d2 = datetime.date(2020, 3, 2) e2 = models.Event('event 2', d1, d2, 'location 2') d1 = datetime.date(2019, 12, 2) d2 = datetime.date(2020, 3, 2) e3 = models.Event('event 2', d1, d2, 'location 2') d1 = datetime.datetime(2020, 2, 1, 8, 10, 0) d2 = datetime.datetime(2020, 2, 1, 9, 10, 0) e4 = models.Event('event 1', d1, d2, 'location 1') d1 = datetime.datetime(2020, 2, 3, 8, 10, 0) d2 = datetime.datetime(2020, 2, 3, 9, 10, 0) e5 = models.Event('event 1', d1, d2, 'location 1') events = [e1, e2, e3] events_without_time = [e4, e5] return events, events_without_time
def addEvent(): if not request.json or not 'event' in request.json: abort(400) userKey = request.authorization.username sessionID = getLatestSession(userKey) addedEvent = [] for entry in request.json['event']: npcID = int(entry['npcID']) typeID = entry['typeID'] location = entry['location'] if 'timestamp' in entry: timestampMS = int(entry['timestamp']) timestamp = datetime.fromtimestamp(timestampMS / 1000.0) else: timestamp = None event = models.Event(userKey=userKey, sessionID=sessionID, npcID=npcID, typeID=typeID, timeStamp=timestamp, location=location) db.session.add(event) addedEvent.append({'event': event.typeID, 'npc': event.npcID}) db.session.commit() return jsonify({'events': addedEvent}), 201
def post(self): """ Create an event. Required json data: lat: latitude lng: longtitude name: short name description: detailed description date: date of event tags: list of tags of this event :return: """ data = request.get_json() creator_id = get_jwt_identity().get('id') name = data.get('name') date_time = data.get('date_time') desc = data.get('desc', '') coords = data.get('coords') if not all([creator_id, name, date_time, coords]): return abort(400, 'Bad params.') event = models.Event(creator_id, name, date_time, coords, desc=desc) db.session.add(event) db.session.commit() return {'id': event.id}, 201
def fill_samples(): from datetime import datetime # User user = models.User('Test', '*****@*****.**', '1234567890') db.session.add(user) db.session.commit() # Events event1 = models.Event(1, 'sample event 1', datetime.now().timestamp(), [55.74, 37.61], 'description 1') event2 = models.Event(1, 'sample event 2', datetime.now().timestamp(), [55.75, 37.63], 'description 2') event3 = models.Event(1, 'sample event 3', datetime.now().timestamp(), [55.75, 37.61], 'description 3') event4 = models.Event(1, 'sample event 4', datetime.now().timestamp(), [55.74, 37.63], 'description 4') for e in (event1, event2, event3, event4): db.session.add(e) db.session.commit() # Route route = models.Route(1, 'sample route', 'route description') db.session.add(route) db.session.commit() point1 = models.Point([55.74, 37.61], route.id) point2 = models.Point([55.75, 37.61], route.id) point3 = models.Point([55.75, 37.63], route.id) point4 = models.Point([55.74, 37.63], route.id) for p in (point1, point2, point3, point4): db.session.add(p) route.set_points([point1, point2, point3, point4]) db.session.add(route) db.session.commit()
def create_event(username): if request.method == "POST": json = request.get_json() headline = json.get("headline") date = json.get("date") description = json.get("description") args = [headline, date, description] user = get_user(db, username) if None not in args and user is not None: if session.get("user_id") == str(user.get("_id")): add_event(db, models.Event(*args, str(user.get("_id")))) return "Event created" else: return "Not logged in" return "Could not create event"
def newactivity(titleid): if request.method == 'POST': data = request.form print (data,sys.stderr) phase = db.session.query(models.Phase,models.Has).join(models.Has, models.Phase.phaseid == models.Has.phaseid).filter(models.Has.titleid == titleid, models.Phase.current == True).first() actid = genID() name = data['name'] startdate = data['startdate'] duration = data['duration'] completed = False if 'starttime' in data: starttime = data['starttime'] endtime = data['endtime'] venue = data['venue'] activity = models.Event(activityid=actid,name=name,startdate=startdate,duration=duration,completed=completed,starttime=starttime,endtime=endtime,venue=venue) else: activity = models.Activity(activityid=actid,name=name,startdate=startdate,duration=duration,completed=completed) consists_of = models.Consists_Of(phaseid=phase.Phase.phaseid,activityid=activity.activityid) db.create_all() db.session.add(activity) db.session.add(consists_of) db.session.commit() return redirect(url_for('activity',activityid=actid)) return render_template('newactivity.html',titleid=titleid)
def createApplication(addFixtures=False): """This method initializes the flask application and set the configuration (hard coded to use dev only for now). @param bool addFixtures: This is a one time setup used for demo purposes to populated some data in sqlite so that the GETs work right away @return flask.Application: returns the configured flask application instance """ myApp.config.from_object(DevConfig()) db.init_app(myApp) migrate = Migrate(myApp, db) from app import models # For demo puposes only, if you are happy to call a bunch of POSTs before checking the GETs # out then this can be deleted. if addFixtures: with myApp.app_context(): db.metadata.create_all(db.engine) for eName, eTime in [ ('Real Madrid vs Barcelona', datetime.datetime(2018, 6, 20, 10, 30, 0)), ('Cavaliers vs Lakers', datetime.datetime(2018, 1, 15, 22, 0, 0)), ]: sport = getOrCreate(db.session, models.Sport, name='Football') event = models.Event(name=eName, startTime=eTime, sport=sport) market = models.Market(name='Winner', event=event) sel1Name, _, sel2Name = eName.partition(' vs ') selection1 = models.Selection(name=sel1Name, odds=1.01, market=market) selection2 = models.Selection(name=sel2Name, odds=1.01, market=market) db.session.add(selection1) db.session.add(selection2) db.session.commit() return myApp
def generate_default_state(): db.drop_all() db.create_all() db.session.commit() ad = models.User(username="******", first_name="Admin", last_name="Admin", email="*****@*****.**") ad.set_password("Admin") db.session.add(ad) u1 = models.User( username="******", first_name="fname", last_name="lname", email="*****@*****.**", profile_pic_filename='Png.png', ) u1.set_password('user1') u2 = models.User( username="******", first_name="fname2", last_name="lname2", email="*****@*****.**", profile_pic_filename='make-an-anime-vaporwave-profile-picture.jpg', ) u2.set_password("user2") u3 = models.User( username="******", first_name="fname3", last_name="lname3", email="*****@*****.**", profile_pic_filename= '59-598379_anime-png-tumblr-anime-profile-pic-transparent-png.png', ) u3.set_password("user3") u4 = models.User( username="******", first_name="fname4", last_name="lname4", email="*****@*****.**", ) u4.set_password("user4") for i in range(100): cert = models.Certificate() u1.certificates.append(cert) u2.certificates.append(cert) u3.certificates.append(cert) db.session.add(cert) for i in range(200): cert = models.Certificate() db.session.add(cert) event1 = models.Event(price=42, title="Event1") event2 = models.Event(price=42, title="Event2") db.session.add(event1) db.session.add(event2) u2.events_host.append(event1) u2.events_host.append(event2) db.session.add(u1) db.session.add(u2) db.session.add(u3) db.session.add(u4) db.session.commit()
def db_write_worker(process_id, write_queue): dbc = models.make_livermore_session() while True: message = write_queue.get(block=True) if message["obj_type"] == const.OBJ_TYPE_OPPPORTUNITY: message_instance = models.Opportunity( version=config.VERSION, path=message["path"], timestamp=message["timestamp"], projected_profit=message["path_profit"], projected_profit_percent=round( float(message["path_profit"]) / float(message["max_q_fiat"]) * 100, 3), required_fiat_quantity=message["max_q_fiat"], opportunity_tag=message["opportunity_tag"], ) if message["obj_type"] == const.OBJ_TYPE_EVENT: message_instance = models.Event( event_type=message["event"], timestamp=message["timestamp"], opportunity_tag=message["opportunity_tag"], ) if message["obj_type"] == const.OBJ_TYPE_TRADE: if "trades" in message: message_instance = [] for t in message["trades"]: my_trade = models.Trade( timestamp=t["timestamp"], exchange=t["exchange"], market=t["market"], order_type=t["order_type"], side=t["side"], price=t["price"], quantity=t["quantity"], fills=t["fills"], status=t["status"], exchange_order_id=t["orderId"], opportunity_tag=t["opportunity_tag"], ) nessage_instance.append(my_trade) else: message_instance = models.Trade( timestamp=message["timestamp"], exchange=message["exchange"], market=message["market"], order_type=message["order_type"], side=message["side"], price=message["price"], quantity=message["quantity"], fills=message["fills"], status=message["status"], exchange_order_id=message["orderId"], opportunity_tag=message["opportunity_tag"], ) if message["obj_type"] == const.OBJ_TYPE_RESULT: message_instance = models.OpportunityResult( actual_profit=message["profit"], opportunity_tag=message["opportunity_tag"], ) try: dbc.add(message_instance) dbc.commit() except Exception as e: print("Error in database write: {}".format(e)) import pdb pdb.set_trace()