-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb.py
50 lines (41 loc) · 1019 Bytes
/
db.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
from google.cloud import datastore
client = datastore.Client('handy-amplifier-200618')
kind = 'Booking'
task_key=client.key(kind)
def create_entity(data):
try:
#print(data)
task= datastore.Entity(key=task_key)
task['user_id']=data['id']
task['person']=data['person']
task['date']=data['date']
task['time']=data['time']
#print(data)
client.put(task)
#print(data)
return True
except:
return False
def get_entity(user_id):
try:
query = client.query(kind='Booking')
query.add_filter('user_id', '=', int(user_id))
details=list(query.fetch())
return details
except:
return False
def insert_user(user_id):
kind='user'
task_key=client.key(kind)
try:
query=client.query(kind='user')
query.add_filter('user_id','=',int(user_id))
details=list(query.fetch())
if len(details)==0:
task=datastore.Entity(key=task_key)
task['user_id']=int(user_id)
client.put(task)
else:
return 'Exist'
except:
return False