def prepare_processed(self, to, when, body, sender): self.to = to self.when = when self.body = body self.sender = sender self.followup_type = None # stores the available choices when the user needs to clarify the correct attendee self.uncertain_attendee = None self.unknown_attendee = None if not sender: raise NoSenderError("No sender found!") if not isinstance(self.when["start"], datetime): return self.prompt_date() if not body: return self.prompt_body() settings = sender["email"] username = settings.get("username") google = Google(username) calendar = google.calendar(settings) self.calendar = calendar # Parse attendees (try to resolve email addresses) parsed_attendees = get_emails(self.to, sender) attendees = parsed_attendees["emails"] for (name, candidates) in parsed_attendees["uncertain"]: self.uncertain_attendee = (name, candidates) return prompt_contact_choice(name, candidates, self) for name in parsed_attendees["unknown"]: self.unknown_attendee = name return self.prompt_unknown_contact(name) event = calendar.event(self.when["start"], self.when["end"], attendees, self.body) self.event = event self.description = ( f"The event {self.body} at {self.when['start'].strftime('%H:%M, %A, %d. %B %Y')} " + "was prepared\nDo you want to book it?") # Check if we are busy me_busy = self.calendar.freebusy(self.when["start"], self.when["end"], ["primary"]) to_busy = calendar.freebusy(self.when["start"], self.when["end"], to) other = f"{', '.join(to_busy[:-1])} and {to_busy[-1]}" if len( to_busy) > 1 else "".join(to_busy) if me_busy and to_busy: question = f"\nYou as well as {other} seem to be busy. Do you want to book the meeting anyway?" return self.busy_prompt(question) elif me_busy: question = "\nYou seem to be busy during this meeting. Do you want to book it anyway?" return self.busy_prompt(question) elif to_busy: question = f"\n{other} seem to be busy during this meeting. Do you want to book it anyway?" return self.busy_prompt(question)
def prepare_processed(self, to, when, body, sender): self.to = to self.when = when self.body = body self.sender = sender self.followup_type = None # if the event has already been found then just prompt the user if self.event: self.description = self.get_task_description(self.event) return None # try to fetch the event by the summary if body["summary"] != "": self.events = self.calendar.get_event_by_summary(body["summary"]) # if no event could be found using the summary try to do it with the user inputed time if (not self.events) and self.when: self.events = self.calendar.get_event_by_timestamp(self.when) if (not self.events) and self.to: # get emails of participants where only the name was entered attendees = [] parsed_attendees = contacts.get_emails(self.to) for email in parsed_attendees["emails"]: attendees.append(email) for (name, candidates) in parsed_attendees["uncertain"]: self.uncertain_attendee = (name, candidates) return prompt_contact_choice(name, candidates) contacts.get_emails(self.to) if len(attendees) > 0: self.events = self.calendar.get_event_by_participants( attendees) if len(self.events) == 1: self.event = self.events[0] elif len(self.events) > 1: return self.prompt_multiple() else: raise NoEventFoundError("Could not find an event.") self.description = self.get_task_description(self.event)
def test_name_is_email(self, four_local_contacts): """ Test that an email will be added to the known emails """ names = ["*****@*****.**", "test@noemail"] res = get_emails(names) assert res["emails"] == ["*****@*****.**"] assert res["uncertain"] == [] assert res["unknown"] == ["test@noemail"]
def test_unknown(self, four_local_contacts): """ Test that an input name that is not in the local contacts will be returned as unknown """ names = ["aron"] res = get_emails(names) assert res["emails"] == [] assert res["uncertain"] == [] assert res["unknown"] == ["aron"]
def test_known(self, four_local_contacts): """ Test that names that exist in the contact book will return the email of the contacts """ names = ["niklas", "mark"] res = get_emails(names) assert res["emails"] == ["*****@*****.**", "*****@*****.**"] assert res["uncertain"] == [] assert res["unknown"] == []
def test_uncertain(self, four_local_contacts): """ Test that names that can be connected to multiple contacts returns all the candidates as uncertain """ names = ["hug", "mark"] res = get_emails(names) assert res["emails"] == ["*****@*****.**"] assert res["uncertain"] == [("hug", [("hugotwo", "*****@*****.**"), ("hugo", "*****@*****.**")])] assert res["unknown"] == []
def test_all(self, four_local_contacts): """ Test that it correctly handles multiple names """ names = ["*****@*****.**", "hug", "aron", "mark", "gustav", "niklas"] res = get_emails(names) assert res["emails"] == [ "*****@*****.**", "*****@*****.**", "*****@*****.**" ] assert res["uncertain"] == [("hug", [("hugotwo", "*****@*****.**"), ("hugo", "*****@*****.**")])] assert res["unknown"] == ["aron", "gustav"]
def prepare_processed(self, to, when, body, sender): crypt = Crypt() self.to = to self.when = when self.body = body if not sender: raise NoSenderError("No sender found!") self.followup_type = None self.sender = sender self.settings = sender["email"] self.username = self.settings.get("username") self.password = crypt.decrypt(self.settings.get( "password")) if self.settings.get("password") else None self.subject = body.partition("\n")[0] self.content = body + f"\n\nRegards,\n{sender['name']}" if not to or len(to) == 0: return self.prompt_receiver() elif len(to) > 1: raise ToManyReceiversError( "Can only handle one (1) receiver at this time") if not body: return self.prompt_body() parsed_recipients = get_emails(self.to, sender) self.receiver = parsed_recipients["emails"] for (name, candidates) in parsed_recipients["uncertain"]: self.uncertain_attendee = (name, candidates) return prompt_contact_choice(name, candidates, self) for name in parsed_recipients["unknown"]: raise NoContactFoundError( "\nCould not find any contacts with name " + name) if len(self.receiver) == 1: self.description = f"The email {self.subject} to {self.receiver[0]} was prepared.\nDo you want to send it?" else: self.description = ( f"The email {self.subject} to {self.receiver[0]} etc. was prepared.\nDo you want to send it?" )