def add_faculty_to_db(self, url, attributes):
     name = attributes[0]
     code = attributes[1]
     faculty = EclassFaculties(
         url = url,
         name = name,
         code = code,
     )
     try:
         faculty.save()
         logger_syslog.info(u'Επιτυχής προσθήκη', extra = log_extra_data(url))
         author = Authors(content_object = faculty)
         author.save()
         logger_syslog.info(u'Επιτυχής προσθήκη', extra = log_extra_data(url))
     except IntegrityError:
         '''
         Check if the entry is already in the DB but marked inactive
         '''
         faculty = EclassFaculties.objects.filter(is_active=False).get(url=url)
         faculty.is_active = True
         faculty.save()
         logger_syslog.info(u'Αλλαγή κατάστασης σε active', extra = log_extra_data(url))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(url))
         logger_mail.exception(error)
     return
 def add_teacher_to_db(self, url, attributes, departments_from_db_q):
     name = attributes[0]
     email = attributes[1]
     try:
         department = departments_from_db_q.get(name = attributes[2])
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(url))
         logger_mail.exception(error)
         return
     teacher = Teachers(
         url = url,
         name = name,
         email = email,
         department = department,
     )
     try:
         teacher.save()
         logger_syslog.info(u'Επιτυχής προσθήκη', extra = log_extra_data(url))
         author = Authors(content_object = teacher)
         author.save()
         logger_syslog.info(u'Επιτυχής προσθήκη', extra = log_extra_data(url))
     except IntegrityError:
         '''
         Check if the entry is already in the DB but marked inactive
         '''
         teacher = Teachers.objects.filter(is_active=False).get(url=url)
         teacher.is_active = True
         teacher.save()
         logger_syslog.info(u'Αλλαγή κατάστασης σε active', extra = log_extra_data(url))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(url))
         logger_mail.exception(error)
     return
예제 #3
0
 def add_teacher_to_db(self, url, attributes, departments_from_db_q):
     name = attributes[0]
     email = attributes[1]
     try:
         department = departments_from_db_q.get(name = attributes[2])
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(url))
         logger_mail.exception(error)
         return
     teacher = Teachers(
         url = url,
         name = name,
         email = email,
         department = department,
     )
     try:
         teacher.save()
         logger_syslog.info(u'Επιτυχής προσθήκη', extra = log_extra_data(url))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(url))
         logger_mail.exception(error)
         return
     author = Authors(content_object = teacher)
     try:
         author.save()
         logger_syslog.info(u'Επιτυχής προσθήκη', extra = log_extra_data(url))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(url))
         logger_mail.exception(error)
     return
 def add_website_to_db(self, url, attributes):
     '''
     Add the website to the DB
     '''
     name = attributes[0]
     rss = attributes[1]
     email = attributes[2]
     website = Websites(
         url = url,
         name = name,
         rss = rss,
         email = email,
     )
     try:
         website.save()
         logger_syslog.info(u'Επιτυχής προσθήκη', extra = log_extra_data(url))
         author = Authors(content_object = website)
         author.save()
         logger_syslog.info(u'Επιτυχής προσθήκη', extra = log_extra_data(url))
     except IntegrityError:
         '''
         Check if the entry is already in the DB but marked inactive
         '''
         website = Websites.objects.filter(is_active=False).get(url=url)
         website.is_active = True
         website.save()
         logger_syslog.info(u'Αλλαγή κατάστασης σε active', extra = log_extra_data(url))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(url))
         logger_mail.exception(error)
     return
