Esempio n. 1
0
 def __str__(self) -> str:
     """Returns the attendee in an iCalendar format."""
     return str(
         ContentLine('ORGANIZER',
                     params=self._get_params(),
                     value='mailto:%s' % self.email))
Esempio n. 2
0
 def serialize_description(event: "Event", container: "Container"):
     if event.description:
         container.append(
             ContentLine("DESCRIPTION",
                         value=escape_string(event.description)))
Esempio n. 3
0
 def serialize_geo(event: "Event", container: "Container"):
     if event.geo:
         container.append(ContentLine("GEO", value="%f;%f" % event.geo))
Esempio n. 4
0
 def serialize_status(event: "Event", container: "Container"):
     if event.status:
         container.append(ContentLine("STATUS", value=event.status))
Esempio n. 5
0
 def serialize_duration(event: "Event", container: "Container"):
     if event.end_representation == "duration":
         duration = event.duration
         assert duration is not None
         container.append(
             ContentLine("DURATION", value=serialize_duration(duration)))
Esempio n. 6
0
    def test_multiple_unique_required(self):
        cont = Container("TEST")
        cont.append(ContentLine(name="OTHER", value="anything"))

        with self.assertRaises(ValueError):
            CT4._from_container(cont)
Esempio n. 7
0
 def serialize_some_attr2bis(test, container):
     if test.some_attr2:
         container.append(
             ContentLine('ATTR2', value=test.some_attr2.upper()))
 def serialize_location(todo: "Todo", container: Container):
     if todo.location:
         container.append(
             ContentLine("LOCATION", value=escape_string(todo.location))
         )
 def serialize_percent(todo: "Todo", container: Container):
     if todo.percent is not None:
         container.append(ContentLine("PERCENT-COMPLETE", value=str(todo.percent)))
 def serialize_description(todo: "Todo", container: Container):
     if todo.description:
         container.append(
             ContentLine("DESCRIPTION", value=escape_string(todo.description))
         )
 def serialize_start(todo: "Todo", container: Container):
     if todo.begin:
         container.append(ContentLine("DTSTART", value=arrow_to_iso(todo.begin)))
 def serialize_created(todo: "Todo", container: Container):
     if todo.created:
         container.append(ContentLine("CREATED", value=arrow_to_iso(todo.created)))
 def serialize_completed(todo: "Todo", container: Container):
     if todo.completed:
         container.append(
             ContentLine("COMPLETED", value=arrow_to_iso(todo.completed))
         )
Esempio n. 14
0
 def serialize_0version(calendar,
                        container):  # 0version will be sorted first
     container.append(ContentLine("VERSION", value="2.0"))
Esempio n. 15
0
 def serialize_calscale(calendar, container):
     if calendar.scale:
         container.append(
             ContentLine("CALSCALE", value=calendar.scale.upper()))
 def serialize_priority(todo: "Todo", container: Container):
     if todo.priority is not None:
         container.append(ContentLine("PRIORITY", value=str(todo.priority)))
Esempio n. 17
0
 def serialize_method(calendar, container):
     if calendar.method:
         container.append(
             ContentLine("METHOD", value=calendar.method.upper()))
 def serialize_summary(todo: "Todo", container: Container):
     if todo.name:
         container.append(ContentLine("SUMMARY", value=escape_string(todo.name)))
Esempio n. 19
0
 def serialize_some_attr(test, container):
     if test.some_attr:
         container.append(ContentLine('ATTR', value=test.some_attr.upper()))
 def serialize_url(todo: "Todo", container: Container):
     if todo.url:
         container.append(ContentLine("URL", value=escape_string(todo.url)))
Esempio n. 21
0
    def test_required_raises(self):
        cont = Container("TEST")
        cont.append(ContentLine(name="PLOP", value="plip"))

        with self.assertRaises(ValueError):
            CT2._from_container(cont)
 def serialize_due(todo: "Todo", container: Container):
     if todo._due_time:
         container.append(ContentLine("DUE", value=arrow_to_iso(todo._due_time)))
