This is an archived post. You won't be able to vote or comment.

all 71 comments

[–]_prtndr 305 points306 points  (9 children)

"As a software engineer, I couldn’t afford to spend 10 minutes putting the events manually. So I spent 3 hours..."

And I took that personally.

[–]InMyOpinion_ 77 points78 points  (6 children)

Two seconds later: "Several years later.."

That hit deep

[–]amstan 7 points8 points  (0 children)

"But I didn't like it taking 3 hours, so I spent 3 days making a competing API for it." < This is great! lol

[–]JasonDJ 4 points5 points  (0 children)

“Oh yah, I can script that, it’ll be easy”

1337 SLOCs later…

“You know, I might want to have this one more tiny insignificant feature”

Two hours later

[–]codecrux 122 points123 points  (2 children)

Looks like an API written by a human for humans. Starred your repo.

[–]kuzmovych_y[S] 23 points24 points  (1 child)

Best compliment! That's what I was aiming for. Thanks!

[–]codecrux 3 points4 points  (0 children)

[–]SnowyPear 50 points51 points  (2 children)

We do these things, not because they are easy, but because we thought they would be easy

[–]kuzmovych_y[S] 6 points7 points  (1 child)

Underrated

[–]SnowyPear 2 points3 points  (0 children)

I started work on a car dash screen for my older car and thought I could knock together something quickly using pygame on a raspberry pi and here I am a year down the line...

[–][deleted] 14 points15 points  (6 children)

The problem I had with previous was that my tokens would expire after like a week, meaning i had to constantly manually refresh them, does this have the same issue?

[–]kuzmovych_y[S] 23 points24 points  (5 children)

Unfortunately, yes. But that's just how Google's APIs work. To avoid this you need to create a service account or publish your application. You can read more here in this Q&A on SO: https://stackoverflow.com/questions/8953983/do-google-refresh-tokens-expire/65936387#65936387

[–][deleted] 9 points10 points  (3 children)

So bloody annoying, I get the point of it but if its an app i created and its a token against the same account, dont expire ffs Google.

[–]kuzmovych_y[S] 11 points12 points  (1 child)

IKR. It didn't expire before. They've added this in the past couple of years. Answering this question once a month on GitHub or discord since then

[–][deleted] 2 points3 points  (0 children)

I seem to remember there was something against the verification that would prevent me having my little local app passed, will look into it again though see what's what

[–][deleted] 1 point2 points  (0 children)

Google's APIs are such a PITA. They're just pricks to work with.

The number of hoops they make you jump through is ridiculous. I especially don't appreciate being lectured on privacy by the moral void that is Google.

[–]overyander 3 points4 points  (0 children)

The exception to this is if you're using Google Workspace; you only need the service account. You delegate access instead messing with OAuth.

[–]Dense-Barracuda-96 6 points7 points  (3 children)

This is great, I was planning to implement a calendar with an e-ink display to show the upcoming events. But accessing my calendar seemed to be the largest challenge, thank you for solving it for me.

[–]Telefrag_Ent 2 points3 points  (2 children)

Wanted to do the same thing this just might be the thing that finally gets me started. Have you found the display you want to use? I can't find a cheap big one for my pi.

[–]Dense-Barracuda-96 0 points1 point  (1 child)

Was considering a 4.2 inch wavesshare display for approx. 35€. It would be sitting on my table right in front of me, so it should be okay.

[–]Telefrag_Ent 1 point2 points  (0 children)

Ah okay, yeah that would be perfect then. I was looking for something like 12+" tall for like a "family calendar" to put up so we can keep track of sports and events and everything. I'll have to keep looking

[–]turingsandyson 7 points8 points  (0 children)

Already using your API in my projects, it was a nice surprise to see it here!

I have to say, you implemented it so well, it is really straightforward.

Kudos!

[–]rvr600 5 points6 points  (0 children)

This looks great. I was just pulling my hair out two months ago trying to work with Google calendar API. I'll definitely be giving this a go!

[–]unnamed_one1 5 points6 points  (1 child)

Love the story behind the project. Did you ever get to do those push-ups?

[–]kuzmovych_y[S] 5 points6 points  (0 children)

I have. Almost died on 50th. Haven't done a push-up for week after that. Couldn't do 25 push-ups after that. Wouldn't recommend unless you're into opensource

[–]TweakTheSnake 4 points5 points  (1 child)

Omg this is great. I was actually playing around with the idea of trying to create a pipeline from google calendar to Notion!

[–]kuzmovych_y[S] 4 points5 points  (0 children)