예제 #5
0
 def add_website_to_db(self, rss, attributes):
     '''
     Add the website to the DB
     '''
     name = attributes[0]
     url = attributes[1]
     email = attributes[2]
     website = Websites(
         rss = rss,
         name = name,
         url = url,
         email = email,
     )
     try:
         website.save()
         logger_syslog.info(u'Επιτυχής προσθήκη', extra = log_extra_data(rss))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(rss))
         logger_mail.exception(error)
         return
     author = Authors(content_object = website)
     try:
         author.save()
         logger_syslog.info(u'Επιτυχής προσθήκη', extra = log_extra_data(rss))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(rss))
         logger_mail.exception(error)
     return
 def add_lesson_to_db(self, url, attributes, faculties_from_db_q):
     name = attributes[0]
     teacher = attributes[1]
     faculty = faculties_from_db_q.get(name = attributes[2])
     ltype = attributes[3]
     lesson = EclassLessons(
         url = url,
         name = name,
         teacher = teacher,
         faculty = faculty,
         ltype = ltype,
     )
     try:
         lesson.save()
         logger_syslog.info(u'Επιτυχής προσθήκη', extra = log_extra_data(url))
         author = Authors(content_object = lesson)
         author.save()
         logger_syslog.info(u'Επιτυχής προσθήκη', extra = log_extra_data(url))
     except IntegrityError:
         '''
         Check if the entry is already in the DB but marked inactive
         '''
         lesson = EclassLessons.objects.filter(is_active=False).get(url=url)
         lesson.is_active = True
         lesson.save()
         logger_syslog.info(u'Αλλαγή κατάστασης σε active', extra = log_extra_data(url))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(url))
         logger_mail.exception(error)
     return
 def add_lesson_to_db(self, url, attributes, faculties_from_db_q):
     name = attributes[0]
     teacher = attributes[1]
     faculty = faculties_from_db_q.get(name = attributes[2])
     ltype = attributes[3]
     lesson = EclassLessons(
         url = url,
         name = name,
         teacher = teacher,
         faculty = faculty,
         ltype = ltype,
     )
     try:
         lesson.save()
         logger_syslog.info(u'Επιτυχής προσθήκη', extra = log_extra_data(url))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(url))
         logger_mail.exception(error)
         return
     author = Authors(content_object = lesson)
     try:
         author.save()
         logger_syslog.info(u'Επιτυχής προσθήκη', extra = log_extra_data(url))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(url))
         logger_mail.exception(error)
     return
예제 #8
0
 def add_student_to_db(self, credentials, request):
     '''
     Adds a new user in the Database, along with the collected credentials from
     dionysos.teilar.gr
     '''
     user = User(
         username = credentials['username'],
         first_name = credentials['first_name'],
         last_name = credentials['last_name'],
         email = credentials['username'] + '@emptymail.com'
     )
     user.is_staff = False
     user.is_superuser = False
     try:
         user.save()
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(credentials['username'], request))
         logger_mail.exception(error)
         raise CronosError(u'Σφάλμα αποθήκευσης βασικών στοιχείων χρήστη')
     '''
     Additional information are added in the userprofile table
     '''
     try:
         user_profile = UserProfile(
             user = user,
             dionysos_username = credentials['username'],
             dionysos_password = encrypt_password(credentials['password']),
             registration_number = credentials['registration_number'],
             semester = credentials['semester'],
             school = Departments.objects.get(name = credentials['school']),
             introduction_year = credentials['introduction_year'],
             declaration = credentials['declaration'],
             #grades = credentials['grades'],
         )
         user_profile.save()
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(credentials['username'], request))
         logger_mail.exception(error)
         raise CronosError(u'Σφάλμα αποθήκευσης πρόσθετων στοιχείων χρήστη')
     '''
     Everything went fine
     Notify admins about the new registration
     '''
     title = u'New user No.%s: %s' % (user.id, user.username)
     message = u'Name: %s %s\nDepartment: %s\nSemester: %s' % (
         user.first_name, user.last_name, user_profile.school, user_profile.semester
     )
     logger_syslog.info(title, extra = log_extra_data(user.username, request))
     try:
         send_mail(settings.EMAIL_SUBJECT_PREFIX + title, message,
             settings.SERVER_EMAIL, [settings.ADMINS[0][1]])
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(user.username, request))
         logger_mail.exception(error)
     '''
     Return the new user object
     '''
     return user
