Exemplo n.º 1
0
def parse_icals():
    """
    Parses ical files and writes the results to database.
    """
    parameters_dict = {key: [] for key in KEYWORDS}
    user_classes = []
    #main_classes = []

    user_ical = open(USER_ICAL_PATH, "r").read()
    #main_ical = open(USER_ICAL_PATH, "r").read()

    parameters = _collect_parameters(user_ical, parameters_dict)
    for i in range(len(parameters["DTSTART:"])):
        user_classes.append(AClass(parameters["Subject code: "][i], parameters["SUMMARY:"][i], parameters["Groups: "][i],
                                   parameters["Type: "][i], parameters["DTSTART:"][i], parameters["DTEND:"][i],
                                   parameters["LOCATION:"][i], parameters["Academician: "][i], True))

    # parameters.clear()
    #
    # parameters = _collect_parameters(main_ical, parameters_dict)
    # for i in range(len(parameters["DTSTART:"])):
    #     main_classes.append(AClass(parameters["Subject code: "][i], parameters["SUMMARY:"][i], parameters["Groups: "][i],
    #                                parameters["Type: "][i], parameters["DTSTART:"][i], parameters["DTEND:"][i],
    #                                parameters["LOCATION:"][i], parameters["Academician: "][i], False))
    #
    # dbc.add_to_db(_combine_classes(user_classes, main_classes))
    dbc.add_to_db(user_classes)
Exemplo n.º 2
0
def parse_icals():
    """
    Parses ical files and writes the results to database.
    """
    parameters_dict = {key: [] for key in KEYWORDS}
    user_classes = []
    #main_classes = []

    user_ical = open(USER_ICAL_PATH, "r").read()
    #main_ical = open(USER_ICAL_PATH, "r").read()

    parameters = _collect_parameters(user_ical, parameters_dict)
    for i in range(len(parameters["DTSTART:"])):
        user_classes.append(
            AClass(parameters["Subject code: "][i], parameters["SUMMARY:"][i],
                   parameters["Groups: "][i], parameters["Type: "][i],
                   parameters["DTSTART:"][i], parameters["DTEND:"][i],
                   parameters["LOCATION:"][i], parameters["Academician: "][i],
                   True))

    # parameters.clear()
    #
    # parameters = _collect_parameters(main_ical, parameters_dict)
    # for i in range(len(parameters["DTSTART:"])):
    #     main_classes.append(AClass(parameters["Subject code: "][i], parameters["SUMMARY:"][i], parameters["Groups: "][i],
    #                                parameters["Type: "][i], parameters["DTSTART:"][i], parameters["DTEND:"][i],
    #                                parameters["LOCATION:"][i], parameters["Academician: "][i], False))
    #
    # dbc.add_to_db(_combine_classes(user_classes, main_classes))
    dbc.add_to_db(user_classes)
Exemplo n.º 3
0
 def on_add_reminder_clicked(self, widget):
     from itc_kit.db import dbc
     try:
         reminder = datatypes.Reminder(self.name_entry.get_text(), self.date_entry.get_text())
         dbc.add_to_db(reminder)
         self._info_label = "Reminder added."
     except ValueError:
         self._info_label = "Invalid datetime."
Exemplo n.º 4
0
 def on_add_reminder_clicked(self, widget):
     from itc_kit.db import dbc
     try:
         reminder = datatypes.Reminder(self.name_entry.get_text(),
                                       self.date_entry.get_text())
         dbc.add_to_db(reminder)
         self._info_label = "Reminder added."
     except ValueError:
         self._info_label = "Invalid datetime."
Exemplo n.º 5
0
 def run(self):
     """
     As long as _exit_thread is false, this objects instance will stay active. When it's true, the instance will
     become inactive and should be left for garbage collection by removing all references to it.
     """
     start_time = datetime.now()
     new_activity = Activity(self._type_of_activity, start_time, datetime.now(), self._time)
     dbc.add_to_db(new_activity)
     while not self._exit_thread and settings.get_time_manager_settings()["activated"]:
         sleep(1)
         self.sub_menu_reference._display_label = converting.sec_to_time(self._time)
         self._time += 1
         dbc.update_last_activity(start_time=start_time, end_time=datetime.now())
Exemplo n.º 6
0
 def test_add_to_db(self):
     from itc_kit.timetable import ical
     ical.parse_icals()
     dt = datetime.now()
     dbc.add_to_db(AClass('', '', '', '', dt, dt, '', '', False))
     dbc.add_to_db(Reminder("Reminder name", dt))
     dbc.add_to_db(Activity("Productive", dt, dt, 10))
     dbc.add_to_db(EMail("Sender"))
Exemplo n.º 7
0
 def run(self):
     """
     As long as _exit_thread is false, this objects instance will stay active. When it's true, the instance will
     become inactive and should be left for garbage collection by removing all references to it.
     """
     start_time = datetime.now()
     new_activity = Activity(self._type_of_activity, start_time,
                             datetime.now(), self._time)
     dbc.add_to_db(new_activity)
     while not self._exit_thread and settings.get_time_manager_settings(
     )["activated"]:
         sleep(1)
         self.sub_menu_reference._display_label = converting.sec_to_time(
             self._time)
         self._time += 1
         dbc.update_last_activity(start_time=start_time,
                                  end_time=datetime.now())
Exemplo n.º 8
0
    def get_unread_email(self):
        mail_service = self.connection
        if mail_service is None:
            self.connection = self.connect_to_account()
        else:
#            print("Mail service is not none ->", mail_service)
            result, data = mail_service.uid("search", None, "UNSEEN")
            if self.mail_settings["first_time"]:
                settings.update_settings("EMail", "first_time", False)
                dbc.add_mail_uid(data[0].split())
            else:
                new_mail_uids = dbc.get_mail_not_read(data[0].split())
                mail_notifications = []
                if len(new_mail_uids) != 0:
                    for mail_uid in new_mail_uids:
                        result, data = mail_service.uid('fetch', mail_uid, "(RFC822)")
                        raw_email = data[0][1]
                        #print("Raw email is:", type(raw_email))
                        email_message = email.message_from_bytes(raw_email)
                        mail_notifications.append(EMail(email_message["From"]))
                    #print("nr of notifications added:", len(mail_notifications))
                    dbc.add_to_db(mail_notifications)