Extract data from public Google Calendar - python

I am trying to grab the event data from the google calendar here. I am having trouble understanding where to find the calendar id in order to use the api, so the example provided on the api hasnt helped me yet. The only link I can find skimming through the html is this:
https://calendar.google.com/calendar/embed?showTitle=0&showTz=0&height=600&wkst=1&bgcolor=%23FFFFFF&src=phoenixcsd.net_n9i5susso9gnl3cur7vsh8gr6o#group.calendar.google.com&color=%2342104A&src=phoenixcsd.net_ivcl5r5lc9bj0082lpl5ssr3h8#group.calendar.google.com&color=%238C500B&src=phoenixcsd.net_gu6bfruuj9lhbuq9tkrsuahkhc#group.calendar.google.com&color=%2329527A&src=phoenixcsd.net_klr8hsblptggl9qluiidj47k90#group.calendar.google.com&color=%230F4B38&src=en.usa%23holiday#group.v.calendar.google.com&color=%23125A12&src=phoenixcsd.net_4d5gf78r3ili7i499jpoev0m18#group.calendar.google.com&color=%2328754E&src=phoenixcsd.net_9ispj3bk9tlrlsg2sq46ika564#group.calendar.google.com&color=%235F6B02&src=phoenixcsd.net_peaa7tsif8bdk54fs61at335ks#group.calendar.google.com&color=%23AB8B00&ctz=America/New_York
as far as I can tell, one of the strings following the src= is supposed to be the calendar id, but ive tried them all. One example is: phoenixcsd.net_peaa7tsif8bdk54fs61at335ks#group.calendar.google.com
I tried verifying with this, but they all gave errors.
I believe I am missing something simple, so how do I
Access the google calendar in my code
Use the api to extract all events (or at least events between two dates) from the calendar
Store the events in a dataframe
thank you for any help

This Python Quickstart should answer the first two questions. You use Events.list to fetch all the events from your calendar.

Related

Is there any code for finding a certain keyword in twitter

I was wondering if anyone has any sample code for finding a certain keyword in twitter that has been recently posted and has a certain amount of likes within a certain timeframe
preferably in python. Anything related to this would help a lot if you have it. Thank You!
I have personally not done this before, but a simple google search yielded this (a python wrapper for the Twitter API):
https://python-twitter.readthedocs.io/en/latest/index.html
and a GitHub with examples that they linked from their getting started page:
https://github.com/bear/python-twitter/tree/master/examples
There you can find some example code for getting all of a user's tweets and much more.
Iterating through a list of users tweets might be able to do the job here, but if that doesn't cut it I recommend searching the docs linked above for what you need.

Exporting an entire Google Calendar (all of its events) TO A FILE via API

I have eight calendars in Google Calendar each having a bunch of events. I would like to export each of these calendars (with all of their events) to their own file. I'll be using Python to write the script, and the script would run nightly from my crontab.
Does the GCal API actually have (a) method(s) for doing this type of export? How would I go about doing this?
Apologies for such a generalized question -- I'm having trouble even getting started with this problem:
I've looked through the Calendar API Reference and was unable to find any clear method for exporting a calendar to a file.
I searched StackOverflow for [google-calendar-api] export and read through the first nine pages of results and there was only one question resembling my problem. The answer is about three years old and doesn't adequately answer the question (or, I just don't understand the answer enough to make use of it).
There is no method to export calendars in the Calendar API. Also depending on what is your desired output format, the adequate answer may be different. Here are some options that come to my mind:
Using the Google Calendar API. First of all you would need to call CalendarList.list() to obtain all your calendars, and after that use the Events.list() call to obtain every event for each calendar.
Import your calendar as an ICAL file using the Secret Address. The idea is that you can obtain a link to a download file that includes all your calendar information, and you simply have to issue a GET request to it. Bear in mind, however, that this address has to be kept private, as anybody possessing it can access all of your calendar information. You can read more about this in the official documentation here.

Python Twitter Statistics