예제 #9
0
 def add_student_to_db(self, request, student):
     '''
     Adds a new user in the Database, along with the collected credentials from
     dionysos.teilar.gr
     '''
     user = User(
         username = student.dionysos_username,
         first_name = unicode(student.dionysos_first_name),
         last_name = unicode(student.dionysos_last_name),
         email = unicode(student.dionysos_username) + u'@emptymail.com'
     )
     user.is_staff = False
     user.is_superuser = False
     try:
         user.save()
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(request))
         logger_mail.exception(error)
         raise CronosError(u'Σφάλμα αποθήκευσης βασικών στοιχείων χρήστη')
     '''
     Additional information are added in the userprofile table
     '''
     try:
         user_profile = UserProfile(
             user = user,
             dionysos_username = student.dionysos_username,
             dionysos_password = encrypt_password(student.dionysos_password),
             registration_number = unicode(student.dionysos_registration_number),
             semester = unicode(student.dionysos_semester),
             school = student.dionysos_school,
             introduction_year = unicode(student.dionysos_introduction_year),
             declaration = student.dionysos_declaration,
             grades = student.dionysos_grades,
         )
         user_profile.save()
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(request))
         logger_mail.exception(error)
         raise CronosError(u'Σφάλμα αποθήκευσης πρόσθετων στοιχείων χρήστη')
     '''
     Everything went fine
     Log the new user and notify admins about the new registration
     '''
     title = u'New user No.%s: %s' % (user.id, user.username)
     message = u'Name: %s %s\nDepartment: %s\nSemester: %s' % (
         user.first_name, user.last_name, user_profile.school, user_profile.semester
     )
     logger_syslog.info(title, extra = log_extra_data(request))
     try:
         send_mail(settings.EMAIL_SUBJECT_PREFIX + title, message,
             settings.SERVER_EMAIL, get_admins_mails())
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(request))
         logger_mail.exception(error)
     '''
     Return the new user object
     '''
     return user
 def get_teilar(self):
     '''
     Grab announcements from the following websites and
     put them in separate custom RSS files:
     - http://teilar.gr/news.php?cid=1
     - http://teilar.gr/news.php?cid=2
     - http://teilar.gr/news.php?cid=5
     - http://teilar.gr/news.php?cid=6
     - http://teilar.gr/tmimatanews.php
     '''
     rss_filenames = {
         1: 'general.rss',
         2: 'teilar_ann.rss',
         5: 'council.rss',
         6: 'committee.rss',
         'tmimatanews.php': 'departments.rss',
     }
     for cid, rss_name in rss_filenames.iteritems():
         custom_rss = self.initialize_rss_file()
         if type(cid) == int:
             output = teilar_anon_login('http://www.teilar.gr/news.php?cid=%s' % cid)
         else:
             output = teilar_anon_login('http://www.teilar.gr/%s' % cid)
         soup = BeautifulSoup(output)
         try:
             announcements_all = soup.find_all('table')[17].find_all('a', 'BlackText11')[:10]
         except Exception as error:
             logger_syslog.error(error, extra = log_extra_data())
             logger_mail.exception(error)
         for item in announcements_all:
             '''
             Get inside the announcement to get the rest of the info
             '''
             ann_url = 'news_detail.php?nid=' + item['href'].split('nid=')[1]
             if type(cid) != int:
                 ann_url = 'tmimata/' + ann_url
             output = teilar_anon_login('http://www.teilar.gr/%s' % ann_url)
             soup = BeautifulSoup(output)
             try:
                 if type(cid) != int:
                     creator = soup.find('span', 'OraTextBold').contents[0].split(' >')[0].replace(u'Τεχν.', u'Τεχνολογίας')
                 else:
                     creator = None
                 temp_td_oratext = soup.find_all('td', 'OraText')
                 pubdate = temp_td_oratext[0].contents[0].split('/')
                 pubdate = date(int(pubdate[2]), int(pubdate[1]), int(pubdate[0]))
                 title = temp_td_oratext[1].contents[0]
                 description = unicode(soup.find('td', 'BlackText11'))
                 enclosure = self.get_enclosure(soup)
             except Exception as error:
                 logger_syslog.error(error, extra = log_extra_data('http://teilar.gr' + ann_url))
                 logger_mail.exception(error)
             self.add_rss_item(custom_rss, title, 'http://teilar.gr/' + ann_url, pubdate, description, creator, enclosure)
         self.write_rss_file(custom_rss, rss_name)
     return
 def deprecate_website_in_db(self, url, websites_from_db_q):
     '''
     Mark websites as inactive
     '''
     website = websites_from_db_q.get(url = url)
     website.is_active = False
     try:
         website.save()
         logger_syslog.info(u'Αλλαγή κατάστασης σε inactive', extra = log_extra_data(url))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(url))
         logger_mail.exception(error)
     return