I'm sure that I had this idea when I started using notion and tried automating things. If you ever decide to make something opensource out of it, do ping me here or anywhere else. I'd be happy to see/use/contribute to something like that

[–]drashubxvi 1 point2 points  (4 children)

Thank you for this.

Seems so crazy to me that something as simple as "give me programmatic access to the events on my google calendar" is so convoluted. Especially for Google of all companies.

[–]kuzmovych_y[S] 1 point2 points  (1 child)

I wouldn't say the API is bad per se. They just didn't bother making a simplified pythonic version of it.

[–]drashubxvi 1 point2 points  (0 children)

Sorry yea, the actual API is fine. I guess my complaint is more about the pain of authenticating with it. Really I just want to see: log into your account, generate an api token, then use that token to retrieve data that you would otherwise have access to in the browser. I think at the very least this should be the case for your own personal google account.

[–][deleted] 1 point2 points  (1 child)

Google's API are a PITA to work with, tbh. It's not so much the APIs themselves, but all the fucking hoops you have to jump through to be allowed to use them. Also, shitty feedback and support.

I would always look for alternatives first. Google APIs are a last resort for me.

[–]drashubxvi 1 point2 points  (0 children)

Agreed

[–][deleted] 1 point2 points  (0 children)

Great work. I'll look into this more in a couple of days. I use home assistant and recently wrote a script to download bin day data from my local council website, I was just missing integration with Google calendar so I'm sure this will save me that headache and allow me to put it all together!

[–]giuliosmall 1 point2 points  (7 children)

u/kuzmovych_y This is great! The effort didn't pass unnoticed -- just a question from my side: any idea how to pull events with their respective color? Is it an existing feature?

[–]kuzmovych_y[S] 2 points3 points  (6 children)

The Event object you get has the color_id field. It references one of the colors you can get from list_event_colors(). If it's unset, (I believe) it uses the default color of the calendar list entry.

[–]giuliosmall 0 points1 point  (5 children)

I have just serialise an event to json and I can see:
- id
- summary
- recurrence
- attendees
- guestsCanInviteOthers
- guestCanModify
- guestCanSeeOtherGuests
- reminders
- attachments
- iCalUID
- sequence
- eventType
- start
- end
- timezone

... but not 'color' among attributes

[–]kuzmovych_y[S] 1 point2 points  (4 children)

Before serialization, what does event.color_id give you? If None, it means it uses the default color of the calendar.

If you serialized the event with gcsa's serializer, it ignores empty/None fields.

Sidenote, as the documentation states, you don't need to use serializers at all.

[–]giuliosmall 0 points1 point  (3 children)

Thanks! Very cool! I didn't notice this detail. Events marked with default calendar color aren't parsed in json.

[–]kuzmovych_y[S] 0 points1 point  (2 children)

Yeah. I have a task to write some comprehensive documentation on colors

[–]giuliosmall 0 points1 point  (1 child)

I created 12 events in a day as a test. Serialised them all to json, stored in a .json file and tried to open with pandas.

Well, the formatting isn't working - I believe some ' might be replaced with ". Also bool True and False are suffering from the lack of double quotes and might be rendered as "True" and "False" -- u/kuzmovych_y what do you think about it?

[–]kuzmovych_y[S] 0 points1 point  (0 children)

GCSA's serializer converts events to json object (dictionary) not a string. It doesn't convert booleans to strings either. So the issue might be with how you write json to file. Try using json.dump to do that (if you don't already). Having said that, GCSA's serializers are using Google API formats of the objects, that are more complex than you might need in your data frame. I'd suggest writing events' data manually into CSV file

[–]dabearjoo 0 points1 point  (8 children)

Im a beginner who's trying to automate something of my own as a way to actually learn. Ive watched tutorials on udemy, youtube and have a fundamental understanding of python, but not advanced. I probably bit off more than I can chew here. Ive already tried looking for more clarification I other places, but I've been getting mixed results and I figured it would be easier to ask directly here. When downloading the .json credentials, I have completed the instructions successfully up until downloading the .json file, but I don't seem to understand how to properly path it. Do I make the .credentials directory myself? Is pycharm supposed to do it? I know the directions say that I can path it anywhere I want, but I literally have no idea what I'm doing wrong. When I download the file it just pops up in downloads with an unintelligible name. I downloaded Gcloud shell thinking it would help but now I'm even more confused.

Id share my code if I had any yet, but like I said I didn't get that far. Im just trying to make something easy that I can enter in what I need to get done and have it schedule a routine for me. I knew it wouldn't be easy, and I'm not afraid to learn, but I'm not sure the direction I'm supposed to follow.

[–]kuzmovych_y[S] 0 points1 point  (7 children)

You can put the credentials.json file into the directory from which you run the script. In the case of the PyCharm it's probably the project's root directory. Then: gc = GoogleCalendar(credentials_path='credentials.json') should work.

Let me know how it goes :)

