moodleNotifer
timely_update.py
Go to the documentation of this file.
1 
5 from .updateDB import updater
6 from .models import Student
7 import re
8 from .subjectdatabase import moodle
9 from .automation import send_message
10 
11 
14 def update_database_daily():
15  all_students = Student.objects.all()
16  print("hello")
17  #print(all_students)
18  for student in all_students:
19  if(student.user_type == "updater"):
20  token = student.moodle_token
21  subs = student.update_courses
22  subs = subs.replace('[','')
23  subs = subs.replace(']','')
24  subs = subs.replace("'",'')
25  #print(subs)
26  subs = subs.split(",")
27  #print(subs)
28  updater(token,subs)
29 
30 
33 def send_update_to_students():
34  all_students = Student.objects.all()
35  for student in all_students:
36  subs = student.courses
37  subs = subs.replace('[','')
38  subs = subs.replace(']','')
39  subs = subs.replace("'",'')
40  subs = subs.split(",")
41  phone_no = student.phone_number
42  send_notification(phone_no,subs)
43 
44 
47 
48 
49 def send_notification(phone_no,subs):
50  print(subs,phone_no)
51  d = moodle()
52  for sub in subs:
53  ass_info = d.assignment_details(sub)
54  quiz_info = d.quiz_details(sub)
55  contents = d.course_contents(sub)
56  final_message = sub +"\n"+ ass_info + quiz_info + contents
57  send_message(final_message,phone_no)
58