moodleNotifer
updateDB.py
Go to the documentation of this file.
1 
5 from .subjectdatabase import *
6 from .login import *
7 from .letsloginourself import worker
8 '''
9 Assumption here is that when this function is called it has token and number of subjects as the valid arguemnts
10 '''
11 
12 
15 def new_user_firstContact(moodle_token):
16  #print("hello")
17  request_helper = worker(moodle_token)
18  course_id, course_name = get_list_of_courses(request_helper)
19  courses = []
20  for key in course_id.keys():
21  courses.append(key)
22  d=moodle()
23  courses_present = d.get_all_courses()
24  updater = False
25  #d.delete_sub()
26  updater_subs = []
27  update_sub_name = {}
28  update_sub_id = {}
29  #print("sample","vample")
30  #print("tatti",courses_present, "hello guys 000 here")
31  for key in course_id.keys():
32  if key not in courses_present:
33  print(key)
34  updater = True
35  updater_subs.append(key)
36  update_sub_name[key] = course_name[key]
37  update_sub_id[key] = course_id[key]
38 
39  # print(courses)
40  # print(updater)
41  # print(updater_subs)
42  #d.printdb()
43  print(courses,update_sub_name,update_sub_id)
44  token_with_new_subject(moodle_token,update_sub_name,update_sub_id)
45  #d.printdb()
46 
47  return courses,updater,updater_subs
48 
49 
50 
53 def updater(moodle_token, subjects):
54  d=moodle()
55  request_helper = worker(moodle_token)
56  for sub in subjects:
57  key_to_pass = sub
58  mcourse_id = d.get_courseid(sub)
59  assignments = get_assignments_info(request_helper,mcourse_id,False)
60  d.update(key_to_pass,2,assignments)
61  quizzes = get_quizzes_info(request_helper,mcourse_id,False)
62  d.update(key_to_pass,3,quizzes)
63  ann_forum = get_discussion_forum_id(request_helper,mcourse_id)
64  d.update(key_to_pass,4,ann_forum)
65  discs = get_discussion_forum_discussions(request_helper, ann_forum['id'])
66  d.update(key_to_pass,5,discs)
67  cc = get_course_contents(request_helper,mcourse_id)
68  d.update(sub,6,cc[-1])
69  #print(cc[-1])
70  #d.printdb()
71 
72 
73 
76 def token_with_new_subject(moodle_token, sub_name, sub_id):
77  #{771: "fml"}
78  # add sub to the subjects table
79  # call functions to update the contents of the subject information table
80  d=moodle()
81  request_helper = worker(moodle_token)
82  for key in sub_id.keys():
83  key_to_pass = int(key)
84  d.insert(key_to_pass,sub_name[key])
85  d.update(key_to_pass,1,sub_id[key])
86  assignments = get_assignments_info(request_helper,sub_id[key],False)
87  d.update(key_to_pass,2,assignments)
88  quizzes = get_quizzes_info(request_helper,sub_id[key],False)
89  d.update(key_to_pass,3,quizzes)
90  ann_forum = get_discussion_forum_id(request_helper,sub_id[key])
91  d.update(key_to_pass,4,ann_forum)
92  discs = get_discussion_forum_discussions(request_helper,ann_forum['id'])
93  d.update(key_to_pass,5,discs)
94  cc = get_course_contents(request_helper,sub_id[key])
95  d.update(key_to_pass,6,cc[-1])
96  #d.printdb()
97