Exemplo n.º 1
0
    def post(self):
        parser = reqparse.RequestParser()
        parser.add_argument('user_id', type=int, required=True)
        parser.add_argument('sender_id', type=int, required=True)
        parser.add_argument('message', type=str, required=True)
        parser.add_argument('subject', type=str, required=True)
        request_params = parser.parse_args()

        data = util.mail(request_params['user_id'], request_params['sender_id'], request_params['message'], request_params['subject'])

        return data
Exemplo n.º 2
0
def vtu(name,email):	
	driver = webdriver.PhantomJS()
	#Presently the code is used to get revaluation results
	#Change the vitavireval to vitavi in the below statement for normal results
	driver.get("http://results.vtu.ac.in/vitavireval.php")
	sbox=driver.find_element_by_xpath('//input[contains(@type, "TEXT")]')
	sbox.send_keys(name)
	sbox.send_keys(Keys.RETURN)
	has=str((BeautifulSoup(driver.page_source)).find('td' ,{ 'width' : '513'}))
	ker=re.sub("\n","", ((((BeautifulSoup(driver.page_source)).find('td' ,{ 'width' : '513'})).text)))
	if(ker != "Results are not yet available for this university seat number  or it might not be a  valid university seat numberClick here to go back"):
	    return mail(email,has,"VTU revaluation results",time.strftime("%d/%m/%Y"),1)
	driver.quit()
Exemplo n.º 3
0
def uploadDir(config, devicename, localroot, label):
    log = logging.getLogger(config['devicename'])

    log.info("scanningFiles")
    totalbytes, totalcount = util.folderInfo(localroot)
    log.info("uploadBegin|{localroot}|{label}|{filecount}|{bytecount}".format(
        localroot=localroot,label=label,filecount=totalcount, bytecount=totalbytes))
    util.mail(config,
        config['templates']['uploadBegin']['body'].format(
            filecount=totalcount,
            megabytes=round(totalbytes/1024/1024,1)),
            subject=config['templates']['uploadBegin']['subject'])



    ftpconfig = config['ftp']
    log.debug("Connecting to " + ftpconfig['server'])
    try:
        host = connectHost(ftpconfig)
    except ftputil.error.FTPError:
        log.exception("Could not connect to FTP Server|"+traceback.format_exc())
        return
    superrootpath=ftpconfig['rootpath']
    host.makedirs(superrootpath)
    host.chdir(superrootpath)
    superrootpath = host.getcwd()
    begintime = datetime.datetime.now()
    rootdirname = begintime.strftime("%Y-%m-%d")
    host.makedirs(rootdirname + "-incomplete")
    host.chdir(rootdirname + "-incomplete")
    remoteroot = host.getcwd()
    host.synchronize_times()
    uploadedfiles = 0
    uploadedbytes = 0
    skippedfiles = 0
    statuslogcount=config['uploadlogcount']
    statusloginterval=config['maxlogdelay']
    statuslogstatus=-1
    lastlogdate=begintime
    failed_files=[]

    def logProgress():
        nonlocal uploadedfiles,totalcount,uploadedbytes,totalbytes
        log.info("uploadProgress|{uploadedfiles}/{totalcount}|{uploadedbytes}/{totalbytes}".format(**vars()))

    def chunkCallback(info):
        nonlocal uploadedbytes,statuslogcount,totalbytes,statuslogstatus,uploadedfiles,totalcount
        uploadedbytes += len(info)
        curstatus = uploadedbytes*statuslogcount//totalbytes
        if curstatus != statuslogstatus:
            statuslogstatus = curstatus
            logProgress()
    for root, dirs, files in os.walk(localroot):
        relroot = os.path.relpath(root, localroot)
        #log.debug("walking "+relroot)
        hostroot = os.path.normpath(os.path.join(remoteroot, util.sanitize(relroot)))
        try:
            host.chdir(hostroot)
        except (socket.error,ftputil.error.FTPError,OSError,IOError) as e:
            log.info("tmp|Connection died(a)|"+traceback.format_exc())
            time.sleep(CONNDIEWAIT)
            host.close()
            host = connectHost(ftpconfig)
            host.chdir(hostroot)

        if (datetime.datetime.now()-lastlogdate).total_seconds() > statusloginterval:
            lastlogdate=datetime.datetime.now()
            logProgress()

        for dirname in dirs:
            dirname=util.sanitize(dirname)
            try:
                host.makedirs(dirname)
            except ftputil.error.PermanentError:
                log.debug("Error(b)|"+traceback.format_exc())
                pass
            except (socket.error,ftputil.error.FTPError,OSError,IOError) as e:
                log.debug("Error(b)|"+traceback.format_exc())
                time.sleep(CONNDIEWAIT)
                host.close()
                host = connectHost(ftpconfig)
                host.chdir(hostroot)
                host.makedirs(dirname)

        for fname in files:
            if (datetime.datetime.now()-lastlogdate).total_seconds() > statusloginterval:
                lastlogdate=datetime.datetime.now()
                logProgress()
            localfname=os.path.join(root,fname)
            if not os.path.isfile(localfname): continue
            hostfname=os.path.join(hostroot,util.sanitize(fname))
            uploadedfiles += 1
            log.debug("uploading " + os.path.join(relroot, fname))
            try:
                uploaded = host.upload_if_newer(localfname,
                    util.sanitize(fname),
                    callback=chunkCallback)
                if not uploaded:
                    log.debug("tmp|skipped file "+localfname)
                    uploadedbytes+=os.path.getsize(localfname)
                    skippedfiles += 1
            except (socket.error,ftputil.error.FTPError,OSError,IOError) as e:
                log.info("tmp|(1)Failed uploading "+localfname+"|"+str(e))
                try:
                    time.sleep(CONNDIEWAIT)
                    host.close()
                    host = connectHost(ftpconfig)
                    host.chdir(hostroot)
                    host.upload(localfname,
                               util.sanitize(fname),
                               callback=chunkCallback)
                except (socket.error,ftputil.error.FTPError,OSError,IOError) as e:
                    log.info("tmp|(2)Failed uploading "+localfname+"|"+str(e))
                    failed_files.append((localfname,hostfname))

    again_failed_files = []
    if len(failed_files)>0: 
        log.info("failedFiles|"+"\n".join([local+"->"+remote for local,remote in failed_files]))
        while True:
            # retry uploading until no more files can be uploaded
            time.sleep(CONNDIEWAIT)
            host.close()
            host = connectHost(ftpconfig)
            for local,remote in failed_files:
                try:
                    host.upload(local,remote,callback=chunkCallback)
                except (socket.error,ftputil.error.FTPError,OSError,IOError) as e:
                    log.info("tmp|Again failed uploading "+localfname+"|"+traceback.format_exc())
                    again_failed_files.append((localfname,hostfname))
            if len(again_failed_files) == len(failed_files):
                break
            else:
                failed_files = again_failed_files
            

    if len(again_failed_files)>0: 
        log.warn("failedFiles|"+"\n".join([local+"->"+remote for local,remote in failed_files]))


    endtime = datetime.datetime.now()
    totaltime = str(datetime.timedelta(seconds=int((endtime-begintime).total_seconds())))
    host.chdir(superrootpath)
    host.rename(remoteroot, findDirname(host, rootdirname))
    host.close()
    if(uploadedfiles<totalcount):
        log.warn(str(totalcount-uploadedfiles)+" files could not be uploaded|")
        if util.getMountPoint(devicename) == None:
            log.error("Device disappeared before upload completed")
            # might happen because unplugged or not enough power
    log.info("uploadComplete|{uploadedfiles}|{uploadedbytes}|{totaltime}|{skippedfiles}".format(**vars()))
    util.mail(config,
        config['templates']['uploadComplete']['body'].format(filecount=uploadedfiles,megabytes=round(uploadedbytes/1024/1024,1),duration=totaltime),
        subject=config['templates']['uploadComplete']['subject'])
