I have a class in pipelines.py that sends and threads to my server's API:
class MyPipeline:
def process_item(self, item, spider):
data = {
"source_id": 'name_of_the_running_spider,
"token": "token",
"products": [dict(item)],
}
headers = {'Content-Type': 'application/json'}
url = 'http://for.example.com/my-api/'
requests.post(url=url, headers=headers, data=json.dumps(data))
return item
The problem is that the pipeline sends each time under one item ("products": [dict(item)]). Is it possible to somehow pass a list items to "products" (for example [dict(item)*10])? If in the spider itself, it can be organized using a loop and a counter, but how to implement it through pipeline.py