예제 #12
0
 def deprecate_website_in_db(self, rss, websites_from_db_q):
     '''
     Mark websites as deprecated
     '''
     website = websites_from_db_q.get(rss = rss)
     website.deprecated = True
     try:
         website.save()
         logger_syslog.info(u'Αλλαγή κατάστασης σε deprecated', extra = log_extra_data(rss))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(rss))
         logger_mail.exception(error)
     return
 def deprecate_faculty_in_db(self, url, faculties_from_db_q):
     '''
     Mark faculties as inactive
     '''
     faculty = faculties_from_db_q.get(url = url)
     faculty.is_active = False
     try:
         faculty.save()
         logger_syslog.info(u'Αλλαγή κατάστασης σε inactive', extra = log_extra_data(url))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(url))
         logger_mail.exception(error)
     return
 def deprecate_lesson_in_db(self, url, lessons_from_db_q):
     '''
     Mark lessons as inactive
     '''
     lesson = lessons_from_db_q.get(url = url)
     lesson.is_active = False
     try:
         lesson.save()
         logger_syslog.info(u'Αλλαγή κατάστασης σε inactive', extra = log_extra_data(url))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(url))
         logger_mail.exception(error)
     return
예제 #15
0
 def deprecate_teacher_in_db(self, url, teachers_from_db_q):
     '''
     Mark teachers as deprecated
     '''
     teacher = teachers_from_db_q.get(url = url)
     teacher.deprecated = True
     try:
         teacher.save()
         logger_syslog.info(u'Αλλαγή κατάστασης σε deprecated', extra = log_extra_data(url))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(url))
         logger_mail.exception(error)
     return
예제 #16
0
 def deprecate_department_in_db(self, url, departments_from_db_q):
     '''
     Mark departments as deprecated
     '''
     department = departments_from_db_q.get(url = url)
     department.deprecated = True
     try:
         department.save()
         logger_syslog.info(u'Αλλαγή κατάστασης σε deprecated', extra = log_extra_data(url))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(url))
         logger_mail.exception(error)
     return
 def deprecate_department_in_db(self, url, departments_from_db_q):
     """
     Mark departments as inactive
     """
     department = departments_from_db_q.get(url=url)
     department.is_active = False
     try:
         department.save()
         logger_syslog.info(u"Αλλαγή κατάστασης σε inactive", extra=log_extra_data(url))
     except Exception as error:
         logger_syslog.error(error, extra=log_extra_data(url))
         logger_mail.exception(error)
     return
예제 #18
0
 def eclass_auth_login(self, request = None):
     '''
     Authentication to e-class.teilar.gr
     '''
     eclass_session = requests.session()
     login_data = {
         'uname': self.eclass_username,
         'pass': self.eclass_password,
         'submit': 'E%95%CE%AF%CF%83%CE%BF%CE%B4%CE%BF%CF%82',
     }
     '''
     Send a GET request to get the cookies. If it fails then e-class.teilar.gr is down
     '''
     try:
         response = eclass_session.get('http://openclass.teilar.gr')
     except Exception as warning:
         if request:
             logger_syslog.warning(warning, extra = log_extra_data(request))
         raise CronosError(u'Παρουσιάστηκε σφάλμα σύνδεσης με το openclass.teilar.gr')
     '''
     Proceed to actual authentication
     '''
     response = eclass_session.post('http://openclass.teilar.gr', login_data)
     '''
     Check if the login is successful
     '''
     try:
         soup = BeautifulSoup(response.text).find_all('p', 'alert1')[0]
         if soup.contents[0] == u'Λάθος στοιχεία.':
             raise LoginError
     except (AttributeError, IndexError):
         pass
     self.eclass_output = response.text
