예제 #1
0
def delete_selected_task(bot, update, chat_data):
    query = update.callback_query
    q_data = int(update.callback_query.data[1:])

    l = []
    for t in chat_data.get('TASKS', []):
        if t.id == q_data:
            t.job.schedule_removal()
            database.tasks.delete(t.id, query.message.chat_id)
            bot.answer_callback_query(query.id,
                                      text='Удалено: %s' % t.text,
                                      show_alert=False)
        else:
            l.append(t)

    chat_data['TASKS'] = l

    if len(chat_data['TASKS']) == 0:
        bot.edit_message_text(text='У вас больше нет заметок😉',
                              chat_id=query.message.chat_id,
                              message_id=query.message.message_id)
        return READY

    k = keyboards.get_task_inline_keyboard(
        timezone.get_timezone(chat_data['LOC']), chat_data['TASKS'])

    bot.edit_message_text(text='Нажмите, чтобы удалить',
                          chat_id=query.message.chat_id,
                          message_id=query.message.message_id,
                          reply_markup=k)
예제 #2
0
def set_location_address(bot, update, chat_data):
    tz = None
    geopos = None
    if update.message.text is not None and len(update.message.text):
        geopos = timezone.get_geopos_for_address(update.message.text)
        if geopos is not None:
            tz = timezone.get_timezone(geopos)

    if tz is None:
        update.message.reply_text(
            'Не удалось определить ваш часовой пояс, извините(\nПопробуйте еще раз',
            reply_markup=keyboards.SET_LOCATION_KEYBOARD)
        logger.error('Bad TZ request in update "{}" for address "{}"'.format(
            update, update.message.text))
        return SET_LOCATION
    else:
        if database.location.get(update.message.chat_id) is None:
            database.location.insert(update.message.chat_id, geopos)
        else:
            database.location.update(update.message.chat_id, geopos)

        chat_data['LOC'] = geopos
        update.message.reply_text('Готово!)\nВаш часовой пояс:\n{}'.format(tz),
                                  reply_markup=keyboards.READY_KEYBOARD)
        logger.info("'{}' set location to '{}'{}".format(
            update, update.message.text, geopos))
        return READY
예제 #3
0
def list_notes(bot, update, chat_data):
    if len(chat_data.get('TASKS', [])) == 0:
        update.message.reply_text('Вы не добавили ни одного напоминания',
                                  reply_markup=keyboards.READY_KEYBOARD)
        return READY
    k = keyboards.get_task_inline_keyboard(
        timezone.get_timezone(chat_data['LOC']), chat_data['TASKS'])
    update.message.reply_text('Нажмите, чтобы удалить', reply_markup=k)
    return READY
예제 #4
0
def show_all_tasks(bot, update, chat_data):
    query = update.callback_query
    if len(chat_data['TASKS']) == 0:
        bot.edit_message_text(text='Вы не добавили ни одного напоминания',
                              chat_id=query.message.chat_id,
                              message_id=query.message.message_id)
        return READY
    k = keyboards.get_task_inline_keyboard(
        timezone.get_timezone(chat_data['LOC']), chat_data['TASKS'])
    bot.edit_message_text(text='Нажмите, чтобы удалить',
                          chat_id=query.message.chat_id,
                          message_id=query.message.message_id,
                          reply_markup=k)
    return READY
예제 #5
0
def get_datetime(wf, dt_format, input_str):
    timezone, tzoffset = get_timezone(wf)

    # Unify input_str
    input_str = input_str and input_str.strip() or 'now'
    input_str = input_str.replace('tmr',
                                  'tomorrow').replace('ytd', 'yesterday')
    if input_str.isdigit():
        input_str = "@{}".format(input_str)

    rc = re.findall(r'^(@\d+)(\s.*){0,1}', input_str)
    if rc:
        timestamp, successor = rc[0]
        rc, _ = exec_cmd(timezone, '{}'.format(timestamp))
        input_str = "{} {}".format(rc, successor)

    return exec_cmd(timezone, input_str, dt_format)
예제 #6
0
def get_committer_id(conn, committer):
	if not hasattr(committer, 'login'):
		return -1
	c = conn.cursor()
	c.execute('SELECT id FROM committers WHERE username=?', (committer.login,))
	temp = c.fetchall()
	if len(temp) == 0:
		tz = timezone.get_timezone(c, committer)
		c.execute('INSERT INTO committers(username,timezone) VALUES (?,?)',
				  (committer.login, tz,))
		conn.commit()
		c.execute('SELECT id FROM committers WHERE username=?',
				  (committer.login,))
		temp = c.fetchall()

	commiter_id = temp[0][0]
	return commiter_id
