I have a problem with google calendar api.
How can you select which calendar to add an event? It add always to default calendar?
thanks
You can list the calendars using the GetOwnCalendarsFeed() and GetAllCalendarsFeed() calls. This will return a list of entries, each of which holds attributes for a given calendar. You need to obtain the calendar's url from the entry.content.src attribute, and use this on your InsertEntry call:
client = calendar.service.CalendarService(email='x', password='y')
feed = client.GetOwnCalendarsFeed()
# map the 'title' -> 'url'
urls = dict((e.title.text, e.content.src) for e in feed.entry)
client.InsertEvent(event, urls['My Calendar'])
Related
I am defining a method which fetches all accountIDs from an organization.
If I am using get_paginator('list_accounts'), then am I okay if I do not check the NextToken?
Code to get the list of all AWS account IDs in the organization:
def get_all_account_ids():
org_client = boto3.client('organizations')
paginator = org_client.get_paginator('list_accounts')
page_iterator = paginator.paginate()
account_ids = []
for page in page_iterator:
for acct in page['Accounts']:
print(acct['Id']) # print the account id
# add to account_ids list
account_ids.append(acct['Id'])
return account_ids
I have seen examples of using either get_paginator() call or while loop checking for NextToken. But I have not seen example using both paginator and NextToken?
No you don't have to check NextToken. That's the point of paginators:
Paginators are a feature of boto3 that act as an abstraction over the process of iterating over an entire result set of a truncated API operation.
searched all entries on the topic and I am close to solution but help is appreciated:
I want to create calendar entries in a non-default calendar in Outlook via python. I did
import win32com.client
outlook = win32com.client.Dispatch('Outlook.Application').GetNamespace('MAPI')
calendar = outlook.Folders('myaccount#mail.com').Folders('calendar').Folders('subcalendar')
I can read entries, count entries of the subcalendar - all good.
Now I try to create a new item in this 'subcalendar' by
newapp = calendar.CreateItem(1)
newapp.Start = '2020-09-25 08:00'
newapp.Subject = 'Testentry'
newapp.Duration = 15
newapp.Save()
throwing error: AttributeError:< unknown >.CreateItem.
I am calling the object 'subcalendar' with the Method CreateItem and the correct object type...seems I am blind but do not see the solution.
Thanks for any help on this!
You can use the following code:
newapp = calendar.Items.Add()
newapp.Start = '2020-09-25 08:00'
newapp.Subject = 'Testentry'
newapp.Duration = 15
newapp.Save()
The Items.Add method creates a new Outlook item in the Items collection for the folder. If the type is not specified, the Type property of the Outlook item defaults to the type of the folder or to MailItem if the parent folder is not typed.
You may find the How To: Create a new Outlook Appointment item article helpful.
I'm trying to extract the emails from all Google Calendar events. I've been following other links (Google Calendar API how to find attendee list) but I'm getting an error
attendees = event['attendees'].get('email', event['attendees'].get('email'))
AttributeError: 'list' object has no attribute 'get'
This is the code
for event in events:
start = event['start'].get('dateTime', event['start'].get('date'))
end = event['end'].get('dateTime', event['end'].get('date'))
attendees = event['attendees'].get('email', event['attendees'].get('email'))
print(attendees)
You can't call get() on a list which I'm guessing event['attendees'] is. You have multiple way of handling this. You can loop through the event['attendees'] and get the email from each individual attendee. You could also use map() to do the same thing
forEach Loop example:
event['attendees'].forEach(attendee => console.log(attendee.get('email')))
map example:
const attendees = event['attendees'].map(attendee => attendee.get('email'))
I am trying to get a policy from boto3 client but there is no method to do so using policy name. By wrapping the create_policy method in a try-except block i can check whether a policy exists or not. Is there any way to get a policy-arn by name using boto3 except for listing all policies and iterating over it.
The ARN should be deterministic given the prefix (if any, and the name).
iam = session.client('iam')
sts = session.client('sts')
# Slow and costly if you have many pages
paginator = iam.get_paginator('list_policies')
all_policies = [policy for page in paginator.paginate() for policy in page['Policies']]
[policy_1] = [p for p in all_policies if p['PolicyName'] == policy_name]
# Fast and direct
account_id = sts.get_caller_identity()['Account']
policy_arn = f'arn:aws:iam::{account_id}:policy/{policy_name}'
policy_2 = iam.get_policy(PolicyArn=policy_arn)['Policy']
# They're equal except with the direct method you'll also get description field
all(policy_1[k] == policy_2[k] for k in policy_1.keys() & policy_2.keys())
You will need to iterate over the policies to get policy names. I am not aware of a get-policy type api that uses policy names only policy ARNs.
Is there a reason that you do not want to get a list of policies? Other than to not download the list.
I'm trying to access to all events of my calendar, hosted on Nextcloud, with python and the caldav library.
With this code:
client = caldav.DAVClient(url) #like "https://..../nextcloud/remote.php/dav/calendars
principal = client.principal()
calendars = principal.calendars()
I can access to all my calendars and iterate over it.
How I can read only a specific calendar, with the name "calendar_name"? In this case I get all calendars, even if I specify the calendar name:
client = caldav.DAVClient(url) #like "https://..../nextcloud/remote.php/dav/calendars/user/calendar_name
principal = client.principal()
calendars = principal.calendars()
If I change the last line of code with calendar_name, I get an empty array.
calendar = principal.calendar('calendar_name')
Note: I can access all calendars and events with the first code posted, but all names are "None", even if the Url is right.
The second snippet still gives you all calendars because you first grab the account (.principal()) and then you list all calendars the account has (principal.calendars()).
The third snippet probably doesn't work because the name (the display name property, not the URL path component) of the calendar quite likely isn't calendar_name but something like Calendar. Theoretically it may even be empty.
To access a single calendar using its URL this may work, didn't try:
client = caldav.DAVClient(url)
calendar = caldav.Calendar(client=client,
url="/nextcloud/remote.php/dav/calendars/user/calendar_name")
Though it may be better to do something like this for various reasons:
client = caldav.DAVClient(url)
principal = client.principal()
calendars = principal.calendars()
calendar = any(c for c in calendars if c.url == your url)
To address your actual question, you need to add more information. If you want the (relative or absolute) URL of the calendar, use something like this:
print calendar.url
If you want to explicitly retrieve the calendar display name, this may work:
print calendar.get_properties([dav.DisplayName()])
Hope this helps.