def set_current(self, horizon=7, notebook_list_number=None, filter=None): """ set_current preforms double duty. 1. If there is an index from the options, use that option to set the current notebook. 2. Pull the notebooks from the DB land. """ if filter is None: filter = None lastday = None if filter: lastday = TimeStamp(filter).tomorrow() filter = TimeStamp(filter).lt(horizon) if notebook_list_number is not None: self.current_notebook = notebook_list_number self.save_state() (j, t) = self.notebooks[self.current_notebook] #if os.path.exists(j): # journal = pickle.load(open(j,'rb')) #else: #if filter: # dk = filter #else: # dk = TimeStamp().daypart() if j == 'journal' else None journal = db.loadjournal(jname=j, daykey=filter, lastday=lastday) #if not os.path.exists(t): td = db.loadtodo(j) todo = td if td else None if todo is None and os.path.exists(t): todo = pickle.load(open(t, 'rb')) else: todo = {} return (journal, todo)
def __init__(self, id=''): if not id: self.id = generate_uuid() else: self.id = id self.pickup_pose = Area() self.delivery_pose = Area() self.earliest_pickup_time = TimeStamp() self.latest_pickup_time = TimeStamp() self.user_id = '' self.load_type = '' self.load_id = '' self.priority = -1
def update_timestamp(message): header = message.get('header') if header: header.update(timeStamp=TimeStamp().to_str()) else: header = MessageFactoryBase.get_header(None) message.update(header)
def done(self, filter='', entry=''): cherrypy.response.headers[ 'Cache-Control'] = 'no-cache, no-store, must-revalidate' c = 0 body = "<div class=\"container\"><div class=\"col-sm-7\">" body += "<form name=\"dome\" id=\"dome\" method=\"GET\" action='add'>" body += "<textarea rows=\"5\" cols=\"49\" name=\"entry\"></textarea>" body += "<input type=\"hidden\" name=\"interval\" id=\"interval\"/>" body += "<button type=\"button\" onclick=\"domeaction();\">Enter</button>" #body += """<button type="submit"></button>""" body += "</form></div><div class=\"col-sm-5\"><h3>{VERSIONNUM}</h3><h4>{PWD}</h4></div></div>" body = body + "<table><tr><th>timestamp</th><th>Entry</th></tr>" global BASEHTML, DLINE if filter is None or filter == '': dayfilter = TimeStamp().daypart() else: dayfilter = TimeStamp(filter).daypart() title = 'Done entries' journal, todo_dict, notebook = notes.load_journal(filter=dayfilter) for i in reversed(sorted(journal.keys())): #if filter == '' or filter in i: if i in todo_dict.keys(): if todo_dict[i] == True: pass else: c = c + 1 body = body + DLINE.format(COUNT=c, DATETIME=journal[i].title, ENTRY=journal[i].entry.replace( '""', '"').replace( "''", "'")) else: c = c + 1 body = body + DLINE.format(COUNT=c, DATETIME=journal[i].title, ENTRY=journal[i].entry.replace( '""', '"').replace("''", "'")) body = body + "</table>" #print(body) VN = config.version() CD = os.getcwd() print(VN) print(CD) body = body.format(VERSIONNUM=VN, PWD=CD) return BASEHTML.format(TITLE=title, BODY=body, dayfilter=TimeStamp().daypart())
def test_get_days_correct_len(self): ts = TimeStamp() startTS = ts.totimestamp(datetime.today() - timedelta(days=9)) endTS = ts.totimestamp(datetime.today()) a = api_gen(startTS, endTS, 10) self.assertTrue( len(a.daysInRange) == 10, "Should be 10 days got " + str(len(a.daysInRange)))
def test_partition_range_bins(self): ts = TimeStamp() startTS = ts.totimestamp(datetime.today() - timedelta(days=200)) endTS = ts.totimestamp(datetime.today()) a = api_gen(startTS, endTS, 10) bins = [x[1] for x in a.daysInRange] self.assertTrue(max(bins) == 10) self.assertTrue(min(bins) == 1)
def is_executable(self): """Returns True if the given task needs to be dispatched based on the task schedule; returns False otherwise """ current_time = TimeStamp() if self.start_time < current_time: return True else: return False
def test_get_days_rolls_to_midnight(self): ts = TimeStamp() startTS = ts.totimestamp(datetime.today() - timedelta(days=2)) endTS = ts.totimestamp(datetime.today()) sdt = ts.todate(startTS) shouldStartAm = datetime(sdt.year, sdt.month, sdt.day) a = api_gen(startTS, endTS, 100) self.assertTrue( a.daysInRange[0][0][0] == shouldStartAm, "first date incorrect expected:" + str(shouldStartAm) + " got :" + str(a.daysInRange[0][0][0]))
def get_header(message_type, meta_model='msg', recipients=[]): if recipients is not None and not isinstance(recipients, list): raise Exception("Recipients must be a list of strings") return { "header": { 'type': message_type, 'metamodel': 'ropod-%s-schema.json' % meta_model, 'msgId': generate_uuid(), 'timestamp': TimeStamp().to_str(), 'receiverIds': recipients } }
def all(self): _, _, notebook = notes.load_journal() body = "<form method=\"GET\" action=\"undo\"><input type=\"text\" name=\"key\"><button type=\"submit\">UNDO</button></form><hr>" body += "<table><tr><th>timestamp</th><th><Entry></th></tr>" global BASEHTML, DLINE title = 'All Journal Entries' journal, _, _ = notes.load_journal() for i in reversed(sorted(journal.keys())): body = body + FLINE.format(DATETIME=journal[i].title, ENTRY=journal[i].entry) body = body + "</table>" return BASEHTML.format( journal=notebook.notebooks[notebook.current_notebook], TITLE=title, BODY=body, dayfilter=TimeStamp().daypart())
def mark_done(key): (journal, todos, notebooks) = load_journal() (jornalname, _) = notebooks.notebooks[notebooks.current_notebook] rightnow = TimeStamp() elapsed_hours = rightnow.elapsed_hours(key) journal_entry = journal.pop(key) db.removeentry(key) journal_entry.title = rightnow.timestamp() old_entry = journal_entry.entry new_entry = "{}<br>@{}+{:.4f}".format(old_entry, key, elapsed_hours) journal_entry.entry = new_entry journal[journal_entry.title] = journal_entry db.updateentry(journal_entry.title, new_entry) db.addentry(jornalname, journal_entry.title, new_entry) todos.pop(key) notebooks.save_current(journal, todos)
def copyto(daykey, journalname): today = TimeStamp() sql0 = """ SELECT entry as entry FROM journal WHERE title LIKE '{}' """ query0 = sql0.format(daykey) with sqlite3.connect('journal.db') as conz: cur = conz.cursor() execor = cur.execute(query0) for row in execor: entry = row[0] start = 1 + len(journalname) newentry = entry[start:] newkey = today.timestamp() sql = """ INSERT INTO journal VALUES('{}' , "{}" , '{}' ) """ query = sql.format(newkey, newentry, journalname) with sqlite3.connect('journal.db') as conx: cursor = conx.cursor() cursor.execute(query) return newentry
def todo(self): body = "" body = body + "<form method=\"GET\" action='add'>" body = body + "<textarea rows=\"5\" cols=\"49\" name=\"entry\"></textarea>" body += "<input type=\"checkbox\" name=\"todo\"/>" body += "<button type=\"submit\">Enter</button>" body += "</form>" body += "<table><tr><th>timestamp</th><th><Entry></th></tr>" global BASEHTML, DLINE title = 'To do entries' journal, todo_dict, notebook = notes.load_journal() if todo_dict: for i in reversed(sorted(todo_dict.keys())): if todo_dict[i] == True and i in journal: body = body + ELINE.format(DATETIME=journal[i].title, ENTRY=journal[i].entry) body = body + "</table>" return BASEHTML.format( journal=notebook.notebooks[notebook.current_notebook], TITLE=title, BODY=body, dayfilter=TimeStamp().daypart())
def day(self, d2g, offset=0): global METAHDR offset = int(offset) body = "" if d2g is not None and len(d2g) > 0: when = TimeStamp(d2g) if offset < 0: then = when.yesterday() ts = then[0:8] return self.day(ts) #window.location.replace("day?d2g="+ts+"&offset=-1"); elif offset > 0: then = when.tomorrow()[0:8] return self.day(then) #window.location.replace("day?d2g="+then+"&offset=1"); else: then = TimeStamp(d2g) body = """ <title>{dayfilter}</title> <link rel="stylesheet" href="bootstrap/bootstrap.min.css"> <link href="static/style.css" rel="stylesheet"> <script> function dstr2date(dstr) {{ var year = timestamp.substr(0,4); var month = timestamp.substr(4,2)-1; var day = timestamp.substr(6,2); var drdt = new Date(year,month,day,0,0,0,0); }} function oops(timestamp) {{ var temp = String(timestamp); var tslc = temp.slice(0,8); document.getElementById("d2g").text=tslc; document.getElementById("offset").value=-1; //window.location.replace("day?d2g="+tslc+"&offset=-1"); document.getElementById("nomen").submit(); }} function goback(dstr) {{ var temp = String(dstr); var ts = temp.slice(0,8); document.getElementById("d2g").text=ts; document.getElementById("offset").value=1; //window.location.replace("day?d2g="+ts+"&offset=1"); document.getElementById("nomen").submit(); }} </script> </head> <body> <a href="/">Home</a> <form name="nome" id="nomen" method="get" action="day"> <input type="hidden" id="offset" name="offset"> <input type="button" value="Previous" onclick="oops({dayfilter});"> <label for="d2g">DATE: </label> <input type="text" id="d2g" name="d2g" value="{dayfilter}"> <input type="button" value="Next" onclick="goback({dayfilter});"> </form> """ bodylist = aday(d2g) for line in bodylist: body += line if type(then) == type(body): return METAHDR + body.format(dayfilter=then) else: return METAHDR + body.format(dayfilter=then.timestamp()) else: body = """ <title>Jef's Journal</title> <link rel="stylesheet" href="bootstrap/bootstrap.min.css"> <link href="static/style.css" rel="stylesheet"> </head> <body> <a href="/">Home</a> <form name="dome" id="dome" method="get" action="day"> <input type="text" id="d2g" name="d2g"> <input type="submit" value="Find"> </form> """ return METAHDR + body
def __init__(self, name_file): self.name_file = name_file self.timestamp = TimeStamp() self.raw_subtitle = [] self.list_subtitle = [] self.timestamps = []
def add(self, entry, dayfilter=None, interval=None): if dayfilter == None: dayfilter = TimeStamp().timestamp() notes.create_journal_entry(entry, dayfilter, interval) return self.done(filter=dayfilter)
def __init__(self, entry, time=None): self.entry = self.encrypt(entry) if time: self.title=time else: self.title = TimeStamp().timestamp()