-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdynamodb_handler.py
52 lines (40 loc) · 1.04 KB
/
dynamodb_handler.py
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#
import json
import boto3
from boto3.dynamodb.conditions import Key, Attr
dynamodb = boto3.resource('dynamodb')
table = dynamodb.Table('wohnung_sucher_db')
def put_item(flat_info):
"""[Put a new item in DB]
Args:
flat_info ([dict]): [Full flat info]
Returns:
[dict]: [response from db]
"""
response = table.put_item(
Item = flat_info
)
return response
def scan_db(attribute, search_criteria):
"""[Scan database and get results based on attribute and search criteria]
Args:
attribute ([str]): [Attributes for search]
search_criteria ([str]): [Search criteria]
Returns:
[type]: [description]
"""
response = table.scan(
FilterExpression=Key(attribute).eq(search_criteria)
#attr = 'source', search_criteria = 'immoscout24'
)
return response['Items']
# def get_item(id,key):
# '''
# Get item from db. id = ''
# '''
# response = table.get_item(
# Key = {
# id : key
# }
# )
# return response