-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathutils.py
More file actions
30 lines (24 loc) · 1.07 KB
/
utils.py
File metadata and controls
30 lines (24 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
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
})