Ejemplo n.º 1
0
def add_time_job(bot, update, job_queue, user_data):

    if not user_data:
        error_instruction(bot, update)

    window_name = user_data['window']
    window_state = user_data['state']
    time_input = update.message.text

    #add job
    window_datetime = TimeManager.convert_string_to_time(time_input)
    logger.info(window_datetime)
    window_timestamp = TimeManager.create_window_timestamp(
        window_name, window_state, time_input)

    job_queue.run_daily(window_job,
                        window_datetime,
                        context=update.message.chat_id,
                        name=window_timestamp)

    #add to database
    myWindowManager.add_window_time(window_name, window_state, time_input)

    #add keyboard

    update.message.reply_text("Auto time function added for {0}.\n"
                              "It will {1} at {2}".format(
                                  window_name, window_state, time_input))

    return end_of_time_operation(bot, update)
Ejemplo n.º 2
0
 def __init__(self, start, end):
     if isinstance(start, str) and isinstance(end, str):
         self.start_millis = TimeManager.time_to_millis(start)
         self.end_millis = TimeManager.time_to_millis(end)
         if self.start_millis >= self.end_millis:
             raise Exception("Error : start must be smaller than end")
         self.start_time = start
         self.end_time = end
     elif isinstance(start, int) and isinstance(end, int):
         if start >= end:
             raise Exception("Error : start must be smaller than end")
         self.start_time = TimeManager.millis_to_time(start)
         self.end_time = TimeManager.millis_to_time(end)
         self.start_millis = start
         self.end_millis = end
     else:
         raise Exception("Illegal arguments given")
Ejemplo n.º 3
0
def window_job(bot, job):
    stamp = job.name
    name, state, time = TimeManager.parse_window_timestamp(stamp)
    logger.info(name + " " + state + " " + time)
    if state == 'open':
        bot.send_message(chat_id = job.context, text = "{0} is opening its window at {1}".format(name, time))
        myWindowManager.change_window_state(name, True)
    if state == 'close':
        bot.send_message(chat_id = job.context, text = "{0} is closing its window at {1}".format(name, time))
        myWindowManager.change_window_state(name, False)
Ejemplo n.º 4
0
def index():
    username = current_user.username.title()
    task_manager = TaskManager.TaskManager()
    table = None
    form = forms.CreateTaskForm(request.form)
    all_tasks = task_manager.retrieve_tasks(username)
    if all_tasks:
        items = ItemTable.objectify(all_tasks)
        table = ItemTable.ItemTable(items)
    if request.method == 'GET':
        if table:
            return render_template('index.html',
                                   username=username,
                                   table=table,
                                   title='Home',
                                   form=form)
        return render_template('index.html',
                               username=username,
                               title='Home',
                               form=form)
    if form.validate_on_submit():
        error = None
        time_manager = TimeManager.TimeManager()
        task = form.task.data
        timestamp = form.timestamp.data
        given_date, given_time = str(timestamp).split(' ')
        if not time_manager.create_timestamp(given_date, given_time):
            error = 'Date/Time must be after current Date/Time'
            return render_template('index.html',
                                   username=username,
                                   error=error,
                                   title='Home',
                                   form=form)
        timestamp = time_manager.timestamp
        task_manager.insert_new_task(task, timestamp, username)
        all_tasks = task_manager.retrieve_tasks(username)
        if all_tasks:
            items = ItemTable.objectify(all_tasks)
            table = ItemTable.ItemTable(items)
            return render_template('index.html',
                                   username=username,
                                   table=table,
                                   title='Home',
                                   form=form)
    return render_template('index.html',
                           username=username,
                           title='Home',
                           form=form)
Ejemplo n.º 5
0
def remove_job_one(bot, update, user_data, job_queue):
    window_name = user_data['window']
    instructions = update.message.text
    logger.info("Received instruction to remove: " + instructions)
    state = instructions.split(' ',1)[0][:-1].lower()
    time = instructions.split('\n',1)[1]

    #remove job by its name
    jobname = TimeManager.create_window_timestamp(window_name, state, time)
    logger.info("Window_timestamp created " + jobname)
    myjob = job_queue.get_jobs_by_name(jobname)
    logger.info(myjob)
    for job in myjob:
        job.schedule_removal()

    #remove data from database
    myWindowManager.remove_window_time(window_name,state,time)
    update.message.reply_text("{0} will no longer {1} at {2}".format(window_name, state, time), reply_markup = ReplyKeyboardRemove())
    return end_of_time_operation(bot, update)
