def desktop_tracking_file_to_atoms(filename, tag="mail"): content = icalhelper.get_content(filename) matchingcontent = [line for line in content if (tag in line)] TF = "%d/%m/%y %H:%M" atoms = [] for line in matchingcontent: content = line[19:] start = line[11:16] end = line[11:16] date = line[8:10] + "/" + line[5:7] + "/" + line[2:4] atoms.append(Atom(start, end, date, "mail", content, TF)) return atoms
def commandline_file_to_atoms(filename): filecontent = icalhelper.get_content(filename) TF = "%d/%m/%y %H:%M" atoms = [] for line in filecontent: content = line[25:].strip() start = line[16:21] end = line[16:21] date = line[7:9] + "/" + line[10:12] + "/" + line[13:15] atoms.append( Atom(start, end, date, "Command line", " " + content, TF)) return atoms pass
def log_file_to_atoms(filename, title=None): if title == None: title = filename content = icalhelper.get_content(filename) if "title" in content[0]: title = content[0][7:].strip() entries = "\n".join(content).split("######") atoms = [] lastdate = "01/01/10" date = "" entries = entries[1:] for e in entries: atom = Atom() lines = e.split("\n", 1) # atom.content="\n".join(lines[1:]).strip()+"\n" atom.content = lines[1] atom.title = title datetitle = e.split("\n")[0] date = datetitle.split(",")[0] if (len(datetitle.split(",")) > 1): postitle = datetitle.split(",")[1] if len(postitle) > 2: atom.title = postitle date = date.replace("2016-", "16 ") date = date.replace("2017-", "17 ") date = re.sub(r":[0-9][0-9] GMT", "", date) date = re.sub(r":[0-9][0-9] BST", "", date) date = re.sub(r"to [0-9][0-9]/../..", "to", date) if date.find("/") > 0: #Then we have both date and time. newdate = date[:9].strip() atom.start = date[9:9 + 15].strip() atom.date = newdate lastdate = newdate else: atom.start = date.strip() atom.date = lastdate if "to" in atom.start: #Then it was a 'to' construct and has a start and end time atom.end = atom.start[9:] atom.start = atom.start[:5] else: atom.end = atom.start atom.start = atom.start[:5] atom.end = atom.end[:5] atoms.append(atom) return atoms
def heartrate_to_atoms(filename): #01-May-2017 23:46,01-May-2017 23:46,69.0 TF = "%d-%b-%Y %H:%M" timestamplength = len("01-May-2017 23:46") datelength = len("01-May-2017") content = icalhelper.get_content(filename) if (args.d): if args.d: index = int(args.d) * 1500 content = content[len(content) - index:] atoms = [] for a in content: start = a[datelength + 1:timestamplength] date = a[:datelength] end = a[timestamplength + 1 + datelength + 1:(timestamplength * 2) + 1] atoms.append( Atom(start, end, date, "Sleep", "Alive", TF) ) #labeling it sleep is wrong, but it keep the same name for the inversion. atoms.pop(0) return atoms
for x in content: print "XX:" + x if "Clocked" in x: pass else: if "Sleep" in x: if "2016" in x: journey = x.split(',') #print datetime.date.today().strftime(__TIME_FORMAT) #print x journeytime = datetime.datetime.strptime( journey[1].replace('"', ''), __TIME_FORMAT) endtime = datetime.datetime.strptime( journey[2].replace('"', ''), __TIME_FORMAT) icalhelper.add_event(cal, "Sleep", journeytime, endtime) print "event added" + x print "returning with calendar" return cal if __name__ == "__main__": # location="oyster/*.csv" # content=[] # for file in glob.glob(location): # # content.extend(icalhelper.get_content(file)) content = icalhelper.get_content( "/Users/josephreddington/Dropbox/git/flow/watson/oyster/all.csv") icalhelper.write_cal("Oyster.ics", processOyster(content)) #write_cal("Sleep.ics", process_hours(get_content("inputfiles/sleep.csv")))