예제 #19
0
 def get_dionysos_introduction_year(self, request = None):
     '''
     Retrieves student's introduction year from dionysos.teilar.gr
     '''
     if not self.dionysos_index_output:
         self.dionysos_auth_login(request, personal_data = True)
     try:
         soup = BeautifulSoup(self.dionysos_index_output).find_all('table')[15]
         '''
         Introduction is in the following form:
         2004 - 2005 X or 2004 - 2005 E
         first_year - second_year season
         We need it in the form 2004X (YearSeason):
         if season is 'X', then year is first_year (2004X)
         if season is 'E', then year is second_year (2005E)
         '''
         season = unicode(soup.find_all('span','tablecell')[1].contents[0])[0]
         if season == u'Ε':
             year = unicode(soup.find_all('span','tablecell')[0].contents[0].split('-')[1])
         else:
             year = unicode(soup.find_all('span','tablecell')[0].contents[0].split('-')[0])
         self.dionysos_introduction_year =  year + season
     except Exception as error:
         if request:
             logger_syslog.error(error, extra = log_extra_data(request))
             logger_mail.exception(error)
         raise CronosError(u'Αδυναμία ανάκτησης Έτους Εισαγωγής')
 def update_posts(self):
     '''
     Update the DB with new posts of all the websites listed in authors.keys()
     '''
     authors = self.get_authors()
     for rss_url, url in authors.iteritems():
         '''
         Parse the RSS feed
         '''
         try:
             rss = feedparser.parse(rss_url)
         except Exception as error:
             '''
             Something went wrong, skip it and go to the next one
             '''
             logger_syslog.error(error, extra = log_extra_data(rss_url))
             logger_mail.exception(error)
             continue
         '''
         Grab the latest max 10 posts
         '''
         if len(rss.entries) > 10:
             entries = rss.entries[:10][::-1]
         else:
             entries = rss.entries[::-1]
         for entry in entries:
             '''
             Get the data of each entry and add them in DB
             '''
             post = self.get_post(entry, rss_url, url)
             self.add_post_to_db(post, url)
예제 #21
0
 def get_or_create_user(self, username = None, password = None, request = None):
     '''
     Retrieves the user from the Django DB. If the user is not
     found in the DB, then it tries to retrieve him from
     dionysos.teilar.gr
     '''
     try:
         '''
         Try to pull the user from the Django DB
         '''
         user = User.objects.get(username = username)
         '''
         If the user is found in the DB, try to login with those
         credentials in dionysos.teilar.gr
         '''
         try:
             if not dionysos_auth_login(username, password):
                 return
         except CronosError:
             '''
             Connection issue with dionysos.teilar.gr. Try to authenticate
             with the password stored in the DB instead
             '''
             if password != decrypt_password(user.get_profile().dionysos_password):
                 return
     except User.DoesNotExist:
         '''
         If the user is not in the DB, try to log in with his
         dionysos.teilar.gr account
         '''
         try:
             output = dionysos_auth_login(username, password, request = request)
         except CronosError:
             raise
         if output:
             '''
             The credentials worked, try to create a user based on those credentials
             '''
             credentials = {'username': username, 'password': password}
             try:
                 front_page = BeautifulSoup(output).find_all('table')[14].find_all('tr')
             except Exception as error:
                 logger_syslog.error(error, extra = log_extra_data(username, request))
                 logger_mail.exception(error)
                 raise CronosError(u'Αδυναμία ανάκτησης στοιχείων χρήστη')
             try:
                 credentials['last_name'] = get_dionysos_last_name(front_page, username, request)
                 credentials['first_name'] = get_dionysos_first_name(front_page, username, request)
                 credentials['registration_number'] = get_dionysos_registration_number(front_page, username, request)
                 credentials['semester'] = get_dionysos_semester(front_page, username, request)
                 credentials['school'] = get_dionysos_school(front_page, username, request)
                 credentials['introduction_year'] = get_dionysos_introduction_year(output, username, request)
                 credentials['declaration'] = get_dionysos_declaration(username, password, request)
                 #credentials['grades'] = get_dionysos_grades(username, password, request)
                 user = self.add_student_to_db(credentials, request)
             except CronosError:
                 raise
         else:
             return
     return user
