[fix] string formatting

This commit is contained in:
Adam Tauber 2014-09-04 23:53:13 +02:00
parent 29afa9b4a1
commit 35ddbecd74

View File

@ -22,13 +22,13 @@ number_of_results = 1
# search-url # search-url
base_url = 'https://{language}.wikipedia.org/' base_url = 'https://{language}.wikipedia.org/'
search_url = base_url + 'w/api.php?action=query\ search_url = base_url + 'w/api.php?action=query'\
&list=search\ '&list=search'\
&{query}\ '&{query}'\
&srprop=timestamp\ '&srprop=timestamp'\
&format=json\ '&format=json'\
&sroffset={offset}\ '&sroffset={offset}'\
&srlimit={limit}' '&srlimit={limit}'
# do search-request # do search-request
@ -37,7 +37,7 @@ def request(query, params):
string_args = dict(query=urlencode({'srsearch': query}), string_args = dict(query=urlencode({'srsearch': query}),
offset=offset, offset=offset,
limit=number_of_results) limit=number_of_results)
format_strings = Formatter().parse(base_url) format_strings = list(Formatter().parse(base_url))
if params['language'] == 'all': if params['language'] == 'all':
language = 'en' language = 'en'
@ -46,6 +46,7 @@ def request(query, params):
if len(format_strings) > 1: if len(format_strings) > 1:
string_args['language'] = language string_args['language'] = language
print search_url.format(**string_args)
# write search-language back to params, required in response # write search-language back to params, required in response
params['language'] = language params['language'] = language