Esempio n. 23
0
 def serialize_class(event: "Event", container: "Container"):
     if event.classification:
         container.append(ContentLine("CLASS", value=event.classification))
 def serialize_duration(todo: "Todo", container: Container):
     if todo._duration:
         representation = timedelta_to_duration(todo._duration)
         container.append(ContentLine("DURATION", value=representation))
Esempio n. 25
0
 def serialize_summary(event: "Event", container: "Container"):
     if event.name:
         container.append(
             ContentLine("SUMMARY", value=escape_string(event.name)))
 def serialize_status(todo: "Todo", container: Container):
     if todo.status:
         container.append(ContentLine("STATUS", value=todo.status))
Esempio n. 27
0
 def serialize_location(event: "Event", container: "Container"):
     if event.location:
         container.append(
             ContentLine("LOCATION", value=escape_string(event.location)))
Esempio n. 28
0
 def serialize_version(calendar, container):
     container.append(ContentLine("VERSION", value="2.0"))
Esempio n. 29
0
 def serialize_url(event: "Event", container: "Container"):
     if event.url:
         container.append(ContentLine("URL",
                                      value=escape_string(event.url)))
Esempio n. 30
0
def main(ref_calendar_path, target):
    # load created calendar
    LOGGER.info(f'pcr_ics start! version {__version__}')
    LOGGER.info(f'ref_calendar_path {ref_calendar_path}')

    target = Path(target)
    if target.exists():
        target.unlink()

    if ref_calendar_path != 'none':
        if ref_calendar_path.startswith('http'):
            try:
                res = requests.get(ref_calendar_path)
                res.encoding = 'utf-8'
                with open(target, 'wb') as fp:
                    fp.write(res.content)
            except requests.exceptions.RequestException as ex:
                LOGGER.error(f'request error when fetching ref_calendar')
                LOGGER.error(ex)
                raise ex
        else:
            ref_calendar_path = Path(ref_calendar_path)
            if ref_calendar_path.exists():
                shutil.copy(ref_calendar_path, target)

    if target.exists():
        with target.open('r', encoding='utf-8') as fp:
            calendar = Calendar(fp.read())
    else:
        calendar = create_new_calendar()

    # to make it simple, I parse db version by myself
    query_calendar_db_version_line = [
        cl for cl in calendar.extra if cl.name == DB_VERSION_KEY
    ]
    if len(query_calendar_db_version_line) == 1:
        calendar_db_version_line = query_calendar_db_version_line[0]
    else:
        calendar_db_version_line = ContentLine(DB_VERSION_KEY)
        calendar.extra.append(calendar_db_version_line)
    calendar_db_version = calendar_db_version_line.value or None
    LOGGER.info(f'calendar_db_version {calendar_db_version}')

    # fetch db
    try:
        db = Database()
        if db.latest_version == calendar_db_version:
            LOGGER.info(f'calendar is up to date')
            if IS_GITHUB_ACTIONS:
                github_sha = os.environ.get('GITHUB_SHA')
                if github_sha:
                    sha_str = f'from {github_sha} '
                else:
                    sha_str = ''
                set_output(
                    'PCR_ICS_COMMIT',
                    f'deploy: triggered update {sha_str}(github_actions)')
            return
        db.download_latest()
    except requests.exceptions.RequestException as ex:
        LOGGER.error(f'request error when updating db')
        LOGGER.error(ex)
        raise ex

    calendar_db_version_line.value = db.latest_version

    calendar = generate_calendar(db, calendar)
    calendar = prettify_calendar(calendar)
    LOGGER.info(f'generate_calendar OK')
    with open(target, 'w', encoding='utf-8', newline='\n') as fp:
        fp.write(str(calendar))
    LOGGER.info(f'target {target} is saved!')

    if IS_GITHUB_ACTIONS:
        set_output(
            'PCR_ICS_COMMIT',
            f'deploy: bump ics file to version {db.latest_version} (github_actions)'
        )