本文整理汇总了Python中oauth2client.file方法的典型用法代码示例。如果您正苦于以下问题:Python oauth2client.file方法的具体用法?Python oauth2client.file怎么用?Python oauth2client.file使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类oauth2client
的用法示例。
在下文中一共展示了oauth2client.file方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: upload_ruleset
# 需要导入模块: import oauth2client [as 别名]
# 或者: from oauth2client import file [as 别名]
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()
示例2: get_gmail_credentials
# 需要导入模块: import oauth2client [as 别名]
# 或者: from oauth2client import file [as 别名]
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
示例3: upload
# 需要导入模块: import oauth2client [as 别名]
# 或者: from oauth2client import file [as 别名]
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
开发者ID:HA6Bots,项目名称:Automatic-Youtube-Reddit-Text-To-Speech-Video-Generator-and-Uploader,代码行数:32,代码来源:videouploader.py
示例4: message_if_missing
# 需要导入模块: import oauth2client [as 别名]
# 或者: from oauth2client import file [as 别名]
def message_if_missing(filename):
"""Helpful message to display if the CLIENT_SECRETS file is missing."""
return _CLIENT_SECRETS_MESSAGE % filename
示例5: get_or_create
# 需要导入模块: import oauth2client [as 别名]
# 或者: from oauth2client import file [as 别名]
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]
示例6: prune_filters_not_in_ruleset
# 需要导入模块: import oauth2client [as 别名]
# 或者: from oauth2client import file [as 别名]
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()
示例7: prune_labels_not_in_ruleset
# 需要导入模块: import oauth2client [as 别名]
# 或者: from oauth2client import file [as 别名]
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