Пример #1
0
 def GET(self, source, feed_type=None):
     if not feed_type:
         events = db.get_events(order='time_start, name',  
             where="not cancelled and time_start >= date_sub(current_timestamp, interval 5 hour) and taken_from= '%s'" % (source))
         web.debug(len(events))
         #add source specific feed
         print render.base(render.show_events( events, admin=False), feeds=["""
             <link rel="alternate"
             type="application/atom+xml" title="%s calendar - Atom"
             href="http://%s/from/%s/feed.atom" />
         """ % (source, config.server_root_url, source),])
     else:
         events = [e for e in db.get_events(limit='100', order='time_taken desc', where ="taken_from= '%s'" % (source))]
         render_cached_feed(events, feed_type)
Пример #2
0
def load_events():
    raw_events = db.get_events(state['rowid_start'], state['rowid_end'])[::-1]
    # convert timestamps to datetime objects
    event_queue.extend(
        map(lambda row: (eval(row[0]), row[1], row[2]), raw_events))
    state['rowid_start'] = state['rowid_end'] + 1
    state['rowid_end'] += chunksize
Пример #3
0
def events_handler(from_timestamp=None, till_timestamp=None):
    """
    Get all events.
    ---
    :param from_timestamp:
    :param till_timestamp:
    :return:
    """
    events = db.get_events(from_timestamp, till_timestamp)
    package_events = [
        event for event in events if event['escrow_pubkey'] is not None
    ]

    # Extra data to help client with indexing.
    event_indexes_by_package = {}
    event_types_by_package = {}
    for idx, event in enumerate(package_events):
        if event['escrow_pubkey'] not in event_indexes_by_package:
            event_indexes_by_package[event['escrow_pubkey']] = []
        if event['escrow_pubkey'] not in event_types_by_package:
            event_types_by_package[event['escrow_pubkey']] = []
        event_indexes_by_package[event['escrow_pubkey']].append(idx)
        event_types_by_package[event['escrow_pubkey']].append(
            event['event_type'])

    return {
        'status': 200,
        'events': events,
        'event_indexes_by_package': event_indexes_by_package,
        'event_types_by_package': event_types_by_package
    }
Пример #4
0
def event_handler3(room_id,username):
    eves=get_events(room_id)
    if eves:
            message="Events Available Are"
            return render_template('display.html', message=message,eves=eves)
    else:
            message = "No Events"
            return render_template('display.html', message=message)
Пример #5
0
 def GET(self, date):
     datedata = date.split('-')
     if len(datedata) == 3:
         events = [e for e in db.get_events(order='name', where='not cancelled and duplicateof is null and year(time_start) = %s and month(time_start) = %s and dayofmonth(time_start) = %s' % tuple(date.split('-')))]
         web.debug(len(events))
         print render.daymap(events, date, render.show_events(events, admin=False, formap=True))
     else:
         web.debug("accessing the daymap with parameters %s" % date)
         web.seeother('/')
Пример #6
0
def event_handler5(room_id,username):

    eves=get_events(room_id)
    if eves:
            message="Events Available Are"
            return render_template('delete.html', message=message,eves=eves,room_id=room_id,username=username)
    else:
            message = "NO Events"
            return render_template('delete.html', message=message)
Пример #7
0
def event_handler2(room_id, username):
    if request.method == 'POST':
        event = request.form.get('event')
        date1 = request.form.get('date1')
        try:
            save_event(username, room_id, event, date1)
            message = "Successfully added"
            eves = get_events(room_id)
            return render_template('display.html', message=message, username=username,eves=eves)
        except DuplicateKeyError:
            message = "Error"
            return render_template('event.html', message=message)
