Example #1
0
 def updateUserLevel(self, project, userID, level):
     con = getConnection()
     checkProjectLoginLevel(con, project)
     lang = projectLang(con, project)
     cursor = con.cursor()
     # check that level is a valid value
     if int(level) is not 1 and int(level) is not 2:
         con.close()
         return 'no'
     # check that user does exist
     query = """
     SELECT count(*) FROM Client WHERE project = %s AND id = %s"""
     cursor.execute(query, (cherrypy.session.get(str(project)+'_projectCode'), userID))
     n = int(cursor.fetchone()[0])
     if n == 1:
         # update user level
         query = """
         UPDATE Client SET level = %s WHERE project = %s AND id = %s"""
         cursor.execute(query, (level, cherrypy.session.get(str(project)+'_projectCode'), userID))
         con.commit()
         # send him a mail to let him know his new status
         query = """
         SELECT Client.mail, Client.login, Project.webname, Project.name
         FROM Client
         INNER JOIN Project
         ON Client.project = Project.id
         WHERE Client.project = %s AND Client.id = %s"""
         cursor.execute(query, (cherrypy.session.get(str(project)+'_projectCode'), userID))
         row = cursor.fetchone()
         mail = row[0]
         userName = row[1]
         projectWebName = row[2]
         projectName = row[3]
         emailTemplate = Template(filename='templates/'+lang+'/mails/modification.mail', output_encoding='utf-8', default_filters=['decode.utf8'], input_encoding='utf-8')
         email = emailTemplate.render(
             to = mail,
             userName = userName,
             projectName = projectName,
             projectWebName = projectWebName,
             level = level
         )
         sendMail(mail, email)
         con.close()
         return 'ok'
     else:
         con.close()
         return 'no'        
Example #2
0
 def doLostPassword(self, projectWebName, login):
     con = getConnection()
     checkProject(con, projectWebName)
     lang = projectLang(con, projectWebName)
     cursor = con.cursor()
     login = login.strip()
     query = """
     SELECT id, mail FROM Client
     WHERE project = %s AND login = %s AND isDeleted = False"""
     cursor.execute(query, (cherrypy.session.get(str(projectWebName)+'_projectCode'), login))
     rows = cursor.fetchall()
     n = 0
     for row in rows:
         n = n + 1
         userID = int(row[0])
         mail = row[1]
     if  n == 0:
         return 'not found'
     else:
         # update the password
         newPassword = randomPwd()
         # encrypting the password
         m = md5.new()
         m.update(newPassword)
         m.update(projectWebName)
         m.update(login)
         query = """
         UPDATE Client
         SET password = %s
         WHERE id = %s AND project = %s"""
         cursor.execute(query, (m.hexdigest(), userID, cherrypy.session.get(str(projectWebName)+'_projectCode')) )
         con.commit()
         # sending email with new password
         query = """
         SELECT name FROM Project WHERE id = %s"""
         cursor.execute(query, (cherrypy.session.get(str(projectWebName)+'_projectCode'), ))
         projectName = cursor.fetchone()[0]
         emailTemplate = Template(filename='templates/'+lang+'/mails/lost_password.mail', output_encoding='utf-8', default_filters=['decode.utf8'], input_encoding='utf-8')
         email = emailTemplate.render(
             to = mail,
             userName = login,
             projectName = projectName,
             projectWebName = projectWebName,
             newPwd = newPassword
         )
         sendMail(mail, email)
     return 'ok'
Example #3
0
 def sendInvitations(self, project, to, msg) :
     """ sendInvitations page
     
     This is not a real page. It sends all invitations sent using the form found on the manageUsers page but has not a page on its own.
     The page displayed at the end is the manageUsers one, with a message to confirm that mails were sent.
     """
     
     con = getConnection()
     
     checkProjectLoginLevel(con, project)
     
     cursor = con.cursor()
     
     lang = projectLang(con, project)
     
     # getting author name
     query = """
     SELECT login
     FROM Client
     WHERE id = %s AND project = %s"""
     cursor.execute(query, (cherrypy.session.get(str(project)+'_idUser'), cherrypy.session.get(str(project)+'_projectCode') ) )
     rows = cursor.fetchall()
     author = 'unknown user'
     for row in rows :
         author = row[0]
     
     # processing "to" field (ie mail addresses)
     mails = to.split(';')
     for mail in mails :
         mail = mail.strip()
         emailTemplate = Template(filename='templates/'+lang+'/mails/invitation.mail', output_encoding='utf-8', default_filters=['decode.utf8'], input_encoding='utf-8')
         email = emailTemplate.render(
             to = mail,
             msg = msg,
             author = author,
             projectName = cherrypy.session.get(str(project)+'_projectName'),
             projectWebName = project
         )
         sendMail(mail, email)
     
     con.close()
     return 'ok'
