Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

help getting values from ics file #425

Closed
Tracked by #443
C-Powers opened this issue Sep 30, 2022 · 3 comments
Closed
Tracked by #443

help getting values from ics file #425

C-Powers opened this issue Sep 30, 2022 · 3 comments

Comments

@C-Powers
Copy link

Hi there, I'm using this package to parse a file. I looked in the docs, but there doesn't seem to be much documentation on how to do this. This is what I've got, and it kinda works, but I'm not getting the native python types out of it.

I have vText to string, vDDDTypes to datetime, and vCalAddress to string that I need to parse.

Thanks for the help!

As an example:

gcal = Calendar.from_ical(content)
out: dict[str, Union[str, datetime]] = {}
for component in gcal.walk():
    if component.name == "VEVENT":
        print(component.get("UID"), type(component.get("UID")))
        print(
            vText.from_ical(component.get("UID")),
            type(vText.from_ical(component.get("UID"))),
        )
        

"""
prints:
[radact]@google.com <class 'icalendar.prop.vText'>
[radact]@google.com <class 'icalendar.prop.vText'>
"""
@C-Powers
Copy link
Author

ah, I think it's to_ical instead of from_ical.

@C-Powers
Copy link
Author

Sorry for the false alarm, I had to rubber duck myself, but this may be nice for someone in the future.

gcal = Calendar.from_ical(content)
    out: dict[str, Any] = {}
    for component in gcal.walk():
        if component.name == "VEVENT":
            out["id"] = vText.to_ical(component.get("UID")).decode("utf-8")

            out["start"] = vDDDTypes.to_ical(component.get("DTSTART")).decode("utf-8")  # type: ignore
            out["end"] = vDDDTypes.to_ical(component.get("DTEND")).decode("utf-8")  # type: ignore

            out["summary"] = vText.to_ical(component.get("SUMMARY")).decode("utf-8")
            out["description"] = vText.to_ical(component.get("DESCRIPTION")).decode(
                "utf-8"
            )
            out["location"] = vText.to_ical(component.get("LOCATION")).decode("utf-8")
            attendees = []
            for a in component.get("ATTENDEE"):
                attendees.append(vCalAddress.to_ical(a).decode("utf-8"))
            out["attendees"] = attendees

            out["google_meet_url"] = vText.to_ical(
                component.get("X-GOOGLE-CONFERENCE")
            ).decode("utf-8")
            ```

@abe-101
Copy link
Contributor

abe-101 commented Dec 19, 2022

@C-Powers Can you provide a example ical file that you parsed with the above script?

I'd like to add it as an example to the docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants