-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgcd_utils.py
84 lines (72 loc) · 2.45 KB
/
gcd_utils.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
75
76
77
78
79
80
81
82
83
84
from google.cloud import datastore
from org import Org
from org_dataset import OrgDataset
client = datastore.Client()
def get_org_dataset():
"""Fetches organizational data from google cloud
datastore and creates an OrgDataset instance containing
the data fetched.
Returns:
An OrgDataset instance containg the data fetched.
"""
query = client.query(kind='organization')
results = list(query.fetch())
orgs = []
for result in results:
orgs.append(Org(result['orgId'], result['orgName'], result['orgPurpose']))
od = OrgDataset()
od.add_orgs(orgs)
return od
def get_account_liked_orgs(account_id):
"""Fetches the ids of the orgs that the user
is interested in.
Args:
account_id (str): The id of the user to
fetch interested orgs for.
Returns:
A python list of strings. Each entry is an
id of an organization the user is interested
in.
"""
query = client.query(kind='account')
query.add_filter('userId', '=', account_id)
results = list(query.fetch())
if len(results) != 1:
raise ValueError('More or less than 1 user returned.'
' Something went wrong.')
return results[0]['userInterestOrgsId']
def get_account_disliked_orgs(account_id):
"""Fetches the ids of the orgs that the user
is NOT interested in.
Args:
account_id (str): The id of the user to
fetch not interested orgs for.
Returns:
A python list of strings. Each entry is an
id of an organization the user is not interested
in.
"""
query = client.query(kind='account')
query.add_filter('userId', '=', account_id)
results = list(query.fetch())
if len(results) != 1:
raise ValueError('More or less than 1 user returned.'
' Something went wrong.')
return results[0]['userDislikeOrgsId']
def get_account_liked_tags(account_id):
"""Fetches the tags that the user
is interested in.
Args:
account_id (str): The id of the user to
fetch tags for.
Returns:
A python list of strings. Each entry is a
tag that the user is interested in
"""
query = client.query(kind='account')
query.add_filter('userId', '=', account_id)
results = list(query.fetch())
if len(results) != 1:
raise ValueError('More or less than 1 user returned.'
' Something went wrong.')
return results[0]['userInterestTags']