예제 #22
0
 def get_eclass_lessons(self, request = None):
     '''
     Get eclass lessons
     '''
     if not self.eclass_output:
         self.eclass_auth_login(request)
     try:
         eclass_output = BeautifulSoup(self.eclass_output).find('table', 'tbl_lesson').find_all('td', align='left')
         if request:
             from cronos.teilar.models import EclassLessons
             '''
             We are using the function from the webapp, all actions will be
             performed to the DB directly.
             Get all lessons and the ones that the student already follows
             '''
             eclass_lessons_all_q = EclassLessons.objects.all()
             eclass_lessons_following = eclass_lessons_all_q.filter(url__in = request.user.get_profile().following_eclass_lessons.all())
             '''
             Get the new list of following lessons
             '''
             new_eclass_lessons = []
             for eclass_lesson in eclass_output:
                 new_eclass_lessons.append(eclass_lesson.find('a')['href'])
             '''
             Convert the python list to QuerySet
             '''
             new_eclass_lessons = eclass_lessons_all_q.filter(url__in = new_eclass_lessons)
             '''
             Find the new additions and put them in the DB
             '''
             eclass_lessons_for_addition = new_eclass_lessons.exclude(url__in = eclass_lessons_following)
             for eclass_lesson in eclass_lessons_for_addition:
                 request.user.get_profile().following_eclass_lessons.add(eclass_lesson)
             '''
             Find the removed ones and remove them from the DB
             '''
             eclass_lessons_for_removal = eclass_lessons_following.exclude(url__in = new_eclass_lessons)
             for eclass_lesson in eclass_lessons_for_removal:
                 request.user.get_profile().following_eclass_lessons.remove(eclass_lesson)
         else:
             '''
             We are using the function from CLI, the output will be a python
             dictionary with the eclass lessons
             '''
             eclass_lessons = {}
             for item in all_lessons:
                 lcode = item.span.contents[0][1:-1]
                 url = u'http://openclass.teilar.gr/courses/%s/' % lcode
                 name = item.a.contents[0]
                 # TODO: teacher, faculty, ltype
                 eclass_lessons[lcode] = [url, name]
             self.eclass_lessons = eclass_lessons
     except Exception as error:
         if request:
             logger_syslog.error(error, extra = log_extra_data(request))
             logger_mail.exception(error)
         raise CronosError(u'Αδυναμία ανάκτησης μαθημάτων e-class')
예제 #23
0
def get_dionysos_first_name(front_page=None, username=None, request=None):
    """
    Retrieves student's first name from dionysos.teilar.gr
    """
    try:
        return unicode(front_page[6].find_all("td")[1].contents[0])
    except Exception as error:
        logger_syslog.error(error, extra=log_extra_data(username, request))
        logger_mail.exception(error)
        raise CronosError(u"Αδυναμία ανάκτησης Ονόματος")
예제 #24
0
def get_dionysos_registration_number(front_page=None, username=None, request=None):
    """
    Retrieves student's registration number from dionysos.teilar.gr
    """
    try:
        return unicode(front_page[7].find_all("td")[1].contents[0])
    except Exception as error:
        logger_syslog.error(error, extra=log_extra_data(username, request))
        logger_mail.exception(error)
        raise CronosError(u"Αδυναμία ανάκτησης Αριθμού Μητρώου")
예제 #25
0
def get_dionysos_semester(front_page=None, username=None, request=None):
    """
    Retrieves student's semester from dionysos.teilar.gr
    """
    try:
        return unicode(front_page[9].findAll("td")[1].contents[0])
    except Exception as error:
        logger_syslog.error(error, extra=log_extra_data(username, request))
        logger_mail.exception(error)
        raise CronosError(u"Αδυναμία ανάκτησης Εξαμήνου")
 def add_department_to_db(self, url, name):
     department = Departments(url=url, name=name)
     try:
         department.save()
         logger_syslog.info(u"Επιτυχής προσθήκη", extra=log_extra_data(url))
         author = Authors(content_object=department)
         author.save()
         logger_syslog.info(u"Επιτυχής προσθήκη", extra=log_extra_data(url))
     except IntegrityError:
         """
         Check if the entry is already in the DB but marked inactive
         """
         department = Departments.objects.filter(is_active=False).get(url=url)
         department.is_active = True
         department.save()
         logger_syslog.info(u"Αλλαγή κατάστασης σε active", extra=log_extra_data(url))
     except Exception as error:
         logger_syslog.error(error, extra=log_extra_data(url))
         logger_mail.exception(error)
     return
