def setup_date(self): """ Responsible for setting up date variables, self.date and self.custom_date """ if self.search_date == "same day": self.date = today() elif self.search_date == "next day": self.date = tomorrow() elif self.search_date == "day before": self.date = yesterday() else: raise Nothing self.custom_date = custom_strftime("%A %B {S}, %Y", self.date) print(self.date)
def date_objects(self): """ Returns the startdate and enddate as a datetime objects None means we don't have them Processing only happens once, results are stored as private internal objects You can reset it if you need to by setting _date_objects to None """ if hasattr(self, "_date_objects") and not self._date_objects == None: return self._date_objects if not hasattr(self, "start_date") or not hasattr(self, "end_date"): return (None, None) if not self.start_date: return (None, None) date_objects = [] # Dates to compare to, needed because strings need to be converted into datetime objects for this_date in ( re.search(r"\((.*)\)$", self.start_date).group(1), re.search(r"\((.*)\)$", self.end_date).group(1) if self.end_date else None, ): if not this_date: date_objects.append(None) else: split = this_date.split(" ") try: remove_non_digits = lambda x: int(re.sub(r"[^0-9]", "", x)) this_day = remove_non_digits(split[0]) except ValueError: return (None, None) try: this_month = self._months.get(split[1].lower()) except ValueError: return (None, None) if not this_month: return (None, None) try: this_year = int(split[2]) except (IndexError, ValueError): this_year = today().year - 1 date_objects.append(datetime.date(this_year, this_month, this_day)) if not date_objects: date_objects = (None, None) self._date_objects = date_objects # stores this for later so we don't have to process it all over again return self._date_objects
# raise NotImplemented def get_subject(self, just_date=False): if just_date: return self.subject_output[20:] else: return self.subject_output def get_html(self, first_p_block=""): d = { 'first_p_block':first_p_block } return self.html_output.format(**d) def tag_not_found(self, tag): """ What to do? """ pass if __name__ == "__main__": notices = Student_Notices() # TURN ON THE ABILITY TO CLICK "EDIT" NEXT TO EACH ONE. # THIS REQUIRES THAN A dbid FIELD BE CREATED ON THE SERVER SIDE # TODO: STREAMLINE THIS BETTER if notices.settings.email: notices.email_editing = True notices.email_to_agents() if notices.settings.wordpress: notices.email_editing = False notices.post_to_wordpress('secondarystudentannouncements', datetime.time(hour=19,minute=5,second=0), date=today())
def first(self): """ Return the first date to start with, default is today """ return today()