apis
¶
-
google.apis.
get_api
(api, **kwargs)[source]¶ Shortcut for creating an API object.
Parameters: Returns: An instance of the created object.
Return type: DriveAPI or PlusAPI or PeopleAPI or DirectoryAPI or GmailAPI or ReportsAPI
Other Functions and Classes¶
The following functions and classes are helpers to the code documented elsewhere.
util
¶
Google API Client Library Page https://developers.google.com/api-client-library/python/reference/pydoc Python Quick Start Page https://developers.google.com/drive/v3/web/quickstart/python
-
class
google.util.
CalDict
[source]¶ A
dict
-like class for storing hourly data for a year.This is intended to have a set of keys that correspond to years. Since Python’s syntax dictates that objects cannot have attributes with names consisting only of numbers (e.g.
cal.2017
), one solution would be to name the year keyscal.y2017
,cal.y2016
, etc. This is the intended convention forCalDict
objects and aligns with how month and day data is named.Once you have created an instance of
CalDict
, you can easily create the structures necessary to store a year’s worth of data like so:>>> cal = CalDict() >>> cal[2017]
Just accessing the
2017
key (which is anint
) assigns its value to be adict
with 12 keys, one for each month, numbered1
through12
. Each of those keys points to adict
object with 31 keys, numbered1
through31
. The day keys point to alist
of 24 integers, initialized to0
. This allows you to increment the value for a particular hour immediately after instantiation, like the following, which increments the counter for the 2 PM hour block on August 31, 2016:>>> cal2 = CalDict() >>> y, m, d = 2016, 8, 31 >>> cal2[y][m][d][14] += 1
Since all months in a
CalDict
instance have 31 days, I recommend you use an external method of validating a particular date before storing or retrieving data.
-
google.util.
get_credentials
(scope=None, application_name=None, secret=None, credential_file=None)[source]¶ Create the credential file for accessing the Google APIs.
https://developers.google.com/drive/v3/web/quickstart/python
Parameters: - scope (str) – String of Scopes separated by spaces to give access to
different Google APIs. Defaults to
SCOPES
. - application_name (str) – Name of this Application. Defaults to
APPLICATION_NAME
. - secret (str) – The secret file given from Google. Should be named
client_secret.json
. Defaults toCLIENT_SECRET_FILE
. - credential_file (str) – Name of the credential file to be created.
Defaults to
CREDENTIAL_FILE
.
Returns: Credential object.
Raises: InvalidCredsError – if the credential file is missing or invalid.
- scope (str) – String of Scopes separated by spaces to give access to
different Google APIs. Defaults to
-
google.util.
set_http
(impersonated_user_email=None)[source]¶ Create and return the Http object used to communicate with Google.
https://developers.google.com/drive/v3/web/quickstart/python
Parameters: impersonated_user_email (str) – Email address of the User to be impersonated. This uses domain wide delegation to do the impersonation. Returns: The Http object. Return type: httplib2.Http Raises: InvalidCredsError – if the credential file is missing or invalid.
-
google.util.
print_json
(obj, sort=False, indent=2)[source]¶ Print the JSON object in a human readable format.
Parameters: Return type:
-
google.util.
convert_mime_type_and_extension
(google_mime_type)[source]¶ Return the conversion type and extension for the given Google MIME type.
Converts mimeType given from google to one of our choosing for export conversion This is necessary to download .g* files.
Information on MIME types:
- https://developers.google.com/drive/v3/web/mime-types
- https://developers.google.com/drive/v3/web/integrate-open
Parameters: google_mime_type (str) – mimeType given from Google API Returns: Tuple in the form (conversion type, extension). If no supported conversion is supported for the given MIME type, the tuple will be (False, False)
.Return type: tuple
const
¶
-
google.const.
CLIENT_SECRET_FILE
= 'client_secret.json'¶ This file is obtained from Google through the API pages. Guide posted below
Look for the “Create authorization credentials” subsection
-
google.const.
CREDENTIAL_FILE
= 'test_creds.json'¶ Name of the file that is made by get_credentials
-
google.const.
APPLICATION_NAME
= 'dbling'¶ Name of the application
-
google.const.
DOWNLOAD_DIRECTORY
= None¶ Optional, if set to a path the user’s drive files will be downloaded to that location
-
google.const.
PAGE_SIZE
= 1000¶ Page size for requests. Specifies the number of records to be returned in a single reply. The accepted range for most requests is [1, 1000].
-
google.const.
SCOPES
= 'https://www.googleapis.com/auth/drive.readonly https://www.googleapis.com/auth/drive.appfolder https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/gmail.readonly https://www.googleapis.com/auth/contacts.readonly https://www.googleapis.com/auth/admin.directory.device.chromeos https://www.googleapis.com/auth/admin.directory.user https://www.googleapis.com/auth/admin.directory.device.mobile.readonly https://www.googleapis.com/auth/admin.directory.customer.readonly https://www.googleapis.com/auth/admin.reports.audit.readonly https://www.googleapis.com/auth/admin.reports.usage.readonly'¶ Scope: https://developers.google.com/drive/v3/web/about-auth
plot
¶
-
google.plot.
HEATMAP_COLORS
= ('#e7f0fa', '#c9e2f6', '#95cbee', '#0099dc', '#4ab04a', '#ffd73e', '#eec73a', '#e29421', '#e29421', '#f05336', '#ce472e')¶ Color scale used by the heat map
-
google.plot.
STOP_FACTOR
= 80¶ Changes how quickly the colors go to the maximum
-
google.plot.
stop
(i)[source]¶ Return the
i
th color stop.In color gradients, the point where a defined color is (as opposed to in between the defined colors, where the colors are “graded”) is called a “stop”. This Python function defines an exponential math function that returns floating point values, in the range of
0
to1
, that define where the gradient stops should occur. In theheatmap()
function, these values will be used to determine the color of each cell based on the normalized values of thez
parameters.The number of stops is determined by the number of colors defined in
HEATMAP_COLORS
. The math function used is below. In it,m = STOP_FACTOR
andn = len(HEATMAP_COLORS)
.\[\frac{m^{(i/(n - 1))} - 1}{m - 1}\]Parameters: i (int) – The current stop number. Must be a value between 0 and len(HEATMAP_COLORS) - 1
, i.e.[0, n)
.Returns: Where the i
th color stop should occur. Will always be a value between 0 and 1.Return type: float Raises: ValueError – When i
isn’t between 0 andlen(HEATMAP_COLORS) -1
.