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