-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
137 changed files
with
19,274 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# Sphinx build info version 1 | ||
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. | ||
config: 68333a9aee992069f7117cbc272fa955 | ||
tags: 645f666f9bcd5a90fca523b33c5a78b7 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
.. _acl: | ||
|
||
Access Control List | ||
=================== | ||
|
||
Access control rule is represented by the class :py:class:`~gcsa.acl.AccessControlRule`. | ||
|
||
`gcsa` allows you to add a new access control rule, retrieve, update and delete existing rules. | ||
|
||
|
||
To do so, create a :py:class:`~gcsa.google_calendar.GoogleCalendar` instance (see :ref:`getting_started` to get your | ||
credentials): | ||
|
||
.. code-block:: python | ||
from gcsa.google_calendar import GoogleCalendar | ||
gc = GoogleCalendar() | ||
List rules | ||
~~~~~~~~~~ | ||
|
||
.. code-block:: python | ||
for rule in gc.get_acl_rules(): | ||
print(rule) | ||
Get rule by id | ||
~~~~~~~~~~~~~~ | ||
|
||
.. code-block:: python | ||
rule = gc.get_acl_rule(rule_id='<acl_rule_id>') | ||
print(rule) | ||
Add access rule | ||
~~~~~~~~~~~~~~~ | ||
|
||
To add a new ACL rule, create an :py:class:`~gcsa.acl.AccessControlRule` object with specified role | ||
(see more in :py:class:`~gcsa.acl.ACLRole`), scope type (see more in :py:class:`~gcsa.acl.ACLScopeType`), and scope | ||
value. | ||
|
||
.. code-block:: python | ||
from gcsa.acl import AccessControlRule, ACLRole, ACLScopeType | ||
rule = AccessControlRule( | ||
role=ACLRole.READER, | ||
scope_type=ACLScopeType.USER, | ||
scope_value='[email protected]', | ||
) | ||
rule = gc.add_acl_rule(rule) | ||
print(rule.id) | ||
Update access rule | ||
~~~~~~~~~~~~~~~~~~ | ||
|
||
.. code-block:: python | ||
rule = gc.get_acl_rule('<acl_rule_id>') | ||
rule.role = ACLRole.WRITER | ||
rule = gc.update_acl_rule(rule) | ||
Delete access rule | ||
~~~~~~~~~~~~~~~~~~ | ||
|
||
.. code-block:: python | ||
rule = gc.get_acl_rule('<acl_rule_id>') | ||
gc.delete_acl_rule(rule) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
.. _attachments: | ||
|
||
Attachments | ||
----------- | ||
|
||
If you want to add attachment(s) to your event, just create :py:class:`~gcsa.attachment.Attachment` (s) and pass | ||
as a ``attachments`` parameter: | ||
|
||
.. code-block:: python | ||
from gcsa.attachment import Attachment | ||
attachment = Attachment(file_url='https://bit.ly/3lZo0Cc', | ||
title='My file', | ||
mime_type='application/vnd.google-apps.document') | ||
event = Event('Meeting', | ||
start=(22/Apr/2019)[12:00], | ||
attachments=attachment) | ||
You can pass multiple attachments at once in a list. | ||
|
||
.. code-block:: python | ||
event = Event('Meeting', | ||
start=(22/Apr/2019)[12:00], | ||
attachments=[attachment1, attachment2]) | ||
To add attachment to an existing event use its :py:meth:`~gcsa.event.Event.add_attachment` method: | ||
|
||
|
||
.. code-block:: python | ||
event.add_attachment('My file', | ||
file_url='https://bit.ly/3lZo0Cc', | ||
mime_type='application/vnd.google-apps.document') | ||
Update event using :py:meth:`~gcsa.google_calendar.GoogleCalendar.update_event` method to save the changes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
.. _attendees: | ||
|
||
Attendees | ||
========= | ||
|
||
If you want to add attendee(s) to your event, just create :py:class:`~gcsa.attendee.Attendee` (s) and pass | ||
as an ``attendees`` parameter (you can also pass just an email of the attendee and | ||
the :py:class:`~gcsa.attendee.Attendee` will be created for you): | ||
|
||
.. code-block:: python | ||
from gcsa.attendee import Attendee | ||
attendee = Attendee( | ||
'[email protected]', | ||
display_name='Friend', | ||
additional_guests=3 | ||
) | ||
event = Event('Meeting', | ||
start=(17/Jul/2020)[12:00], | ||
attendees=attendee) | ||
or | ||
|
||
.. code-block:: python | ||
event = Event('Meeting', | ||
start=(17/Jul/2020)[12:00], | ||
attendees='[email protected]') | ||
You can pass multiple attendees at once in a list. | ||
|
||
|
||
.. code-block:: python | ||
event = Event('Meeting', | ||
start=(17/Jul/2020)[12:00], | ||
attendees=[ | ||
'[email protected]', | ||
Attendee('[email protected]', display_name='Friend') | ||
]) | ||
To **notify** attendees about created/updated/deleted event use `send_updates` parameter in `add_event`, `update_event`, | ||
and `delete_event` methods. See :py:class:`~gcsa.google_calendar.SendUpdatesMode` for possible values. | ||
|
||
To add attendees to an existing event use its :py:meth:`~gcsa.event.Event.add_attendee` method: | ||
|
||
.. code-block:: python | ||
event.add_attendee( | ||
Attendee('[email protected]', | ||
display_name='Friend', | ||
additional_guests=3 | ||
) | ||
) | ||
or | ||
|
||
.. code-block:: python | ||
event.add_attendee('[email protected]') | ||
to add a single attendee. | ||
|
||
Use :py:meth:`~gcsa.event.Event.add_attendees` method to add multiple at once: | ||
|
||
.. code-block:: python | ||
event.add_attendees( | ||
[ | ||
Attendee('[email protected]', | ||
display_name='Friend', | ||
additional_guests=3 | ||
), | ||
'[email protected]', | ||
'[email protected]' | ||
] | ||
) | ||
Update event using :py:meth:`~gcsa.google_calendar.GoogleCalendar.update_event` method to save the changes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
.. _authentication: | ||
|
||
Authentication | ||
============== | ||
|
||
There are several ways to authenticate in ``GoogleCalendar``. | ||
|
||
Credentials file | ||
---------------- | ||
|
||
If you have a ``credentials.json`` (``client_secret_*.json``) file (see :ref:`getting_started`), ``GoogleCalendar`` | ||
will read all the needed data to generate the token and refresh-token from it. | ||
|
||
To read ``credentials.json`` (``client_secret_*.json``) from the default directory (``~/.credentials``) use: | ||
|
||
.. code-block:: python | ||
gc = GoogleCalendar() | ||
In this case, if ``~/.credentials/token.pickle`` file exists, it will read it and refresh only if needed. If | ||
``token.pickle`` does not exist, it will be created during authentication flow and saved alongside with | ||
``credentials.json`` (``client_secret_*.json``) in ``~/.credentials/token.pickle``. | ||
|
||
To **avoid saving** the token use: | ||
|
||
.. code-block:: python | ||
gc = GoogleCalendar(save_token=False) | ||
After token is generated during authentication flow, it can be accessed in ``gc.credentials`` field. | ||
|
||
To specify ``credentials.json`` (``client_secret_*.json``) file path use ``credentials_path`` parameter: | ||
|
||
.. code-block:: python | ||
gc = GoogleCalendar(credentials_path='path/to/credentials.json') | ||
or | ||
|
||
.. code-block:: python | ||
gc = GoogleCalendar(credentials_path='path/to/client_secret_273833015691-qwerty.apps.googleusercontent.com.json') | ||
Similarly, if ``token.pickle`` file exists in the same folder (``path/to/``), it will be used and refreshed only if | ||
needed. If it doesn't exist, it will be generated and stored alongside the ``credentials.json`` (``client_secret_*.json``) | ||
(in ``path/to/token.pickle``). | ||
|
||
To specify different path for the pickled token file use ``token_path`` parameter: | ||
|
||
.. code-block:: python | ||
gc = GoogleCalendar(credentials_path='path/to/credentials.json', | ||
token_path='another/path/user1_token.pickle') | ||
That could be useful if you want to save the file elsewhere, or if you have multiple google accounts. | ||
|
||
Token object | ||
------------ | ||
|
||
If you store/receive/generate the token in a different way, you can pass loaded token directly: | ||
|
||
.. code-block:: python | ||
from google.oauth2.credentials import Credentials | ||
token = Credentials( | ||
token='<access_token>', | ||
refresh_token='<refresh_token>', | ||
client_id='<client_id>', | ||
client_secret='<client_secret>', | ||
scopes=['https://www.googleapis.com/auth/calendar'], | ||
token_uri='https://oauth2.googleapis.com/token' | ||
) | ||
gc = GoogleCalendar(credentials=token) | ||
It will be refreshed using ``refresh_token`` during initialization of ``GoogleCalendar`` if needed. | ||
|
||
|
||
Multiple calendars | ||
------------------ | ||
To authenticate multiple Google Calendars you should specify different `token_path` for each of them. Otherwise, | ||
`gcsa` would overwrite default token file location: | ||
|
||
.. code-block:: python | ||
gc_primary = GoogleCalendar(token_path='path/to/tokens/token_primary.pickle') | ||
gc_secondary = GoogleCalendar(calendar='[email protected]', | ||
token_path='path/to/tokens/token_secondary.pickle') | ||
Browser authentication timeout | ||
------------------------------ | ||
|
||
If you'd like to avoid your script hanging in case user closes the browser without finishing authentication flow, | ||
you can use the following solution with the help of Pebble_. | ||
|
||
First, install `Pebble` with ``pip install pebble``. | ||
|
||
.. code-block:: python | ||
from gcsa.google_calendar import GoogleCalendar | ||
from concurrent.futures import TimeoutError | ||
from pebble import concurrent | ||
@concurrent.process(timeout=60) | ||
def create_process(): | ||
return GoogleCalendar() | ||
if __name__ == '__main__': | ||
try: | ||
process = create_process() | ||
gc = process.result() | ||
except TimeoutError: | ||
print("User hasn't authenticated in 60 seconds") | ||
Thanks to Teraskull_ for the idea and the example. | ||
|
||
.. _Pebble: https://pypi.org/project/Pebble/ | ||
.. _Teraskull: https://github.com/Teraskull | ||
|
Oops, something went wrong.