def get_previous_or_target_headers(page, target_date):
    prev_date = datetime.datetime.strptime(
        "1900-01-01", "%Y-%m-%d").date()  # start date for comparison
    store = page.children[0]
    for child in page.children:
        block_type = child.get("type")
        if "header" in block_type:  # check only headers block
            prop = child.get("properties")
            if prop is None:
                continue
            title = prop["title"]
            date = get_date_from_title(title)
            if date:
                d = NotionDate.from_notion([date])
                if isinstance(
                        d.start,
                        datetime.datetime):  # check only date, ignore time
                    date = d.start.date()
                else:
                    date = d.start
                if date == target_date:  # if date is same return exact date
                    return "exact", child
                else:
                    if prev_date < date < target_date:  # update last item and continue searching
                        store = child
                        prev_date = date
    return "prev", store
 def create_task(self, task):
     title = task['title']
     due_date = task['due_date'] if 'due_date' in task else None
     logging.info("Creating task in notion. Summary: %s - Due date: %s",
                  title, due_date)
     self.page.collection.parent.views
     newrow = self.page.collection.add_row()
     newrow.title = title
     if due_date:
         start_date = due_date.strftime("%Y-%m-%d")
         notionDate = NotionDate.from_notion({"start_date": start_date})
         newrow.due_date = notionDate
     return newrow