Ejemplo n.º 6
0
 def setUp(self):
     self.time_manager = TimeManager.TimeManager()
     self.invalid_date = '{year}-{month}-{day}'.format(
         year=(TimeManager.CURRENT_YEAR - 1),
         month=TimeManager.CURRENT_MONTH,
         day=TimeManager.CURRENT_DAY)
     self.valid_date = '{year}-{month}-{day}'.format(
         year=(TimeManager.CURRENT_YEAR + 1),
         month=TimeManager.CURRENT_MONTH,
         day=TimeManager.CURRENT_DAY)
     self.invalid_time = '{hour}:{minute}'.format(
         hour=(TimeManager.CURRENT_HOUR - 1),
         minute=TimeManager.CURRENT_MINUTE)
     self.valid_time = '{hour}:{minute}'.format(
         hour=(TimeManager.CURRENT_HOUR + 1),
         minute=TimeManager.CURRENT_MINUTE)
     self.current_date = '{year}-{month}-{day}'.format(
         year=TimeManager.CURRENT_YEAR,
         month=TimeManager.CURRENT_MONTH,
         day=TimeManager.CURRENT_DAY)
     self.current_time = '{hour}:{minute}'.format(
         hour=TimeManager.CURRENT_HOUR, minute=TimeManager.CURRENT_MINUTE)
Ejemplo n.º 7
0
    if msg_type == "near_sunset":
        msg += "Sunset is in 1 hour! "
        msg_type = "near_day_end"
    if msg_type == "near_day_end":
        gap = 10000 - int(count)
        msg = msg + count + " steps taken today!"
        if gap > 0:
            msg += " " + str(gap) + " more steps to reach 10K!"
    elif msg_type == "day_end":
        weekday = dt.now().strftime("%A")
        msg = count + " was your final step total for " + weekday + "."
    print(msg)
    twil_client.messages.create(to=target_phone, from_=twil_phone, body=msg)


timings = TimeManager.TimeManager()
twil_client = twilio_setup()
fitbit_client = fitbit_setup()


def main():
    scheduler = sched.scheduler(time.time, time.sleep)

    timings.update_sunset_time()
    scheduler.enterabs(time.mktime(timings.near_day_end_time.timetuple()), 1,
                       step_alert,
                       (timings.near_day_end, scheduler, "near_day_end"))
    scheduler.enterabs(time.mktime(timings.day_end_time.timetuple()), 1,
                       step_alert, (timings.day_end, scheduler, "day_end"))
    scheduler.enterabs(time.mktime(timings.near_sunset_time.timetuple()), 1,
                       step_alert, (timings.day_end, scheduler, "near_sunset"))
Ejemplo n.º 8
0
BEGIN_DATE = None

#------------- DATABASE -------------
DATABASE_HOST_NAME = ""

DATABASE_USERNAME = ""

DB_USER_PASSWORD = ""

DATABASE_NAME = ""

AUTH_PLUGIN = "mysql_native_password"

#################### MAIN ########################
#Create a time manager
timeManager = TimeManager(BEGIN_DATE)
#Create a database Client
databaseClient = DatabaseConnect(DATABASE_HOST_NAME, DATABASE_USERNAME,
                                 DB_USER_PASSWORD, DATABASE_NAME, AUTH_PLUGIN)
#Create a AlientVault TAXII Client and Connect to database
alientvaultTaxiAndDatabaseConnect = TaxiClientToDatabase(
    OTX_TAXI_CLIENT['hostURL'], OTX_TAXI_CLIENT['useHHTPS'],
    OTX_TAXI_CLIENT['discoveryPath'], OTX_TAXI_CLIENT['usernameKey'],
    OTX_TAXI_CLIENT['password'], OTX_TAXI_CLIENT['collectionNames'],
    databaseClient, timeManager)
esetTaxiAndDatabaseConnect = TaxiClientToDatabase(
    ESSET_TAXI_CLIENT['hostURL'], ESSET_TAXI_CLIENT['useHHTPS'],
    ESSET_TAXI_CLIENT['discoveryPath'], ESSET_TAXI_CLIENT['usernameKey'],
    ESSET_TAXI_CLIENT['password'], ESSET_TAXI_CLIENT['collectionNames'],
    databaseClient, timeManager)
#Download STIXX File and Insert to database
Ejemplo n.º 9
0
	o: 164(try), 366(except)

nname: 158
n 158(None)[]:
	i: 98(), 125(), 157(AE)
	o: 161(try), 1158(except)

nname: 125
n 125(None)[debug.PRINT_EXCEPTION()
debug.log.error('Time configuration failed')
]:
	i: 0(except)
	o: 158()

nname: 98
n 98(None)[TimeManager().time_setter = config.user_config['base']['timeupdatemode']
]:
	i: 76(), 97()
	o: 158()

nname: 97
n 97(None)[]:
	i: 37(f)
	o: 98()

nname: 76
n 76(None)[config.user_config['base']['timeupdatemode'] = WYCLOCK_AUTO_SETTER
]:
	i: 37(t)
	o: 98()
Ejemplo n.º 10
0
 def __init__(self, graph):
     self.graph = graph
     self.dstnc = {}
     self.prvus = {}
     self.timeM = TimeManager.TimeManager(self.graph)
Ejemplo n.º 11
0
 def GoOnBreak(self):
     tm.StampStartBreak()
 
     if tk.messagebox.showinfo("Breaktime", "Gone on Break!"):   
         tm.StampEndBreak()