Пример #8
0
def main_menu(bot, update, user_data):
    text = update.message.text
    if (text == "Abrir Porton"):
        update.message.reply_text("Cual porton desea abrir?",
                                  reply_markup=gate_choose)
        return c.OPEN
    elif (text == "Cerrar Porton"):
        update.message.reply_text("Cual porton desea cerrar?",
                                  reply_markup=gate_choose)
        return c.CLOSE
    elif (text == "Timbre"):
        gpio.touch_button(0)
        update.message.reply_text("Tocando el timbre..",
                                  reply_markup=markup_main)
        return c.MAIN
    elif (text == "Estado de los Portones"):
        message = ""
        for i in range(c.TOTAL_SENSORS):
            if (gpio.read_gpio(i) == c.CLOSED_GPIO):
                state = "cerrado"
            elif (gpio.read_gpio(i) == c.OPEN_GPIO):
                state = "abierto"
            else:
                state = "desconocido"
            message += "Porton " + str(i) + " en estado: " + state + "\n"
        update.message.reply_text(message, reply_markup=markup_main)
        return c.MAIN
    elif (text == "Suscripciones"):
        update.message.reply_text('Que desea hacer?',
                                  reply_markup=subscribe_main)
        return c.SUBSCRIBE
    elif (text == "Ultimos 10 eventos"):
        events = db.get_events(10)
        if (events != None):
            message = ""
            for event in events:
                if (event[0] == c.CLOSED_GPIO):
                    state = "cerrado"
                elif (event[0] == c.OPEN_GPIO):
                    state = "abierto"
                else:
                    state = "desconocido"
                message += "Porton: " + str(
                    event[1]) + " " + state + " " + event[2].astimezone(
                        timezone('America/Costa_Rica')).strftime(
                            "%d %b %I:%M %p") + "\n"
            update.message.reply_text(message)
        update.message.reply_text('Que desea hacer?', reply_markup=markup_main)
        return c.MAIN
    else:
        return c.MAIN
Пример #9
0
def read_events():
    print('backend service responding to request for events')
    # string is default to prevent error when jsonifying python datetime
    return json.dumps(db.get_events(), indent=4, sort_keys=True,
                      default=str), 200
Пример #10
0
 def GET(self):
     events = db.get_events( order='time_start, name', \
             where='not cancelled and time_start >= date_sub(current_timestamp, interval 5 hour)')
     web.debug(len(events))
     print render.base(render.show_events( events, admin=True))
Пример #11
0
 def GET(self, format_type='atom'):
     events = [e for e in db.get_events(limit='100', order='time_taken desc', where='duplicateof is null')]
     web.debug(type(events[0].name))
     render_cached_feed(events, format_type)
Пример #12
0
def event_handler7(event,username,room_id,created):
    remove_event(event,created)
    eves = get_events(room_id)
    message="Events Available are"
    return render_template('display.html', message=message,eves=eves)
