Skip to content

Scrapy, a fast high-level web crawling & scraping framework for Python.

Make check of placeholder less strict

BroodingKangaroo6454d456d2bc
diff --git a/docs/topics/feed-exports.rst b/docs/topics/feed-exports.rst
index 56efa80a7..0bb5f1733 100644
--- a/docs/topics/feed-exports.rst
+++ b/docs/topics/feed-exports.rst
@@ -448,11 +448,12 @@ generated:
* ``%(batch_time)s`` - gets replaced by a timestamp when the feed is being created
(e.g. ``2020-03-28T14-45-08.237134``)
-* ``%(batch_id)0xd`` - gets replaced by the sequence number of the batch.
-By replacing ``x`` with an integer you set the number of leading zeroes to prevent
-inappropriate sorting like this: [``'1'``, ``'10'``, ``'2'``]. Here are some examples:
- ``%(batch_id)01d`` for the second batch gets replaced by ``2``
- ``%(batch_id)05d`` for the third batch gets replaced by ``00003``
+* ``%(batch_id)d`` - gets replaced by the sequence number of the batch.
+
+ Use :ref:`printf-style string formatting <python:old-string-formatting>` to
+ alter the number format. For example, to make the batch ID a 5-digit
+ number by introducing leading zeroes as needed, use ``%(batch_id)05d``
+ (e.g. ``3`` becomes ``00003``, ``123`` becomes ``00123``).
For instance, if your settings include::
diff --git a/scrapy/extensions/feedexport.py b/scrapy/extensions/feedexport.py
index adb6ea2e4..e15c1a09c 100644
--- a/scrapy/extensions/feedexport.py
+++ b/scrapy/extensions/feedexport.py
@@ -375,9 +375,9 @@ class FeedExporter:
%(batch_time)s or %(batch_id)s to distinguish different files of partial output
"""
for uri_template, values in self.feeds.items():
- if values['batch_item_count'] and not re.findall(r'(%\(batch_time\)s|(%\(batch_id\)0\d*d))', uri_template):
+ if values['batch_item_count'] and not re.search(r'%\(batch_time\)s|%\(batch_id\)', uri_template):
logger.error(
- '%(batch_time)s or %(batch_id)0xd must be in uri({}) if FEED_EXPORT_BATCH_ITEM_COUNT setting '
+ '%(batch_time)s or %(batch_id) must be in uri({}) if FEED_EXPORT_BATCH_ITEM_COUNT setting '
'or FEEDS.batch_item_count is specified and greater than 0. For more info see:'
'https://docs.scrapy.org/en/latest/topics/feed-exports.html#feed-export-batch-item-count'
''.format(uri_template)
diff --git a/tests/test_feedexport.py b/tests/test_feedexport.py
index d20b40e2f..4e0b867a4 100644
--- a/tests/test_feedexport.py
+++ b/tests/test_feedexport.py
@@ -1265,7 +1265,7 @@ class BatchDeliveriesTest(FeedExportTestBase):
yield self.assertExported(items, header, rows, settings=Settings(settings))
def test_wrong_path(self):
- """ If path is without %(batch_time)s and %(batch_id)0xd an exception must be raised """
+ """ If path is without %(batch_time)s and %(batch_id) an exception must be raised """
settings = {
'FEEDS': {
self._random_temp_filename(): {'format': 'xml'},