Exemple #1
0
def request_video(channel):
    current_user = User.query.filter_by(
        username=user_logged['user_name']).first()
    if current_user.resources >= 5:
        led.all_off()
        led.red_on()
        print("You spent 5 points for a video!")
        current_user.resources -= 5
        activity_time = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
        # write something here
        new_activity = Activity(uid=user_logged['user_uid'],
                                date=activity_time.split(' ')[0],
                                time=activity_time.split(' ')[1],
                                query='video')
        db.session.add(new_activity)
        db.session.commit()
        led.all_on()
        user_logged['user_resources'] = current_user.resources
        user_logged['user_choice'] = 'video'
        user_logged[
            'message'] = 'You queried a video from us. This costs all your points.'
        socketio.emit('server_response', {'data': user_logged},
                      namespace='/conn')
        user_logged['user_choice'] = ''
    else:
        print('You cannot afford a video.')
        user_logged['message'] = 'You cannot afford a video.'
        socketio.emit('server_response', {'data': user_logged},
                      namespace='/conn')
Exemple #2
0
def request_text(channel):
    user_logged['user_choice'] = 'text'
    # print(user_logged['user_name'])
    #     data = api.request_quotes()
    #     print(data)
    #     print('Button Pressed')
    #     GPIO.output(14, GPIO.HIGH)
    current_user = User.query.filter_by(
        username=user_logged['user_name']).first()
    if current_user.resources >= 1:
        led.all_off()
        led.blue_on()
        current_user.resources -= 1
        activity_time = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
        new_activity = Activity(uid=user_logged['user_uid'],
                                date=activity_time.split(' ')[0],
                                time=activity_time.split(' ')[1],
                                query='text')
        db.session.add(new_activity)
        db.session.commit()
        print('You spend 1 point.')
        user_logged['user_choice'] = 'text'
        user_logged['user_resources'] = current_user.resources
        user_logged[
            'message'] = 'You queried a text message from us. This costs you one.'
        socketio.emit('server_response', {'data': user_logged},
                      namespace='/conn')
        # text_requested = api.request_tweets()
        printer.random_texts()
        # print(text_requested)
        led.all_on()
        user_logged[
            'message'] = 'Your query is finished. What else do you want from us?'
        socketio.emit('server_response', {'data': user_logged},
                      namespace='/conn')

    else:
        user_logged['message'] = 'You cannot afford a text message.'
        socketio.emit('server_response', {'data': user_logged},
                      namespace='/conn')
        print('You cannot afford a text message.')
Exemple #3
0
def request_sound(channel):
    user_logged['user_choice'] = 'sound'
    current_user = User.query.filter_by(
        username=user_logged['user_name']).first()
    if current_user.resources >= 3:
        led.all_off()
        led.green_on()
        # printer.print_tweets()
        print("You spent 3 points for a sound message!")

        current_user.resources -= 3
        activity_time = time.strftime("%Y-%m-%d %H:%M:%S", time.gmtime())
        new_activity = Activity(uid=user_logged['user_uid'],
                                date=activity_time.split(' ')[0],
                                time=activity_time.split(' ')[1],
                                query='sound')
        db.session.add(new_activity)
        db.session.commit()

        user_logged['user_resources'] = current_user.resources
        user_logged[
            'message'] = 'You queried a sound message. This costs you three.'
        user_logged['user_choice'] = 'sound'
        socketio.emit('server_response', {'data': user_logged},
                      namespace='/conn')
        sound.play_random_sound()
        led.all_on()
        user_logged[
            'message'] = 'Your query is finished. What else do you want from us?'
        socketio.emit('server_response', {'data': user_logged},
                      namespace='/conn')

    else:
        user_logged['message'] = 'You cannot afford a sound message.'
        socketio.emit('server_response', {'data': user_logged},
                      namespace='/conn')
        print('You cannot afford a sound message.')
Exemple #4
0
# coding=utf-8
import time
import temp, led

while True:
    total_temp = 0
    for sensor in temp.sensors:
        sensor_temp = temp.read_temp(sensor)
        #print "{} -- {}".format(sensor["code"],sensor_temp)
        total_temp += sensor_temp
    total_temp = total_temp / len(temp.sensors)
    print u"TEMPERATURE => {} ºC".format(total_temp)
    led.all_off()
    led.show_value(total_temp)

    time.sleep(1)