documente_shared 0.1.2__py3-none-any.whl → 0.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of documente_shared might be problematic. Click here for more details.
- documente_shared/domain/entities.py +7 -3
- documente_shared/domain/repositories.py +1 -1
- documente_shared/infrastructure/dynamo_repositories.py +11 -4
- documente_shared/infrastructure/dynamo_table.py +75 -0
- documente_shared/infrastructure/s3_bucket.py +38 -0
- {documente_shared-0.1.2.dist-info → documente_shared-0.1.3.dist-info}/METADATA +1 -1
- documente_shared-0.1.3.dist-info/RECORD +13 -0
- documente_shared-0.1.2.dist-info/RECORD +0 -11
- {documente_shared-0.1.2.dist-info → documente_shared-0.1.3.dist-info}/WHEEL +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
from dataclasses import dataclass
|
|
2
2
|
from datetime import datetime
|
|
3
|
+
from decimal import Decimal
|
|
3
4
|
from typing import Optional
|
|
4
5
|
|
|
5
6
|
from documente_shared.domain.enums import DocumentProcessStatus
|
|
@@ -12,7 +13,7 @@ class DocumentProcess(object):
|
|
|
12
13
|
file_path: str
|
|
13
14
|
processed_csv_path: str
|
|
14
15
|
processed_xlsx_path: str
|
|
15
|
-
processing_time: Optional[
|
|
16
|
+
processing_time: Optional[Decimal] = None
|
|
16
17
|
enqueued_at: Optional[datetime] = None
|
|
17
18
|
started_at: Optional[datetime] = None
|
|
18
19
|
failed_at: Optional[datetime] = None
|
|
@@ -72,7 +73,10 @@ class DocumentProcess(object):
|
|
|
72
73
|
'file_path': self.file_path,
|
|
73
74
|
'processed_csv_path': self.processed_csv_path,
|
|
74
75
|
'processed_xlsx_path': self.processed_xlsx_path,
|
|
75
|
-
'processing_time':
|
|
76
|
+
'processing_time': (
|
|
77
|
+
str(self.processing_time)
|
|
78
|
+
if self.processing_time else None
|
|
79
|
+
),
|
|
76
80
|
'enqueued_at': self.enqueued_at.isoformat() if self.enqueued_at else None,
|
|
77
81
|
'started_at': self.started_at.isoformat() if self.started_at else None,
|
|
78
82
|
'failed_at': self.failed_at.isoformat() if self.failed_at else None,
|
|
@@ -88,7 +92,7 @@ class DocumentProcess(object):
|
|
|
88
92
|
processed_csv_path=data.get('processed_csv_path'),
|
|
89
93
|
processed_xlsx_path=data.get('processed_xlsx_path'),
|
|
90
94
|
processing_time=(
|
|
91
|
-
data.get('processing_time')
|
|
95
|
+
Decimal(data.get('processing_time'))
|
|
92
96
|
if data.get('processing_time') else None
|
|
93
97
|
),
|
|
94
98
|
enqueued_at=(
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
from documente_shared.domain.entities import DocumentProcess
|
|
2
2
|
from documente_shared.domain.repositories import DocumentProcessRepository
|
|
3
|
+
from documente_shared.infrastructure.dynamo_table import DynamoDBTable
|
|
3
4
|
|
|
4
5
|
|
|
5
|
-
class DynamoDocumentProcessRepository(
|
|
6
|
+
class DynamoDocumentProcessRepository(
|
|
7
|
+
DynamoDBTable,
|
|
8
|
+
DocumentProcessRepository,
|
|
9
|
+
):
|
|
10
|
+
|
|
6
11
|
def persist(self, instance: DocumentProcess) -> DocumentProcess:
|
|
7
|
-
|
|
12
|
+
self.put(instance.to_dict)
|
|
13
|
+
return instance
|
|
14
|
+
|
|
8
15
|
|
|
9
|
-
def
|
|
10
|
-
|
|
16
|
+
def remove(self, instance: DocumentProcess):
|
|
17
|
+
self.delete(key=instance.digest)
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
|
|
3
|
+
import boto3
|
|
4
|
+
from boto3.dynamodb.conditions import Key
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
RETURN_VALUES = 'UPDATED_NEW'
|
|
8
|
+
|
|
9
|
+
@dataclass
|
|
10
|
+
class DynamoDBTable(object):
|
|
11
|
+
table_name: str
|
|
12
|
+
|
|
13
|
+
def __post_init__(self):
|
|
14
|
+
self._table = boto3.resource('dynamodb').Table(self.table_name)
|
|
15
|
+
|
|
16
|
+
def get(self, key: str):
|
|
17
|
+
return self._table.get_item(Key=key).get('Item')
|
|
18
|
+
|
|
19
|
+
def get_all(self):
|
|
20
|
+
return self._table.scan().get('Items')
|
|
21
|
+
|
|
22
|
+
def upsert(self, key, attributes):
|
|
23
|
+
return self.put({**key, **attributes})
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def filter_by(self, attribute, target_value):
|
|
27
|
+
return self._table(
|
|
28
|
+
FilterExpression=Key(attribute).eq(target_value),
|
|
29
|
+
).get('Items')
|
|
30
|
+
|
|
31
|
+
def put(self, attributes: dict, condition: dict = None):
|
|
32
|
+
extra_args = {}
|
|
33
|
+
if condition:
|
|
34
|
+
extra_args['ConditionExpression'] = condition
|
|
35
|
+
return self._table.put_item(Item=attributes, **extra_args)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def update(self, key: str, attributes: dict):
|
|
39
|
+
return self._table.update_item(
|
|
40
|
+
Key=key,
|
|
41
|
+
UpdateExpression=self._update_expression(attributes),
|
|
42
|
+
ExpressionAttributeNames=self._expression_attribute_names(attributes),
|
|
43
|
+
ExpressionAttributeValues=self._expression_attribute_values(attributes),
|
|
44
|
+
ReturnValues=RETURN_VALUES,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
def delete(self, key: str):
|
|
48
|
+
return self._table.delete_item(Key=key)
|
|
49
|
+
|
|
50
|
+
def count(self) -> int:
|
|
51
|
+
return self._table.item_count
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
@classmethod
|
|
55
|
+
def _update_expression(cls, attributes):
|
|
56
|
+
return 'SET {param}'.format(
|
|
57
|
+
param=','.join(
|
|
58
|
+
'#{key}=:{key}'.format(
|
|
59
|
+
key=key,
|
|
60
|
+
)
|
|
61
|
+
for key in attributes
|
|
62
|
+
),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
@classmethod
|
|
66
|
+
def _expression_attribute_names(cls, attributes):
|
|
67
|
+
return {
|
|
68
|
+
'#{key}'.format(key=key): key for key in attributes
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def _expression_attribute_values(cls, attributes):
|
|
73
|
+
return {
|
|
74
|
+
':{key}'.format(key=key): attr for key, attr in attributes.items()
|
|
75
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
from dataclasses import dataclass
|
|
2
|
+
from typing import Optional
|
|
3
|
+
|
|
4
|
+
from python_layer.python import boto3
|
|
5
|
+
|
|
6
|
+
def remove_none_values(data: dict) -> dict: # noqa: WPS110
|
|
7
|
+
return {key: value for key, value in data.items() if value is not None} # noqa: WPS110
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
@dataclass
|
|
11
|
+
class S3Bucket(object):
|
|
12
|
+
bucket_url: str
|
|
13
|
+
|
|
14
|
+
def __post_init__(self):
|
|
15
|
+
self._resource = boto3.resource('s3')
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def get(self, file_name: str):
|
|
19
|
+
return self._resource.Object(self.bucket_url, file_name).get()
|
|
20
|
+
|
|
21
|
+
def upload(self, file_name, file_content, content_type: Optional[str] = None):
|
|
22
|
+
optional_params = {'ContentType': content_type}
|
|
23
|
+
return self._resource.Object(self.bucket_url, file_name).put(
|
|
24
|
+
Body=file_content,
|
|
25
|
+
**remove_none_values(optional_params),
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
def delete(self, file_name):
|
|
29
|
+
return self._resource.Object(self.bucket_url, file_name).delete()
|
|
30
|
+
|
|
31
|
+
def get_url(self, file_name):
|
|
32
|
+
return 'https://{bucket_url}.s3.amazonaws.com/{file_name}'.format(
|
|
33
|
+
bucket_url=self.bucket_url,
|
|
34
|
+
file_name=file_name,
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
def read(self, file_name):
|
|
38
|
+
return self.get(file_name)['Body'].read()
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
documente_shared/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
documente_shared/domain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
documente_shared/domain/base_enum.py,sha256=DojAfn-zQdtjtImeHUpBzE6TBTm07XrbMOdW3h8RVd8,1449
|
|
4
|
+
documente_shared/domain/entities.py,sha256=0Flg2yWYdVM34hAwZmarn8CUKGZ9LchtC6Imeikbthk,3726
|
|
5
|
+
documente_shared/domain/enums.py,sha256=LF-gY3EyucQSmGBxXNy8z4Cb4Ry672muPtz5Xt7e9oo,227
|
|
6
|
+
documente_shared/domain/repositories.py,sha256=h_nArptP5Xh7Jrhden-Ii9rZQqzgLFHhuzj1p78LgmU,365
|
|
7
|
+
documente_shared/infrastructure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
documente_shared/infrastructure/dynamo_repositories.py,sha256=RrJ3T1GsH5NNbaTqBwZ4_h34nWnoQ9mhcd5VDRiiv48,521
|
|
9
|
+
documente_shared/infrastructure/dynamo_table.py,sha256=H4X_SlK3DzOAt4wPQ8u4wkURt00bsKr5mfeSQTTA1O8,2094
|
|
10
|
+
documente_shared/infrastructure/s3_bucket.py,sha256=nJe6OCHhycPcl21gwazC_xxqVQ6y1cRS4T3LH14Hfjk,1180
|
|
11
|
+
documente_shared-0.1.3.dist-info/METADATA,sha256=1sL4e7TIZ29d2o1EEKaOkMLGdWtNMnfKicSX09H5zh0,639
|
|
12
|
+
documente_shared-0.1.3.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
13
|
+
documente_shared-0.1.3.dist-info/RECORD,,
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
documente_shared/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
documente_shared/domain/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
documente_shared/domain/base_enum.py,sha256=DojAfn-zQdtjtImeHUpBzE6TBTm07XrbMOdW3h8RVd8,1449
|
|
4
|
-
documente_shared/domain/entities.py,sha256=A9fepr2Y5IkCxe8W18uhos4UlEJ8VGSTd8PSCcEY98M,3600
|
|
5
|
-
documente_shared/domain/enums.py,sha256=LF-gY3EyucQSmGBxXNy8z4Cb4Ry672muPtz5Xt7e9oo,227
|
|
6
|
-
documente_shared/domain/repositories.py,sha256=j9BtQOJiNiXJ6nVo7MnP1oBuoN02Ox9cyCrvPGlkD30,365
|
|
7
|
-
documente_shared/infrastructure/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
-
documente_shared/infrastructure/dynamo_repositories.py,sha256=-lyG9oaskt6LdgdETFMZTUPS0_3fooLJzauX1pNDaos,348
|
|
9
|
-
documente_shared-0.1.2.dist-info/METADATA,sha256=4QFYDMlB9U5b83e6R6law8lRf_Dy_lc3nrpriOrZFAs,639
|
|
10
|
-
documente_shared-0.1.2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
|
|
11
|
-
documente_shared-0.1.2.dist-info/RECORD,,
|
|
File without changes
|