예제 #7
0
def show_selected_task(bot, update, chat_data):
    query = update.callback_query
    q_data = int(update.callback_query.data[1:])

    tz = timezone.get_timezone(chat_data['LOC'])

    for t in chat_data.get('TASKS', []):
        if t.id == q_data:
            bot.edit_message_text(
                text='\n'.join((t.text, tz.get_time(t.time))),
                chat_id=query.message.chat_id,
                message_id=query.message.message_id,
                reply_markup=keyboards.get_selected_task_inline_keyboard(
                    tz, t))
            return READY

    return show_all_tasks(bot, update, chat_data)
예제 #8
0
def add_note_time(bot, update, chat_data, job_queue):
    utc_now = int(datetime.datetime.utcnow().timestamp())
    t = datetime_parser.get_timestamp(update.message.text, utc_now)
    if t is None:
        update.message.reply_text(
            'Не понимаю( Посмотрите возможные форматы задания даты и времени',
            reply_markup=keyboards.ADD_NOTE_TIME_KEYBOARD)
        logger.info('WRONG TIME FORMAT: {} "{}"'.format(
            update.effective_user, update.message.text))
        return ADD_NOTE_TIME

    if len(chat_data.get('TASKS', [])) > MAX_TASKS_NUM_PER_CHAT:
        update.message.reply_text(
            'У вас слишком много напоминаний, зачем столько???🙀',
            reply_markup=keyboards.READY_KEYBOARD)
        return READY

    job = job_queue.run_once(alarm,
                             t - utc_now,
                             context=(utc_now, update.message.chat_id,
                                      chat_data['text']))
    task = tasks.Task(utc_now, chat_data['text'], t, job)

    if 'TASKS' not in chat_data:
        chat_data['TASKS'] = []
    chat_data['TASKS'].append(task)

    database.tasks.insert(update.message.chat_id, task)

    update.message.reply_text('"{}" добавлено на {}'.format(
        task.text,
        timezone.get_timezone(chat_data['LOC']).get_time(task.time)),
                              reply_markup=keyboards.READY_KEYBOARD)

    logger.info('ADD NEW NOTE: {} "{}" at "{}"'.format(update.effective_user,
                                                       task.text,
                                                       update.message.text))

    return READY
예제 #9
0
def set_location_geopos(bot, update, chat_data):
    geopos = timezone.geopos_to_key(update.message.location.latitude,
                                    update.message.location.longitude)
    tz = timezone.get_timezone(geopos)

    if tz is None:
        update.message.reply_text(
            'Не удалось определить ваш часовой пояс, извините(\nПопробуйте еще раз'
        )
        logger.error('Bad TZ request in update "{}" for geopos "{} {}"'.format(
            update, *geopos))
        return SET_LOCATION

    if database.location.get(update.message.chat_id) is None:
        database.location.insert(update.message.chat_id, geopos)
    else:
        database.location.update(update.message.chat_id, geopos)

    chat_data['LOC'] = geopos
    update.message.reply_text('Готово!)\nВаш часовой пояс:\n{}'.format(tz),
                              reply_markup=keyboards.READY_KEYBOARD)
    logger.info("'{}' set location to {}".format(update, geopos))
    return READY
예제 #10
0
def settings(bot, update, chat_data):
    tz = timezone.get_timezone(chat_data['LOC'])
    update.message.reply_text('Ваш часовой пояс:\n{}'.format(tz),
                              reply_markup=keyboards.SETTINGS_KEYBOARD)
    return SETTINGS
예제 #11
0
def get_time(bot, update, chat_data):
    tz = timezone.get_timezone(chat_data['LOC'])
    update.message.reply_text(tz.get_current_time(),
                              reply_markup=keyboards.READY_KEYBOARD)
    return READY

# for optimization solver to work , 
# starting address must be the same as the ending addressa
ad_dres = addresses[0]  # take first address  from 'addresses' array
addresses.append(ad_dres) # add first address to the end of 'addresses' array

order_id = resDatas(sys.argv[4]) # Split a string into an array of substrings
# order_id = [id1,id2,......,id(n)]

API_Key_Google = 'AIzaSyCNSyD13siR0AvcuoKMBntWw_b0xz_n_AQ'     # google api
API_Key_Tomtom = 'cntu9IDdS7Rawt7yAARx9YfxRD7jR4vI'  # tomomt api
API_Key_Mapbox = 'pk.eyJ1Ijoic2lnbmlmaWMiLCJhIjoiY2p6OXVqbzV4MDE2MDNkbzA3bWFuMjBtNiJ9._5hiEwXhS7enZFm_SvmVeg' # mapbox api
optimise_selection = int(sys.argv[5]) # cast to integer 

start_datetime = timezone.get_timezone(addresses, API_Key_Google)


def optimise_or_onlyETA(orderid_list, address_list, optimise, start_datetime):

    if optimise == 1:
        # call optimise function
       
        optimisation_results = option1_optimisation.get_optimised_route(orderid_list, address_list, API_Key_Tomtom,
                                                                        API_Key_Mapbox, start_datetime)
        optimisation_results = json.loads(optimisation_results)
        print(optimisation_results)
        sys.stdout.flush()   # free memory
    else:
        # do not optimise, just route and call ETA function