#! /usr/bin/env python from datetime import datetime from functools import cmp_to_key days = [ "Ponedeljak", "Utorak", "Sreda", "Cetvrtak", "Petak", "Subota", "Nedelja", ] months = [ "Januar", "Februar", "Mart", "April", "Maj", "Jun", "Jul", "Avgust", "Septembar", "Oktobar", "Novembar", "Decembar", ] today = datetime.today().date() def parse_date(date): return datetime.strptime(date,"%d-%m-%Y").date() def compare_events(one, two): one = parse_date(one.split(", ")[0]) two = parse_date(two.split(", ")[0]) if one>two: return 1 elif one==two: return 0 else: return -1 def is_past_event(event): return event < today def load_events(): events = [] with open("dogadjaji.txt", "rt") as file: file.readline() for event in file.readlines(): event = event.strip() if event != "": events.append(event) return events def write_events(events): with open("dogadjaji.txt", "wt") as file: file.write("datum, vreme, lokacija, tema\n") for event in events: file.write(event+"\n") def sort_events(events): return sorted(events, key = cmp_to_key(compare_events)) events = load_events() events = sort_events(events) write_events(events) start = "
Datum | \nVreme | \nMesto | \nTema | \n
---|