Python oauth2client.file() Examples

The following are 15 code examples of oauth2client.file(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module oauth2client , or try the search function .
Example #1
Source File: upload.py    From gmail-yaml-filters with MIT License 6 votes vote down vote up
def upload_ruleset(ruleset, service=None, dry_run=False):
    service = service or get_gmail_service()
    known_labels = GmailLabels(service, dry_run=dry_run)
    known_filters = GmailFilters(service)

    for rule in ruleset:
        if not rule.publishable:
            continue

        # See https://developers.google.com/gmail/api/v1/reference/users/settings/filters#resource
        filter_data = rule_to_resource(rule, known_labels)

        if not known_filters.exists(filter_data):
            filter_data['action'] = dict(filter_data['action'])
            filter_data['criteria'] = dict(filter_data['criteria'])
            print('Creating', filter_data['criteria'], filter_data['action'], file=sys.stderr)
            # Strip out defaultdict and set; they won't be JSON-serializable
            request = service.users().settings().filters().create(userId='me', body=filter_data)
            if not dry_run:
                request.execute() 
Example #2
Source File: upload.py    From gmail-yaml-filters with MIT License 6 votes vote down vote up
def get_gmail_credentials(
    scopes=[
        'https://www.googleapis.com/auth/gmail.settings.basic',
        'https://www.googleapis.com/auth/gmail.labels',
    ],
    client_secret_path='client_secret.json',
    application_name='gmail_yaml_filters',
):
    credential_dir = os.path.join(os.path.expanduser('~'), '.credentials')
    credential_path = os.path.join(credential_dir, application_name + '.json')
    if not os.path.exists(credential_dir):
        os.makedirs(credential_dir)

    store = oauth2client.file.Storage(credential_path)
    credentials = store.get()
    if not credentials or credentials.invalid:
        flow = oauth2client.client.flow_from_clientsecrets(client_secret_path, scopes)
        flow.user_agent = application_name
        flags_parser = argparse.ArgumentParser(parents=[oauth2client.tools.argparser])
        credentials = oauth2client.tools.run_flow(flow, store, flags=flags_parser.parse_args([]))
        print('Storing credentials to', credential_path, file=sys.stderr)

    return credentials 
Example #3
Source File: videouploader.py    From Automatic-Youtube-Reddit-Text-To-Speech-Video-Generator-and-Uploader with MIT License 5 votes vote down vote up
def upload(title, description, tags, thumbnailpath, filepath, time_to_upload):
    credentials = get_credentials()
    http = credentials.authorize(httplib2.Http())
    try:#checkcall
        p = subprocess.check_call([settings.python27_location,
                   "%s\\__main__.py" % settings.youtube_upload_location,
                   "--title=%s" % title,
                   "--description=%s" % description,
                   "--category=Entertainment",
                   "--thumbnail=%s"% thumbnailpath,
                   "--tags=%s" % tags,
                   #"--default-language=\"en\"",
                   #"--embeddable=True",
                   "--publish-at=%s" % time_to_upload,
                   "--privacy=private",
                   #"--default-audio-language=\"en\"",
                   "--credentials-file=%s" % settings.google_cred_upload_creds,
                   "--client-secrets=%s" % settings.google_cred_upload,
                   "%s" % filepath], stderr=STDOUT)

    except subprocess.CalledProcessError as e:
        print("Error Occured Uploading Video")
        if e.returncode == 3:
            print("Out of quotes")
        return False
        #print(output)
    # "--thumbnail=%s" % settings.upload_path + thumbnailpath,

    print("successfully finished uploading video")
    return True 
Example #4
Source File: tools.py    From splunk-ref-pas-code with Apache License 2.0 5 votes vote down vote up
def message_if_missing(filename):
  """Helpful message to display if the CLIENT_SECRETS file is missing."""

  return _CLIENT_SECRETS_MESSAGE % filename 
Example #5
Source File: tools.py    From sndlatr with Apache License 2.0 5 votes vote down vote up
def message_if_missing(filename):
  """Helpful message to display if the CLIENT_SECRETS file is missing."""

  return _CLIENT_SECRETS_MESSAGE % filename 
Example #6
Source File: tools.py    From billing-export-python with Apache License 2.0 5 votes vote down vote up
def message_if_missing(filename):
  """Helpful message to display if the CLIENT_SECRETS file is missing."""

  return _CLIENT_SECRETS_MESSAGE % filename 
Example #7
Source File: upload.py    From gmail-yaml-filters with MIT License 5 votes vote down vote up
def get_or_create(self, name):
        try:
            return self[name]
        except KeyError:
            print('Creating label', name, file=sys.stderr)
            if self.dry_run:
                self[name] = fake_label(name)
                return self[name]
            request = self.gmail.users().labels().create(userId='me', body={'name': name})
            created = request.execute()
            self[name] = created
            return self[name] 
Example #8
Source File: upload.py    From gmail-yaml-filters with MIT License 5 votes vote down vote up
def prune_filters_not_in_ruleset(ruleset, service, dry_run=False):
    prunable_filters = find_filters_not_in_ruleset(ruleset, service, dry_run)
    for prunable_filter in prunable_filters:
        print('Deleting', prunable_filter['id'], prunable_filter['criteria'], prunable_filter['action'], file=sys.stderr)
        request = service.users().settings().filters().delete(userId='me', id=prunable_filter['id'])
        if not dry_run:
            request.execute() 
Example #9
Source File: upload.py    From gmail-yaml-filters with MIT License 5 votes vote down vote up
def prune_labels_not_in_ruleset(ruleset, service, match=None, dry_run=False,
                                continue_on_http_error=False):
    known_labels = GmailLabels(service, dry_run=dry_run)
    ruleset_filters = [rule_to_resource(rule, known_labels) for rule in ruleset]

    used_label_ids = set(
        label_id
        for filter_dict in ruleset_filters
        for label_ids in filter_dict['action'].values()
        for label_id in label_ids
    )

    unused_labels = [
        label
        for label in GmailLabels(service, dry_run=dry_run)
        if label['id'] not in used_label_ids
        and label['type'] == 'user'
        and (match is None or match(label['name']))
    ]

    for unused_label in sorted(unused_labels, key=itemgetter('name')):
        print('Deleting label', unused_label['name'], '({})'.format(unused_label['id']), file=sys.stderr)
        request = service.users().labels().delete(userId='me', id=unused_label['id'])
        if not dry_run:
            try:
                request.execute()
            except googleapiclient.errors.HttpError:
                if not continue_on_http_error:
                    raise 
Example #10
Source File: tools.py    From googleapps-message-recall with Apache License 2.0 5 votes vote down vote up
def message_if_missing(filename):
  """Helpful message to display if the CLIENT_SECRETS file is missing."""

  return _CLIENT_SECRETS_MESSAGE % filename 
Example #11
Source File: tools.py    From twitter-for-bigquery with Apache License 2.0 5 votes vote down vote up
def message_if_missing(filename):
  """Helpful message to display if the CLIENT_SECRETS file is missing."""

  return _CLIENT_SECRETS_MESSAGE % filename 
Example #12
Source File: tools.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def message_if_missing(filename):
  """Helpful message to display if the CLIENT_SECRETS file is missing."""

  return _CLIENT_SECRETS_MESSAGE % filename 
Example #13
Source File: tools.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def message_if_missing(filename):
  """Helpful message to display if the CLIENT_SECRETS file is missing."""

  return _CLIENT_SECRETS_MESSAGE % filename 
Example #14
Source File: tools.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def message_if_missing(filename):
  """Helpful message to display if the CLIENT_SECRETS file is missing."""

  return _CLIENT_SECRETS_MESSAGE % filename 
Example #15
Source File: tools.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def message_if_missing(filename):
  """Helpful message to display if the CLIENT_SECRETS file is missing."""

  return _CLIENT_SECRETS_MESSAGE % filename