-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelper.py
74 lines (58 loc) · 2.07 KB
/
helper.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
from google.protobuf import wrappers_pb2 as wrapper
from google.protobuf.timestamp_pb2 import Timestamp
import base64
import random
import grpc
from db_model import Event
import hts.common.common_pb2 as common
from sqlalchemy.orm import class_mapper
def getInt32Value(value):
if value is None:
return None
temp = wrapper.Int32Value()
temp.value = value
return temp
def getTimeStamp(data):
if data is None:
return None
timestamp = Timestamp()
timestamp.FromDatetime(data)
return timestamp
def b64encode(data):
encodedBytes = base64.b64encode(data.encode("utf-8"))
return str(encodedBytes, "utf-8")
def getStringValue(value):
if value is None:
return None
temp = wrapper.StringValue()
temp.value = value
return temp
def getRandomNumber():
return round(random.random() * 100)
def throwError(details: str, statusCode: grpc.StatusCode, context):
context.set_code(statusCode)
context.set_details(details)
return proto_pb2.Response()
def getEventsByIds(events_id: [str], session):
events = []
query_events = session.query(Event).filter(Event.id.in_(events_id)).all()
if query_events is not None:
events = map(
lambda event: common.Event(
id=event.id,
organization_id=event.organization_id,
location_id=getInt32Value(event.location_id),
description=event.description,
name=event.name,
cover_image_url=getStringValue(event.cover_image_url),
cover_image_hash=getStringValue(event.cover_image_hash),
poster_image_url=getStringValue(event.poster_image_url),
poster_image_hash=getStringValue(event.poster_image_hash),
profile_image_url=getStringValue(event.profile_image_url),
profile_image_hash=getStringValue(event.profile_image_hash),
attendee_limit=event.attendee_limit,
contact=getStringValue(event.contact),
),
query_events,
)
return events