Example #4
0
 def deleteUser(self, project, userID):
     con = getConnection()
     checkProjectLoginLevel(con, project)
     lang = projectLang(con, project)
     cursor = con.cursor()
     # check that user does exist
     query = """
     SELECT count(*) FROM Client WHERE project = %s AND id = %s"""
     cursor.execute(query, (cherrypy.session.get(str(project)+'_projectCode'), userID))
     n = int(cursor.fetchone()[0])
     if n == 1:
         # check that user is not the project's owner
         query = """
         SELECT owner FROM Project WHERE id = %s"""
         cursor.execute(query, (cherrypy.session.get(str(project)+'_projectCode'), ))
         row = cursor.fetchone()
         ownerID = row[0]
         if int(ownerID) != int(userID) :
             # send revocation or rejection email
             query = """
             SELECT Client.mail, Client.login, Project.webname, Project.name, Client.allowed
             FROM Client
             INNER JOIN Project
             ON Client.project = Project.id
             WHERE Client.project = %s AND Client.id = %s"""
             cursor.execute(query, (cherrypy.session.get(str(project)+'_projectCode'), userID))
             row = cursor.fetchone()
             mail = row[0]
             userName = row[1]
             projectWebName = row[2]
             projectName = row[3]
             isAllowed = row[4]
             if isAllowed:
                 mailType = 'revocation'
             else:
                 mailType = 'rejection'
             emailTemplate = Template(filename='templates/'+lang+'/mails/'+mailType+'.mail', output_encoding='utf-8', default_filters=['decode.utf8'], input_encoding='utf-8')
             email = emailTemplate.render(
                 to = mail,
                 userName = userName,
                 projectName = projectName,
                 projectWebName = projectWebName,
             )
             sendMail(mail, email)
             # delete user
             # if the user was already in the project, we don't really delete it
             # we just set isDeleted to True so that he can't log in anymore
             if isAllowed:
                 query = """
                 UPDATE Client
                 SET isDeleted = True
                 WHERE project = %s AND id = %s"""
             else:
                 query = """
                 DELETE FROM Client WHERE project = %s AND id = %s"""    
             cursor.execute(query, (cherrypy.session.get(str(project)+'_projectCode'), userID))
             con.commit()
             con.close()
             return 'ok'
         else:
             con.close()
             return 'owner'
     else:
         con.close()
         return 'no'
Example #5
0
 def doRegister(self, projectWebName, login, pwd1, pwd2, email):
     con = getConnection()
     checkProject(con, projectWebName)
     lang = projectLang(con, projectWebName)
     # clean data
     login = login.strip()
     pwd1 = pwd1.strip()
     pwd2 = pwd2.strip()
     email = email.strip()
     # check data
     errors = {  'equalPwd': True,
         'emptyPwd': (pwd1 == '' or pwd2 == ''),
         'emptyLogin': login=='',
         'emptyEMail': email=='',
         'loginTaken': False,
         'ok': False}
     # pwd1 and pwd2 are equal
     if pwd1 != pwd2 :
             errors['equalPwd'] = False
     # login is already taken
     query = """
     SELECT count(*) FROM Client
     WHERE project = %s AND login = %s"""
     cursor = con.cursor()
     cursor.execute(query, (cherrypy.session.get(str(projectWebName)+'_projectCode'), login))
     if int(cursor.fetchone()[0]) > 0:
             errors['loginTaken'] = True
     #   return errors
     if errors['emptyPwd'] or errors['emptyLogin'] or errors['emptyEMail'] or not errors['equalPwd'] or errors['loginTaken']:
             return demjson.encode(errors)
     # no error were found, just go on with the normal procedure
     query = """
     INSERT INTO Client(login, password, project, level, allowed, mail)
     VALUES (%s, %s, %s, 1, False, %s)"""
     m = md5.new()
     m.update(pwd1)
     m.update(projectWebName)
     m.update(login)
     cursor.execute(query, (login, m.hexdigest(), cherrypy.session.get(str(projectWebName)+'_projectCode'), email))
     con.commit()
     # send emails
     # to admins
     # get projectName
     query = """
     SELECT name
     FROM Project
     WHERE Project.id = %s"""
     cursor.execute(query, (cherrypy.session.get(str(projectWebName)+'_projectCode'), ))
     projectName = cursor.fetchone()[0]
     # send mails to all admins            
     query = """
     SELECT login, mail
     FROM Client
     WHERE project = %s AND level = 2"""
     cursor.execute(query, (cherrypy.session.get(str(projectWebName)+'_projectCode'), ))
     rows = cursor.fetchall()
     for row in rows :
         emailTemplate = Template(filename='templates/'+lang+'/mails/new_user.mail', output_encoding='utf-8', default_filters=['decode.utf8'], input_encoding='utf-8')
         emailContent = emailTemplate.render(
             to = row[1],
             userName = row[0],
             projectName = projectName,
             projectWebName = projectWebName)
         sendMail(row[1], emailContent)
         # to new user
         emailTemplate = Template(filename='templates/'+lang+'/mails/registration.mail', output_encoding='utf-8', default_filters=['decode.utf8'], input_encoding='utf-8')
         emailContent = emailTemplate.render(
             to = email,
             userName = login,
             projectName = projectName,
             projectWebName = projectWebName,
             password = pwd1)
     sendMail(email, emailContent)
     errors['ok'] = True
     return demjson.encode(errors)              