Exemplo n.º 4
0
    parser.add_argument('action', help='task to perform', choices=actions)
    parser.add_argument('-n', '--number', default=10, type=int, help='number of ranks to show')
    parser.add_argument('-g', '--group', help='group to focus on')
    parser.add_argument('-m', '--mail', nargs='*', help='email address to get output')
    parser.add_argument('-s', '--subject', help='optional email subject')
    parser.add_argument('-a', '--attach', action='store_true', help='also attach email body as a txt file to the email')
    parser.add_argument('-e', '--extension', default='txt', help='extension of template you want to use')

    args = parser.parse_args()

    try:
        result = actions.get(args.action)(validate_group(args.group))
    except:
        if not args.mail:
            raise
        else:
            if not args.group: args.group=''
            subject = args.action+' '+args.group if not args.subject else args.subject
            mail([args.mail[0]], subject, str(sys.exc_info()[0]), host=True)
            logging.error('CRASHED and email sent')
    else:
        if result:
            if not args.mail:
                print(result) # chcp 65001
            else:
                if not args.group: args.group=''
                subject = args.action+' '+args.group+' '+args.extension if not args.subject else args.subject
                mail(args.mail, subject, result, args.attach)
                logging.info('email sent')
        logging.info('Done')
Exemplo n.º 5
0
if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Tools for agent-stats admins')
    parser.add_argument('action', help='task to perform', choices=['snarf', 'check_for_applicants', 'weekly', 'monthly', 'update_group_names', 'summary', 'test'])
    parser.add_argument('-n', '--number', default=10, type=int, help='number of ranks to show')
    parser.add_argument('-g', '--group', help='group to focus on', choices=[name for row in exec_mysql('SELECT name FROM groups;') for name in row])
    parser.add_argument('-m', '--mail', nargs='*', help='email address to get output')
    parser.add_argument('-s', '--subject', help='optional email subject')

    args = parser.parse_args()

    actions = {'snarf': snarf,
               'summary': summary,
               'weekly': weekly_roundup,
               'monthly': monthly_roundup,
               'check_for_applicants': check_for_applicants,
               'update_group_names': update_group_names,
               'test': test}
    result = actions.get(args.action)(args.group)

    if result:
        result = result.strip()

        if not args.mail:
            print(result) # chcp 65001
        elif result:
            if not args.group: args.group=''
            subject = args.action+' '+args.group if not args.subject else args.subject
            mail(args.mail, subject, result)
            logging.info('email sent')
    logging.info('Done')
Exemplo n.º 6
0
                        ])
    parser.add_argument('-m',
                        '--mail',
                        nargs='*',
                        help='email address to get output')
    parser.add_argument('-s', '--subject', help='optional email subject')

    args = parser.parse_args()

    try:
        result = actions.get(args.action)(args.group)
    except:
        if not args.mail:
            raise
        else:
            if not args.group: args.group = ''
            subject = args.action + ' ' + args.group if not args.subject else args.subject
            mail([args.mail[0]], subject, str(sys.exc_info()[0]))
            logging.info('CRASHED and email sent')
    else:
        if result:
            result = result.strip()

            if not args.mail:
                print(result)  # chcp 65001
            elif result:
                if not args.group: args.group = ''
                subject = args.action + ' ' + args.group if not args.subject else args.subject
                mail(args.mail, subject, result)
                logging.info('email sent')
        logging.info('Done')