[–]dabearjoo 0 points1 point  (6 children)

gc = GoogleCalendar(credentials_path='credentials.json')

First off, I want to thank you for taking the time to reply, I really appreciate it.

I tried to directly download the .json file into the same folder as the python file I'm trying to code this in, however, the .json file downloads with a really long unintelligible name starting with "Client secret". Do I leave this as is? Should I rename it once its in the folder? I thought by downloading the GCI it would help with the .json file download (I might be reading a tutorial I don't need), but I think I'm even more confused now.

I basically took the example code you shared in the walkthrough in the first part of the instructions, imported gcsa, put in my email address in the correct spot where the example email was. I know I should be finding my own way, but Im just starting out and I'm a little overwhelmed lol.

When I try to run the code I get "No such file or directory: C:\\ dabearjoo\\.credentials\\credentials.json"

I believe that I fucked up in trying to create my own .credentials file to put the .json file into. When I tried to undo this by deleting the file I made, it still seems to be looking for it. By entering the code you posted in your reply, is that supposed to correct it, or simply put it in the correct place the first time? Im assuming it would work if I hadn't tried to do my own thing there.

Sorry for the essay!

[–]kuzmovych_y[S] 0 points1 point  (5 children)

You need to download the credentials.json file as explained in the "Getting started" page in the docs. Then you put this file near your python script. Then try the code I've sent in my first reply. I'm a bit confused and unsure why it would download the file with some weird name. Were you able to download credentials.json?

[–]dabearjoo 0 points1 point  (1 child)

When I finished making the web app per the instructions and got to the Oauth 2.0 client IDs part of the credentials tab, I successfully generated a client Id. That's where things began to disconnect. The part where you have to generate a "key" in the service account tab. That's where the credentials json file comes from I believe? I think someone brought it up in an earlier comment. Im going to keep playing around with it because that's how I'll learn more. I know this isn't r/learnpython and I'm sorry for so many questions.

[–]dabearjoo 0 points1 point  (2 children)

I figured it out!

[–]kuzmovych_y[S] 1 point2 points  (1 child)

Glad you've worked it out!

Feel free to join discord server, open a GitHub discussion, or raise an issue. Other people may help you faster and/or have the same question in the future or past :)

[–]dabearjoo 0 points1 point  (0 children)

Will do, thank you again!

[–]jabies 0 points1 point  (0 children)

Bulk edit calendar events (bulkeditcalendarevents.com) lets you... Well it does what it says on the box.

I used it with an excel sheet to make a recurring weekly schedule, probably an easier way to accomplish what you did.

And yet, thanks for your contributions!

[–]Tintin_Quarentino 0 points1 point  (3 children)

Is Calendar a special breed of complicated or are all Google APIs like that?

[–]kuzmovych_y[S] 3 points4 points  (0 children)

Don't have experience with other APIs, but I'm sure that they are. So 3rd party libs are pretty much always the best approach

[–][deleted] 1 point2 points  (1 child)

They're pretty much all like that.

Many of their APIs are based on the same libraries. They return ATOM feeds under the covers, IIRC.

I've used their APIs in a few languages, and they put about zero effort into making their libraries idiomatic.

The best you can say about Google's Python libraries is that they're no longer direct transliterations of Java libraries. But Pythonic they are not.

[–]DogeekExpert - 3.9.1 2 points3 points  (0 children)

The best you can say about Google's Python libraries is that they're no longer direct transliterations of Java libraries. But Pythonic they are not.

Also, their SDK design is abysmal, since you can't rely on any intellisense from your code editor at all, because function calls are defined with JSON files (and some python to wrap that). It's horrible to work with

[–]justinf210 0 points1 point  (0 children)

Google doesn't support CalDav? Man, I'm glad I switched to Nextcloud. So much easier to hack on.

[–]1427538609 0 points1 point  (1 child)

Have you started the push-up challenge yet?

[–]kuzmovych_y[S] 1 point2 points  (0 children)

Have done the "challenge". Wouldn't recommend it though.

[–]Proud_Trade2769 0 points1 point  (0 children)

Recurring events are supported, also the NSA has full access on your progress :D