예제 #27
0
 def add_department_to_db(self, url, name):
     department = Departments(
         url = url,
         name = name,
     )
     try:
         department.save()
         logger_syslog.info(u'Επιτυχής προσθήκη', extra = log_extra_data(url))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(url))
         logger_mail.exception(error)
         return
     author = Authors(content_object = department)
     try:
         author.save()
         logger_syslog.info(u'Επιτυχής προσθήκη', extra = log_extra_data(url))
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data(url))
         logger_mail.exception(error)
     return
 def get_authors(self):
     '''
     Retrieves the authors from the DB tables:
     Departments, Teachers, EclassLessons, Websites
     It returns a dictionary with the following structure:
     authors = {'rss': 'url'}
     (depending on what of those two is unique in each table)
     '''
     authors = {}
     '''
     Add the teilar.gr various websites. It also includes some
     recreated RSS feeds, since the ones that teilar provides are not good
     '''
     try:
         websites = Websites.objects.filter(is_active = True)
         for website in websites:
             authors[website.rss] = website.url
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data())
         logger_mail.exception(error)
         raise CronosError(u'Παρουσιάστηκε σφάλμα σύνδεσης με τη βάση δεδομένων')
     '''
     Add the eclass lessons in the list of RSS authors
     '''
     try:
         eclass_lessons = EclassLessons.objects.filter(is_active = True)
         for lesson in eclass_lessons:
             authors[u'http://openclass.teilar.gr/modules/announcements/rss.php?c=%s' % lesson.url.split('/')[4]] = lesson.url
     except Exception as error:
         logger_syslog.error(error, extra = log_extra_data())
         logger_mail.exception(error)
         raise CronosError(u'Παρουσιάστηκε σφάλμα σύνδεσης με τη βάση δεδομένων')
     '''
     Add the Departments from the DB in the list of RSS sites
     EDIT: They don't offer good RSS, I am recreating it, it is included in Websites table
     '''
     #departments = Departments.objects.filter(is_active = True)
     #for department in departments:
     #    authors['http://teilar.gr/tmimata/rss_tmima_news_xml.php?tid=%i' % department.url.split('=')[1] = department.url
     return authors
예제 #29
0
    def get_dionysos_declaration(self, request = None):
        '''
        Retrieves student's latest declaration
        '''

        '''
        Declaration includes the following information:
        Lesson code eg 121E
        Title eg ΠΡΟΓΡΑΜΜΑΤΙΣΜΟΣ Ι (Θ)
        Semester eg Β
        DM eg 2
        Hours eg 4
        Type eg Y
        Grade
        '''
        if not self.dionysos_declaration_output:
            self.dionysos_auth_login(declaration = True)
        soup = BeautifulSoup(self.dionysos_declaration_output)
        '''
        Temp variables are named based on the HTML tags they contain. Those
        variables give faster results, since we don't have to regenerate the
        same data in each time the for loop is executed.
        '''
        try:
            temp = soup.find_all('table')[13].find('table')
            temp_td_bottom = temp.find_all('td', 'bottomborderLight')
            declaration = temp_td_bottom
            i = 0
            while i < len(declaration):
                '''
                Some of the above results are inside single HTML tags (<td>2</td>)
                and some are in double ones (<td><span>4</span</td>). We work around
                this with a try/except block
                '''
                try:
                    '''
                    Add information that is inside double HTML tags
                    '''
                    declaration[i] = unicode(declaration[i].contents[0].contents[0]).strip()
                except AttributeError:
                    '''
                    Add information that is inside single HTML tags
                    '''
                    declaration[i] = unicode(declaration[i].contents[0]).strip()
                i += 1
            declaration = ':'.join(declaration).replace('&amp;', '&')
            self.dionysos_declaration = declaration
        except Exception as error:
            if request:
                logger_syslog.error(error, extra = log_extra_data(request))
                logger_mail.exception(error)
            raise CronosError(u'Αδυναμία ανάκτησης Δήλωσης')
예제 #30
0
 def get_dionysos_semester(self, request = None):
     '''
     Retrieves student's semester from dionysos.teilar.gr
     '''
     if not self.dionysos_index_minimal_output:
         self.dionysos_auth_login(request, personal_data = True)
     try:
         self.dionysos_semester = self.dionysos_index_minimal_output[9].find_all('td')[1].contents[0]
     except Exception as error:
         if request:
             logger_syslog.error(error, extra = log_extra_data(request))
             logger_mail.exception(error)
         raise CronosError(u'Αδυναμία ανάκτησης Εξαμήνου')