Utilities¶
- kingfisher_scrapy.util.components(start, stop=None)[source]¶
Return a function that returns the selected non-empty path components, excluding the
.jsonextension.>>> components(-1)('http://example.com/api/planning.json') 'planning'
>>> components(-2, -1)('http://example.com/api/planning/package.json') 'planning'
- kingfisher_scrapy.util.parameters(*keys, parser=None)[source]¶
Return a function that returns the selected query string parameters.
>>> parameters('page')('http://example.com/api/packages.json?page=1') 'page-1'
>>> parameters('year', 'page')('http://example.com/api/packages.json?year=2000&page=1') 'year-2000-page-1'
- kingfisher_scrapy.util.join(*functions, extension=None)[source]¶
Return a function that joins the given functions’ outputs and sets the file extension, if provided.
>>> join(components(-1), parameters('page'))('http://example.com/api/planning.json?page=1') 'planning-page-1'
- kingfisher_scrapy.util.date_range_by_interval(start, stop, step)[source]¶
Yield date ranges from the
startdate to thestopdate, in intervals ofstepdays, in reverse chronological order.
- kingfisher_scrapy.util.date_range_by_month(start, stop)[source]¶
Yield the first day of the month as a
datefrom thestartto thestopdates, in reverse chronological order.
- kingfisher_scrapy.util.date_range_by_year(start, stop)[source]¶
Return the year as an
intfrom thestartto thestopyears, in reverse chronological order.
- kingfisher_scrapy.util.get_parameter_value(url, key)[source]¶
Return the first value of the query string parameter.
- kingfisher_scrapy.util.replace_parameters(url, **kwargs)[source]¶
Return a URL after updating the query string parameters’ values.
- kingfisher_scrapy.util.append_path_components(url, path)[source]¶
Return a URL after appending path components to its path.
- kingfisher_scrapy.util.add_query_string(method, params)[source]¶
Return a function that yields the requests yielded by the wrapped method, after updating the query string parameter values in each request’s URL.
- kingfisher_scrapy.util.add_path_components(method, path)[source]¶
Return a function that yields the requests yielded by the wrapped method, after appending path components to each request’s URL.
- kingfisher_scrapy.util.items_basecoro(target, prefix, map_type=None, skip_key=None)[source]¶
Replicate the same function from
ijson/common.py.A
skip_keyargument is added. If theskip_keyis in the current path, the current event is skipped. Otherwise, the method is identical.
- kingfisher_scrapy.util.items(events, prefix, map_type=None, skip_key=None)[source]¶
Replicate the same function from
ijson/common.py.A
skip_keyargument is added, which is passed as a keyword argument toitems_basecoro(). Otherwise, the method is identical.