Skip to content

Instantly share code, notes, and snippets.

@Deepwalker
Created May 4, 2015 20:23
Show Gist options
  • Select an option

  • Save Deepwalker/bcf37a7bc0a7bb277bfc to your computer and use it in GitHub Desktop.

Select an option

Save Deepwalker/bcf37a7bc0a7bb277bfc to your computer and use it in GitHub Desktop.
list_or_string = (t.List(t.String(allow_blank=True)) >> first) | t.String(allow_blank=True)
check_comma_string = list_or_string >> (lambda s: s.split(',')) >> t.List(t.String(allow_blank=True) >> str.strip)
list_or_string_date = (t.List(t.String(allow_blank=True)) >> first) | t.String(allow_blank=True)
parse_ga_qs = t.Dict({
t.Key('start-date') >> 'start': list_or_string_date,
t.Key('end-date') >> 'end': list_or_string_date,
t.Key('dimensions', optional=True): check_comma_string,
t.Key('metrics', optional=True): check_comma_string,
t.Key('segment', optional=True): check_comma_string,
t.Key('filters', optional=True): check_comma_string,
t.Key('sort', optional=True): check_comma_string,
t.Key('range', optional=True): list_or_string_date,
}).ignore_extra('max-results', 'api_url')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment