Skip to content

Commit

Permalink
Fix typo in readme
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzmoyev committed Oct 18, 2024
1 parent 04dc309 commit 7d2fcae
Show file tree
Hide file tree
Showing 137 changed files with 19,274 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Create recurring event
**Suggestion**: use beautiful_date_ to create `date` and `datetime` objects in your
projects (*because its beautiful... just like you*).
projects (*because it's beautiful... just like you*).


References
Expand Down
4 changes: 4 additions & 0 deletions docs/html/.buildinfo
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 added docs/html/.doctrees/acl.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/attachments.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/attendees.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/authentication.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/calendars.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/change_log.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/code/acl.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/code/attachment.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/code/attendees.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/code/calendar.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/code/code.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/code/conference.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/code/event.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/code/free_busy.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/code/google_calendar.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/code/person.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/code/recurrence.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/code/reminders.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/code/settings.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/colors.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/conference.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/environment.pickle
Binary file not shown.
Binary file added docs/html/.doctrees/events.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/free_busy.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/getting_started.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/index.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/recurrence.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/reminders.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/serializers.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/settings.doctree
Binary file not shown.
Binary file added docs/html/.doctrees/why_gcsa.doctree
Binary file not shown.
Binary file added docs/html/_images/push_ups.webp
Binary file not shown.
76 changes: 76 additions & 0 deletions docs/html/_sources/acl.rst.txt
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)
39 changes: 39 additions & 0 deletions docs/html/_sources/attachments.rst.txt
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.
81 changes: 81 additions & 0 deletions docs/html/_sources/attendees.rst.txt
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.
122 changes: 122 additions & 0 deletions docs/html/_sources/authentication.rst.txt
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

Loading

0 comments on commit 7d2fcae

Please sign in to comment.