Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions scrapy_azure_exporter/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from scrapy_azure_exporter import AzureFeedStorage
from azure.core.exceptions import ResourceExistsError
from scrapy.pipelines.files import FilesPipeline
from scrapy.utils.project import get_project_settings

settings = get_project_settings()

class AzureFilesStore():
def __init__(self,uri):
self.azure_feed = AzureFeedStorage(
uri = uri,
connection_string = settings.get('AZURE_CONNECTION_STRING',False),
account_url_with_sas_token = settings.get('AZURE_ACCOUNT_URL_WITH_SAS_TOKEN', False),
account_url = settings.get('AZURE_ACCOUNT_URL',False),
account_key = settings.get('AZURE_ACCOUNT_KEY',False)
)

self.basename = self.azure_feed.export_file_name[:]

def persist_file(self, path, buf, info, meta=None, headers= None):
self.azure_feed.export_file_name = os.path.join(self.basename,path)
try:
self.azure_feed._store_in_thread(BytesIO(buf.getvalue()))
except ResourceExistsError:
pass


FilesPipeline.STORE_SCHEMES.update({
'azure': AzureFilesStore
})
Comment on lines +28 to +30

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels a bit hacky. I wonder if, until scrapy/scrapy#1272 is implemented, the way to go about this would be to document how users need to do this themselves.