I need to get the number of people who have followed a certain account by month, also the number of people who have unfollowed the same account by month, the total number of tweets by month, and the total number of times something the account tweeted has been retweeted by month.
I am using python to do this, and have installed python-twitter, but as the documentation is rather sparse, I'm having to do a lot of guesswork. I was wondering if anyone could point me in the right direction? I was able to get authenticated using OAuth, so thats not an issue, I just need some help with getting those numbers.
Thank you all.
These types of statistical breakdowns are not generally available via the Twitter API. Depending on your sample date range, you may have luck using Twittercounter.com's API (you can sign up for an API key here).
The API is rate limited to 100 calls per hour, unless you get whitelisted. You can get results for the previous 14 days. An example request is below:
http://api.twittercounter.com?twitter_id=813286&apikey=[api_key]
The results, in JSON, look like this:
{"version":"1.1","username":"BarackObama","url":"http:\/\/www.barackobama.com","avatar":"http:\/\/a1.twimg.com\/profile_images\/784227851\/BarackObama_twitter_photo_normal.jpg","followers_current":7420937,"date_updated":"2011-04-16","follow_days":"563","started_followers":"2264457","growth_since":5156480,"average_growth":"9166","tomorrow":"7430103","next_month":"7695917","followers_yesterday":7414507,"rank":"3","followers_2w_ago":7243541,"growth_since_2w":177396,"average_growth_2w":"12671","tomorrow_2w":"7433608","next_month_2w":"7801067","followersperdate":{"date2011-04-16":7420937,"date2011-04-15":7414507,"date2011-04-14":7400522,"date2011-04-13":7385729,"date2011-04-12":7370229,"date2011-04-11":7366548,"date2011-04-10":7349078,"date2011-04-09":7341737,"date2011-04-08":7325918,"date2011-04-07":7309609,"date2011-04-06":7306325,"date2011-04-05":7283591,"date2011-04-04":7269377,"date2011-04-03":7257596},"last_update":1302981230}
The retweet stats aren't available from Twittercounter, but you might be able to obtain those from Favstar (although they don't have a public API currently.)
My problem is I also need to get unfollow statistics, which twittercounter does not supply.
My solution was to access the twitter REST API directly, using the oauth2 library in python. I found this very simple compared to some of the other twitter libraries for python out there. This example was particularly helpful: http://parand.com/say/index.php/2010/06/13/using-python-oauth2-to-access-oauth-protected-resources/

Twitter API: Getting Data for Analytics

I am looking to create a simple graph showing 2 numbers of time for my personal twitter. They are:
Number of followers per day
Number of mentions per day
From my research so far, the search API does not provide a date so I am not about to do a GROUP BY. The only way I can have access to dates is through the OAuth Api but that requires interaction from the end user which I am trying to avoid.
Can someone point me in the right direction in order to achieve this? Thanks.
The best way is to use a cron to record the data daily.
However, you can query the mentions using the search api with a untill tag. Which should do the trick.
We can although use the search api to fetch mentions but there is a limit in it.
At a given point of time you can only fetch 200 mentions.
Any one knows how to get total mentions count?

How can I edit a secondary calendar using google python API

I wonder if it's possible to create and delete events with Google API in a secondary calendar. I know well how to do it in main calendar so I only ask, how to change calendar_service to read and write to other calendar.
I've tried loging with secondary calendar email, but that's not possible with BadAuthentication Error. The URL was surely correct, becouse it was read by API.
Waiting for your help.
A'm answering my own question so I can finally accept this one. The problem has been solved some time ago.
The most important answer is in this documentation.
Each query can be run with uri as argument. For example "InsertEvent(event, uri)". Uri can be set manually (from google calendar settings) or automatically, as written in post below. Note, that CalendarEventQuery takes only username, not the whole url.
The construction of both goes this way:
user = "abcd1234#group.calendar.google.com"
uri = "http://www.google.com/calendar/feeds/{{ user }}/private/full-noattendees"
What's useful, is that you can run queries with different uri and add/delete events to many different calendars in one script.
Hope someone finds it helpful.
I got the same issue but I found this solution (I do not remember where)
This solution is to extract the secondary calendar user from its src url provided by google
This is probably not the better one but it's a working one
Note:the code is extracted from a real project [some part has been removed] and must be adapted to your particular case and is provide as sample just to have a support for explaination (It will not work as is)
# 1 - Connect using the main user email address in a classical way
cal_client = gdata.calendar.service.CalendarService()
# insert here after connection stuff
# 2 - For each existing calendars
feed = cal_client.GetAllCalendarsFeed():
# a loop the find the calendar by it's title (cal_title)
for a_calendar in feed.entry:
if cal_title in a_calendar.title.text:
cal_user = a_calendar.content.src.split('/')[5].replace('%40','#')
# If you print a_calendar.content.src.split you will see that the url
# contains an email like definition. This is the one to used to work
# with the calendar
Then you just have to replace the default user by the cal_user in the api to work on the secondary calendar.
Replace call is required because google api function are doing internal conversion on special characters like '%'
I hope this will help you.

Categories

Resources