-
Notifications
You must be signed in to change notification settings - Fork 0
/
gql_data_extraction.py
170 lines (147 loc) · 5.11 KB
/
gql_data_extraction.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
from gisconnector.apicall import gis_get_gql_paginated
from gisconnector.lc_list import lc_list
from pkgutil import get_data
from json2csv import json2csv
import datetime as dt
import json
import csv
import sys
def convert_programme(prog):
if prog == 'GV':
return [1]
elif prog == 'GT':
return [2]
elif prog == 'GE':
return [5]
elif prog == 'ALL':
return [1,2,5]
else:
print("Programme entered is invalid.")
exit()
if __name__ == "__main__":
get_applications = "get_applications.gql"
get_people = "get_people.gql"
get_email = "get_email.gql"
csv_file_path = '/home/thales/Documents/workspace/aiesec-projects/Data-Extraction-GraphQL/Extractions GraphQL/'
csv_file_name = ''
# Setting up LC list
lcs = lc_list()
print('\n'+"INITIALIZING SCRIPT..."+'\n')
# INPUTS:
prog = str(input("Programme (GV, GT, GE, ALL): "))
programmes_decoded = convert_programme(prog)
status = str(input("status (applications, accepted, approved, realized, finished, completed): "))
if status == 'applications':
date_type = 'created_at'
elif status == 'accepted':
date_type = 'date_matched'
elif status == 'approved':
date_type = 'date_approved'
elif status == 'realized':
date_type = 'date_realized'
elif status == 'finished':
date_type = 'experience_end_date'
elif status == 'completed':
date_type = 'experience_end_date'
else:
raise NameError('error: app_type argument is invalid.')
start_date = input("Start Date (yyyy-mm-dd): ")
end_date = input("End Date (yyyy-mm-dd): ")
entity_name = input("LC name: ")
for lc in lcs:
if lc['name'] == entity_name:
entity_id = lc['id']
type_req = str(input("Type (ICX, OGX): "))
print('\n'+"### DATA ###"+'\n')
csv_file_name += "Data " + entity_name + " " + type_req + " " + prog + " " + status + " " + start_date + " " + end_date + '.csv'
csv_file_path += csv_file_name
start_date = start_date + "T00:00:00.000Z"
end_date = end_date + "T23:59:59.999Z"
# ICX Data
if type_req == "ICX":
if prog == 'GV':
print("Getting IGV Applications...")
elif prog == 'GT':
print("Getting IGT Applications...")
elif prog == 'GE':
print("Getting IGE Applications...")
elif prog == 'ALL':
print("Getting ICX Applications...")
applications = gis_get_gql_paginated(get_data("gql", get_applications).decode("utf-8"), silent=False, variables={
"applied_at": True,
"status": True,
"experience_start_date": True,
"tags": False,
"opportunity": True,
"applicant_name": True,
"organization": True,
"host_mc": False,
"host_lc": False,
"home_mc": False,
"home_lc": False,
"phone_number": False,
"date_realized": False,
"page": 1,
"perPage": 200,
"filters": {
"opportunity_committee": entity_id,
"programmes": programmes_decoded,
date_type: {
"from": start_date,
"to": end_date
},
#"status": "completed",
"nps_grade_value": {
"min": None,
"max": None
}
},
"sort": ""
})
raw_json_data = json.loads(json.dumps(applications))['data']
#print(raw_json_data)
json2csv(raw_json_data, csv_file_path)
# OGX Data
elif type_req == "OGX":
if prog == 'GV':
print("Getting OGV Applications...")
elif prog == 'GT':
print("Getting OGT Applications...")
elif prog == 'GE':
print("Getting OGE Applications...")
elif prog == 'ALL':
print("Getting OGX Applications...")
people = gis_get_gql_paginated(get_data("gql", get_people).decode("utf-8"), silent=False, variables={
"first_name": True,
"last_name": True,
"name": False,
"managers": False,
"date_of_birth": False,
"status": True,
"phone": True,
"home_lc": True,
"referral": False,
"home_mc": True,
"contacted_at": False,
"contacted_by": False,
"signed_up_at": False,
"lc_alignment": False,
"selected_programmes": True,
"phone_number": True,
"page": 1,
"perPage": 30,
"filters": {
"home_committee": entity_id,
"selected_programmes": programmes_decoded,
date_type: {
"from": start_date,
"to": end_date
}
},
"q": None,
"sort": ""
})
raw_json_data = json.loads(json.dumps(people))['data']
json2csv(raw_json_data, csv_file_path)
else:
print("Error: Type of application was not found.")