forked from product-rnd/announcement-automation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathannouncement.py
140 lines (113 loc) · 6.02 KB
/
announcement.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
# Import required dependencies to use Google's API
import pandas as pd
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError
# Get students name and email from Algoritma Score Academy and Active Students spreadsheet
def get_students(creds, ACTIVE_STUDENT_ID, SHEET_RANGE, SCORE_ACADEMY_ID, EMAIL_RANGE):
# Call Classroom API
service = build('sheets', 'v4', credentials=creds)
# Retrive values from sheet range in Active Students spreadsheet
sheet = service.spreadsheets().values().batchGet(spreadsheetId=ACTIVE_STUDENT_ID,
ranges=SHEET_RANGE).execute()
# Create a dataframe from the retrieved values
active_df = pd.DataFrame(sheet['valueRanges'][0]['values'], columns=['Name', 'Class', 'Email'])
active_df['Email'] = active_df['Email'].str.strip().str.lower()
# Retrive values from sheet range in Score Academy spreadsheet
sheet = service.spreadsheets().values().batchGet(spreadsheetId=SCORE_ACADEMY_ID,
ranges=EMAIL_RANGE).execute()
# Create a dataframe from the retrieved values
score_df = pd.DataFrame(sheet['valueRanges'][0]['values'], columns=['Email', 'Email Classroom'])
score_df['Email'] = score_df['Email'].str.strip().str.lower()
score_df['Email Classroom'] = score_df['Email Classroom'].str.strip().str.lower()
# Merge both Active Students and Score Academy dataframes based on the student's email
classroom_df = pd.merge(active_df, score_df, how='left', on='Email')
classroom_df = classroom_df[classroom_df['Email'].notna()]
# Give status based on the student's classroom email availability
classroom_df.loc[classroom_df['Email Classroom'].notna(), 'Status'] = '✅ Assigned'
classroom_df.loc[classroom_df['Email Classroom'].isna(), 'Status'] = '❌ Missing'
return classroom_df
# Create draft announcement with assigned students
def announce(creds, courses, course_name, classroom_df, session):
# Call Classroom API
service = build('classroom', 'v1', credentials=creds)
# Get Google Classroom id
for course in courses:
if course_name == course['name']:
course_id = course['id']
break
# Get students list
response = service.courses().students().list(courseId=course_id).execute()
students = response.get('students')
while response.get('nextPageToken'):
response = service.courses().students().list(courseId=course_id, pageToken = response['nextPageToken']).execute()
students.extend(response.get('students'))
student_id = []
# Get students id based on students' classroom email
for student in students:
if student['profile']['emailAddress'] in classroom_df['Email Classroom'].tolist():
student_id.append(student['userId'])
elif "@algorit.ma" in student['profile']['emailAddress']:
student_id.append(student['userId'])
elif (student['profile']['emailAddress'] == "algostudentday@gmail.com") & (session == 'Day Online'):
student_id.append(student['userId'])
elif (student['profile']['emailAddress'] == "algostudentnight0@gmail.com") & (session == 'Night Online'):
student_id.append(student['userId'])
elif (student['profile']['emailAddress'] == "algostudentnight1@gmail.com") & (session == 'Night Onsite'):
student_id.append(student['userId'])
# Create the announcement body and settings
body = {
'text': session,
'state': "DRAFT",
'assigneeMode': 'INDIVIDUAL_STUDENTS',
"individualStudentsOptions": {
"studentIds": student_id
}
}
# Create the announcement
response = service.courses().announcements().create(courseId=course_id, body=body).execute()
def course_list(specialization):
if specialization == 'Data Analytics':
return ['Python for Data Analysts (P4DA)',
'Exploratory Data Analysis (EDA)',
'Data Wrangling and Visualization (DWV)',
'Structured Query Language (SQL)',
'Capstone Project Data Analytics',
'Introduction to Machine Learning I (IML1)',
'Introduction to Machine Learning II (IML2)']
elif specialization == 'Data Visualization':
return ['Programming for Data Science (P4DS)',
'Practical Statistic (PS)',
'Data Visualization (DV)',
'Interactive Plotting (IP)',
'Capstone Project Data Visualization']
elif specialization == 'Machine Learning':
return ['Regression Model (RM)',
'Classification in Machine Learning I (C1)',
'Classification in Machine Learning II (C2)',
'Unsupervised Learning (UL)',
'Time Series & Forecasting (TSF)',
'Neural Network and Deep Learning (NN)',
'Capstone Project Machine Learning']
else:
return ['']
def learnr(topic):
if topic == 'Programming for Data Science (P4DS)':
return 'https://algoritmads.shinyapps.io/prep4ds/'
elif topic == 'Practical Statistic (PS)':
return 'https://algoritmads.shinyapps.io/preps/'
elif topic == 'Data Visualization (DV)':
return 'https://ahmadhusain.shinyapps.io/learnr-dv/'
elif topic == 'Interactive Plotting (IP)':
return 'https://vicnp.shinyapps.io/IP_LearnR/'
elif topic == 'Regression Model (RM)':
return 'https://inayatus.shinyapps.io/AlgLearnRM/'
elif topic == 'Classification in Machine Learning I (C1)':
return 'https://algoritma.shinyapps.io/LearnRC1/'
elif topic == 'Classification in Machine Learning II (C2)':
return 'https://11pgcm-amalia.shinyapps.io/LearnR-CIML2/'
elif topic == 'Unsupervised Learning (UL)':
return 'https://inayatus.shinyapps.io/AlgLearnRUL/'
elif topic == 'Time Series & Forecasting (TSF)':
return 'https://kevinwibowo.shinyapps.io/AlgLearnRTS/'
else:
return '_____________'