Пример #13
0
def events_handler(max_events_num=100, mock=None):
    """
    Get all events.
    ---
    :param max_events_num:
    :param mock:
    :return:
    """
    if not bool(mock):
        events = db.get_events(max_events_num)
    # Mock data. Temporary.
    else:
        events = {
            'packages_events': [{
                'timestamp': '2018-08-03 14:29:18.116482',
                'escrow_pubkey': 'GB5SUIN2OEJXG2GDYG6EGB544DQLUVZX35SJJVLHWCEZ4FYWRWW236FB',
                'user_pubkey': 'GBUPZ63WK2ZLOCXPCUOMM7XRUGXOVJC3RIBL7KBTUSHLKFRKVHUB757L',
                'event_type': 'launched', 'location': '51.4983407,-0.173709'
            }, {
                'timestamp': '2018-08-03 14:35:05.958315',
                'escrow_pubkey': 'GB5SUIN2OEJXG2GDYG6EGB544DQLUVZX35SJJVLHWCEZ4FYWRWW236FB',
                'user_pubkey': 'GCBKJ3QLHCBK5WBF4UZ5K2LOVDI63WG2SKLIWIMREPRLCTIHD6B5QR65',
                'event_type': 'couriered', 'location': '51.4983407,-0.173709'
            }, {
                'timestamp': '2018-08-04 17:02:55.138572',
                'escrow_pubkey': 'GB5SUIN2OEJXG2GDYG6EGB544DQLUVZX35SJJVLHWCEZ4FYWRWW236FB',
                'user_pubkey': 'GDRGF2BU7CV4QU4E54B72BJEL4CWFMTTVSVJMKWESK32HLTYD4ZEWJOR',
                'event_type': 'received', 'location': '53.3979468,-2.932953'
            }, {
                'timestamp': '2018-08-03 06:35:17.169421',
                'escrow_pubkey': 'GBMU5SWBUNBCDRUMIZNCDOTMIRGLBFY5DEPIE4OTBAUOFK4V3HOENAGT',
                'user_pubkey': 'GANEU37FIEBICW6352CVIUD7GYOV5H7W5YUE5ECDH5PJNF7R5ISYJR3K',
                'event_type': 'launched', 'location': '31.2373787,34.7889161'
            }, {
                'timestamp': '2018-08-03 07:01:17.192375',
                'escrow_pubkey': 'GBMU5SWBUNBCDRUMIZNCDOTMIRGLBFY5DEPIE4OTBAUOFK4V3HOENAGT',
                'user_pubkey': 'GBL4FZ6HCA6SQATD5UYHQYMVWASBEZCKGL2P7PEU6VNLONVFZY6DPV3R',
                'event_type': 'couriered', 'location': '31.2373787,34.7889161'
            }, {
                'timestamp': '2018-08-05 22:05:53.162485',
                'escrow_pubkey': 'GBMU5SWBUNBCDRUMIZNCDOTMIRGLBFY5DEPIE4OTBAUOFK4V3HOENAGT',
                'user_pubkey': 'GBYYI24HZ75OYBAHZOUVAAQNS5YHMN32VLCDBZFXHAAJKRRSCZICBIDJ',
                'event_type': 'received', 'location': '32.8266712,34.9774087'
            }, {
                'timestamp': '2018-08-07 05:55:15.168276',
                'escrow_pubkey': 'GALIFYZ6GDHXWDH2QZLRJY2XS77A6WXILDFSRH6ZZM3IYOIH2XEK3TAK',
                'user_pubkey': 'GAZ2UUQUEYY2LHAQMP4M737DXXX3TM7L6BE5JT7LYWS5GYL6VXQ6HASR',
                'event_type': 'launched', 'location': '12.926039,77.5056131'
            }, {
                'timestamp': '2018-08-07 09:14:18.137124',
                'escrow_pubkey': 'GALIFYZ6GDHXWDH2QZLRJY2XS77A6WXILDFSRH6ZZM3IYOIH2XEK3TAK',
                'user_pubkey': 'GBQR3QGZOS2K4MQPPJDKRMJ6MIEACCG4BRO23UE33TDFRZOM57VL5O5J',
                'event_type': 'couriered', 'location': '12.926039,77.5056131'
            }, {
                'timestamp': '2018-08-09 14:27:16.143762',
                'escrow_pubkey': 'GALIFYZ6GDHXWDH2QZLRJY2XS77A6WXILDFSRH6ZZM3IYOIH2XEK3TAK',
                'user_pubkey': 'GAYOZB7SZBD7O4UPLLQNXFN5ZZCQJSXBKERNIY4MIWL7DVXF7DBF7OU6',
                'event_type': 'received', 'location': '28.7050581,77.1419526'}],
            'user_events': [{
                'timestamp': '2018-08-01 17:46:18.169723',
                'escrow_pubkey': None,
                'user_pubkey': 'GBUPZ63WK2ZLOCXPCUOMM7XRUGXOVJC3RIBL7KBTUSHLKFRKVHUB757L',
                'event_type': 'installed app', 'location': '51.5482912,-0.3048464'
            }, {
                'timestamp': '2018-07-22 19:36:18.123142',
                'escrow_pubkey': None,
                'user_pubkey': 'GCCYNSN3WETV2FBASFVXKAJ54OX4NUTP4ZUJFGXTX47A2GRQYQ52QQBK',
                'event_type': 'installed app', 'location': '50.2443519,28.6989147'
            }, {
                'timestamp': '2018-07-22 19:58:38.164237',
                'escrow_pubkey': None,
                'user_pubkey': 'GCCYNSN3WETV2FBASFVXKAJ54OX4NUTP4ZUJFGXTX47A2GRQYQ52QQBK',
                'event_type': 'passed kyc', 'location': '50.2443519,28.6989147'
            }, {
                'timestamp': '2018-07-28 05:34:21.134562',
                'escrow_pubkey': None,
                'user_pubkey': 'GBOTDKM6ZJNV54QLXKTU5WSYFXJZDZZSGKTYHDNWDDVAEVB73DPLSP4H',
                'event_type': 'funded account', 'location': '22.9272893,113.3443182'
            }, {
                'timestamp': '2018-07-30 22:12:21.136421',
                'escrow_pubkey': None,
                'user_pubkey': 'GAUHIJXEV2D46G375FJNCUBGVUKXRF7C3VC7U3HUPCBIZUYHJKP4N6XA',
                'event_type': 'funded account', 'location': '-16.2658233,-47.9159335'
            }, {
                'timestamp': '2018-08-03 17:35:14.136415',
                'escrow_pubkey': None,
                'user_pubkey': 'GAL54ATIHYBWMKYUNQSM3QAGZGCUBJGF6KEFFSQTEV7JOOA72UEJP4UL',
                'event_type': 'funded account', 'location': '51.0465554,-114.0752757'}]}
    return {'status': 200, 'events': events}