Example #6
0
 def createProject(self, projectName, projectWebName, login, pwd1, pwd2, email, lang):
     langs = ['en', 'fr']
     if lang not in langs:
         lang = 'en'
     # clean data
     projectName = projectName.strip()
     projectWebName = projectWebName.strip().lower()
     login = login.strip()
     pwd1 = pwd1.strip()
     pwd2 = pwd2.strip()
     email = email.strip()
     # check data
     errors = {  'validChars': True,
                 'equalPwd': True,
                 'validProjectWebName': True,
                 'emptyPwd': (pwd1 == '' or pwd2 == ''),
                 'emptyLogin': login=='',
                 'emptyProjectWebName': projectWebName=='',
                 'emptyProjectName': projectName == '',
                 'emptyEMail': email=='',
                 'ok': False}
     # the webname does not contains special chars
     validChars = "0123456789abcdefghijklmnopqrstuvwxyz"
     for c in projectWebName :
         if c not in validChars :
             errors['validChars'] = False
     # pwd1 and pwd2 are equal
     if pwd1 != pwd2 :
         errors['equalPwd'] = False
     # checking that a project with the same webname does not already exists
     con = getConnection()
     cursor = con.cursor()
     query = """
     SELECT count(*)
     FROM Project
     WHERE webname = %s"""
     cursor.execute(query, (projectWebName, ))
     row = cursor.fetchone()
     if row[0] >= 1 :
         errors['validProjectWebName'] = False
     # if there are errors, just send them back to the page
     error = errors['emptyPwd'] or errors['emptyLogin'] or errors['emptyProjectWebName'] or errors['emptyProjectName'] or errors['emptyEMail']
     error = error or not errors['validChars'] or not errors['equalPwd'] or not errors['validProjectWebName']
     if error:
         return demjson.encode(errors)
     # no error were found, just go on with the normal procedure
     # create project
     query = """
     INSERT INTO Project(name, webname, lang)
     VALUES (%s, %s, %s)"""
     cursor.execute(query, (projectName, projectWebName, lang))
     con.commit()
     checkProject(con, projectWebName)
     # add superuser for the project
     query = """
     INSERT INTO Client(login, password, project, level, allowed, mail)
     VALUES (%s, %s, %s, 2, True, %s);
     SELECT lastval();"""
     m = md5.new()
     m.update(pwd1)
     m.update(projectWebName)
     m.update(login)
     cursor.execute(query, (login, m.hexdigest(), cherrypy.session.get(str(projectWebName)+'_projectCode'), email))
     adminID = int(cursor.fetchone()[0])
     # updating project owner :
     query = """
     UPDATE Project
     SET owner = %s
     WHERE webname = %s"""
     cursor.execute(query, (adminID, projectWebName))
     con.commit()
     con.close()
     # send email
     emailTemplate = Template(filename='templates/'+lang+'/mails/new_project.mail', output_encoding='utf-8', default_filters=['decode.utf8'], input_encoding='utf-8')
     emailContent = emailTemplate.render(
         to = email,
         userName = login,
         projectName = projectName,
         projectWebName = projectWebName,
         password = pwd1
     )
     sendMail(email, emailContent)
     errors['ok'] = True
     return demjson.encode(errors)
from datetime import datetime, time
from scraping import get_webpage, extract_info
from visualizations import makeARDPieChart, makeDailyGraph
from mailing import createMail, sendMail

link = "https://www.covid19india.org/"
indiapc = "ind.jpg"
statepc = "sta.jpg"
statsfile = "daily_total.txt"
dailygraph = "growth.jpg"  #add any jpg file named growth.jpg to folder when running for first time
state = " "  #add name of your state
receiver_list = [" "]  #add email addresses of receivers

html_page = get_webpage(link)
data = extract_info(html_page, state)

makeARDPieChart(data["India"][1:], indiapc)
makeARDPieChart(data[state][1:], statepc)

if datetime.now().time().replace(minute=0, second=0, microsecond=0) == time(
        12):  # graph is plotted daily using data at 1200 hours
    makeDailyGraph(data["India"][0], statsfile, dailygraph)

msg = createMail(data["India"][0], data[state][0], indiapc, statepc,
                 dailygraph, state)
sendMail(msg, receiver_list)