Skip to content

Commit

Permalink
Remove functions not needed in quickstart app
Browse files Browse the repository at this point in the history
  • Loading branch information
AndyDiamondstein authored Sep 29, 2017
1 parent aa7b057 commit 62cfdb9
Showing 1 changed file with 0 additions and 52 deletions.
52 changes: 0 additions & 52 deletions python/quickstart_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,66 +100,14 @@ def print_response(response):
'such as <code>playlists.delete()</code>, but it is also ' +
'true for some other methods, such as <code>videos.rate()</code>.')

# Build a resource based on a list of properties given as key-value pairs.
# Leave properties with empty values out of the inserted resource.
def build_resource(properties):
resource = {}
for p in properties:
# Given a key like "snippet.title", split into "snippet" and "title", where
# "snippet" will be an object and "title" will be a property in that object.
prop_array = p.split('.')
ref = resource
for pa in range(0, len(prop_array)):
is_array = False
key = prop_array[pa]

# For properties that have array values, convert a name like
# "snippet.tags[]" to snippet.tags, and set a flag to handle
# the value as an array.
if key[-2:] == '[]':
key = key[0:len(key)-2:]
is_array = True

if pa == (len(prop_array) - 1):
# Leave properties without values out of inserted resource.
if properties[p]:
if is_array:
ref[key] = properties[p].split(',')
else:
ref[key] = properties[p]
elif key not in ref:
# For example, the property is "snippet.title", but the resource does
# not yet have a "snippet" object. Create the snippet object here.
# Setting "ref = ref[key]" means that in the next time through the
# "for pa in range ..." loop, we will be setting a property in the
# resource's "snippet" object.
ref[key] = {}
ref = ref[key]
else:
# For example, the property is "snippet.description", and the resource
# already has a "snippet" object.
ref = ref[key]
return resource

# Remove keyword arguments that are not set
def remove_empty_kwargs(**kwargs):
good_kwargs = {}
if kwargs is not None:
for key, value in kwargs.iteritems():
if value:
good_kwargs[key] = value
return good_kwargs

def channels_list_by_username(client, **kwargs):
kwargs = remove_empty_kwargs(**kwargs) # See full sample for function
response = client.channels().list(
**kwargs
).execute()

return print_response(response)



if __name__ == '__main__':
# When running locally, disable OAuthlib's HTTPs verification. When
# running in production *do not* leave this option enabled.
Expand Down

0 comments on commit 62cfdb9

Please sign in to comment.