예제 #1
0
def validate_data():
    most_recent = get_last('BTCUSD')[0]
    previous = get_previous('BTCUSD', most_recent, 2)[1][0]
    period = abs(previous - most_recent)
    qty = get_count()
    for i in range(qty):
        time_to_check = most_recent - (i * period)
        get_time(time_to_check)
예제 #2
0
def create_ex(title, author, difficulty, desc, inputs, output, hidden, language, timeout, enable):
    os.mkdir(title)
    dec = database.read("exercices.json")
    data = {'difficulty': difficulty, 'date': database.get_time(), 'author': str(author), 'description': desc, 'inputs': inputs, 'output': output, 'hidden': hidden, 'language': language, 'timeout': timeout, 'enable': enable, 'test_amount': 0, 'executed_test': 0}
    dec[title] = data
    database.write("exercices.json", dec)
    return show_ex(title, data)
예제 #3
0
 def create_show_button(t, l):
     if not t:
         label = "%s" % get_location(l)
     else:
         label = get_time(t)
     return InlineKeyboardButton(
         label,
         callback_data="{'action':'show', 'time':%d, 'location': %d}" %
         (t, l))
예제 #4
0
def fetch_reply(msg, session_id):
    response = detect_intent_from_text(msg, session_id)
    if response.intent.display_name == 'get_news':
        news = get_news(dict(response.parameters))
        news_str = 'Here are your news:'
        for row in news:
            news_str += "\n\n{}\n\n{}\n\n".format(row['title'], row['link'])
        return news_str, '', ''

    elif response.intent.display_name == 'get_weather':
        owm = pyowm.OWM('2242ac01869a406a63e2cf1f430724ef')
        weather = dict(response.parameters)
        city = weather.get("geo-city")
        country = weather.get("geo-country")
        if country != '':
            observation = owm.weather_at_place(city + ',' + country)
        else:
            observation = owm.weather_at_place(city + ',india')
        w = observation.get_weather()
        wind = w.get_wind()['speed']
        humidity = w.get_humidity()
        temprature = w.get_temperature('celsius')['temp']
        status = w.get_detailed_status()
        userdata = {
            'geo-city': city,
            'geo-country': country,
            'time': get_time()
        }
        insertdata(userdata)
        weather = "\nstatus: {}\n".format(status)
        weather += "\ntemprature: {} °c\n".format(temprature)
        weather += "\nhumidity : {}\n".format(humidity)
        weather += "\nwind speed: {}\n".format(wind)
        return weather, '', ''

    elif response.intent.display_name == "get_makeup":
        makeup = dict(response.parameters)
        product = makeup.get('product_type')
        brand = makeup.get('brand')
        if product != '' and brand != '':
            URL = "http://makeup-api.herokuapp.com/api/v1/products.json?brand=" + brand + "&product_type=" + product
            userdata = {'product': product, 'brand': brand, 'time': get_time()}
            insertdata(userdata)
        elif product != '' and brand == '':
            URL = "http://makeup-api.herokuapp.com/api/v1/products.json?product_type=" + product
            userdata = {'product': product, 'time': get_time()}
            insertdata(userdata)
        else:
            URL = "http://makeup-api.herokuapp.com/api/v1/products.json?brand=" + brand
            userdata = {'brand': brand, 'time': get_time()}
            insertdata(userdata)
        request = requests.get(URL)
        content_data = request.json()
        if len(content_data) != 0:
            data = ''
            for i in range(0, 2, 1):
                data += "Product Name and Price : {} {}".format(
                    content_data[i]['name'], content_data[i]['price'])
                data += "\nProduct Description: {}\n".format(
                    content_data[i]['description'])
                data += "\nProduct Link:\n {}\n\n".format(
                    content_data[i]['product_link'])
            print(len(data))
            return data, '', ''
        else:
            return "Product not available", '', ''

    elif response.intent.display_name == "get_dictionary":
        dictionary = dict(response.parameters)
        app_id = "230078d5"
        app_key = "52e933da09c08cfc07c21ad20a32b412"
        endpoint = "entries"
        language_code = "en-us"
        word_id = dictionary.get('word_type')
        url = "https://od-api.oxforddictionaries.com/api/v2/" + endpoint + "/" + language_code + "/" + word_id.lower(
        )
        r = requests.get(url, headers={"app_id": app_id, "app_key": app_key})
        content_data = r.json()
        if len(content_data) != 0:
            data = "Meaning of {} is {}".format(
                word_id, content_data["results"][0]["lexicalEntries"][0]
                ["entries"][0]["senses"][0]["definitions"][0])
            userdata = {'word': word_id, 'time': get_time()}
            insertdata(userdata)
            return data, '', ''
        else:
            return "No Meaning Of Dictionary", '', ''

    elif response.intent.display_name == "get_company":
        company = dict(response.parameters)
        company_name = company.get('company_name')
        company_data = wikipedia.summary(company_name, sentences=2)
        page_image = wikipedia.page(company_name).images[1]
        return company_data, page_image, "type2"

    else:
        return response.fulfillment_text, '', ''
예제 #5
0
def button(bot, update):
    query = update.callback_query

    reply = ast.literal_eval(query.data)
    print 'BUTTON:', reply
    if reply.get('action') == 'update':
        update_task(query.from_user, reply)
        if 'time' in reply:
            bot.editMessageText(text="Ок, %s" %
                                get_time(reply['time']).encode('utf8'),
                                chat_id=query.message.chat_id,
                                message_id=query.message.message_id)

            def create_location_button(num):
                return InlineKeyboardButton(
                    get_location(num),
                    callback_data="{'action':'update', 'id':%s, 'location':%s}"
                    % (reply['id'], num))

            keyboard = [[create_location_button(i) for i in range(1, 5)]]
            reply_markup = InlineKeyboardMarkup(keyboard)

            bot.sendMessage(chat_id=query.message.chat_id,
                            text="Это где?",
                            reply_markup=reply_markup)

        if 'location' in reply:
            bot.editMessageText(text="Ок, %s" %
                                get_location(reply['location']).encode('utf8'),
                                chat_id=query.message.chat_id,
                                message_id=query.message.message_id)

    if reply.get('action') == 'show':

        number_of_tasks, task_id, task = get_task_from_db(
            query.from_user, reply.get('time', 0), reply.get('location', 0),
            reply.get('number', 0))
        reply['number'] = reply.get('number', 0) + 1
        if number_of_tasks == 0:
            bot.sendMessage(chat_id=query.message.chat_id, text='Таких нет!')
            return
        if reply['number'] >= number_of_tasks:
            reply['number'] = 0
            button_name = 'Давай сначала!'
        else:
            button_name = 'Следущую!'
        keyboard = [[
            InlineKeyboardButton(
                'Делаю!',
                callback_data="{'action':'update', 'id':%s, 'status':1}" %
                task_id),
            InlineKeyboardButton(button_name, callback_data=str(reply)),
            InlineKeyboardButton('Удалить!',
                                 callback_data="{'action':'delete', 'id':%s}" %
                                 task_id)
        ]]
        reply_markup = InlineKeyboardMarkup(keyboard)
        bot.sendMessage(chat_id=query.message.chat_id,
                        text=task,
                        reply_markup=reply_markup)

    if reply.get('action') == 'delete':

        delete_task(reply.get('id'))
예제 #6
0
 def create_time_button(num):
     return InlineKeyboardButton(
         get_time(num),
         callback_data="{'action':'update', 'id':%s, 'time':%s}" %
         (id, num))