def Generator(filereports): COLUMN_NAMES=['AppName','TCID','STATUS','EXEDATE','PASSED'] temp=pd.DataFrame(columns=COLUMN_NAMES) temp1=pd.DataFrame(columns=COLUMN_NAMES) count=0 for i in filereports: data1=pd.read_csv(i) passc=data1.STATUS=="Pass" if(count==0): tempf=data1[passc] temp['AppName']=tempf['AppName'] temp['TCID']=tempf['TCID'] temp['STATUS']=tempf['STATUS'] temp['EXEDATE']=tempf['EXEDATE'] temp['PASSED']=2.0 count=1 else: temp1['AppName']=data1[passc]['AppName'] temp1['TCID']=data1[passc]['TCID'] temp1['STATUS']=data1[passc]['STATUS'] temp1['EXEDATE']=data1[passc]['EXEDATE'] temp1['PASSED']=data1[passc][data1.columns[-1]] temp=pd.concat([temp,temp1]) temp=temp.dropna() temp.to_csv("pass_data.csv",index=False) zi.zip() mail.sender() su.suggester("pass_data.csv")
def load(self): self.cleartmp() self.Fname = tkFileDialog.askopenfilename(filetypes=[('Raspberry Pi Game','*.rpg;*.zip')]) if self.Fname <> '': z= Zipper.zipper() z.openfile(os.path.dirname(__file__) + "/Project", self.Fname) self.opengame()
def __init__(self, inputFilePath): self._parser = etree.XMLParser(encoding='utf-8', remove_blank_text=True) self.zipper = customZipper.Zipper() self.blueprint = z.ZipFile(inputFilePath) self.prefix = "{http://schemas.openxmlformats.org/wordprocessingml/2006/main}" self.paragraphs = [] self.questions = [] self.blank = etree.fromstring( """<w:p xmlns:w="http://schemas.openxmlformats.org/wordprocessingml/2006/main"><w:pPr><w:pStyle w:val="Normal"/><w:ind w:left="0" w:right="0" w:hanging="0"/><w:rPr><w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/><w:sz w:val="20"/><w:lang w:val="tr-TR"/></w:rPr></w:pPr><w:r><w:rPr><w:sz w:val="20"/><w:lang w:val="tr-TR"/></w:rPr></w:r></w:p>""" ) fileNameList = self.blueprint.namelist() # Traverse archived docx file and add all files # except document.xml to zipper for fName in fileNameList: with self.blueprint.open(fName) as f: if fName == 'word/document.xml': self.docXMLRoot = etree.fromstring(f.read()) else: self.zipper.addFile(fName, f.read()) self.body = self.docXMLRoot.find(self.prefix + "body") for paragraph in self.docXMLRoot.iter(self.prefix + "p"): clone = copy.deepcopy(paragraph) self.paragraphs.append(clone) # clear document for paragraph in self.docXMLRoot.iter(self.prefix + "p"): self.body.remove(paragraph) # get questions for i in range(len(self.paragraphs)): paragraphText = self.getParagraphText(self.paragraphs[i]) if ("@" in paragraphText) and not ("@&" in paragraphText): pars = [self.paragraphs[i]] j = 1 while not ("$" in self.getParagraphText( self.paragraphs[i + j])): pars.append(self.paragraphs[i + j]) j += 1 if "$" in self.getParagraphText(self.paragraphs[i + j]): pars.append(self.paragraphs[i + j]) q = Question.Question(pars) self.questions.append(q) i = i + j
def parse(infile, ConfigParam=defaultdict): date_regex = ConfigParam['ftp_date'] file_start_regex = ConfigParam['ftp_file_start'] work_dir = ConfigParam['workdir'] t1_input_file = None if (re.match(date_regex, infile)) or (re.match('current', infile, re.IGNORECASE)): try: ftp = FTP(ConfigParam['ftp_host']) except: print 'Oops! FTP_HOST parameter has not been set correctly in the config file.' sys.exit() ftp.login() if infile == 'current': try: remote_dir = ConfigParam['ftp_curr_path'] remote_dir = remote_dir.rstrip('/') except: print 'Oops! FTP Download directory path not set correctly in config file.' sys.exit() else: [month, year] = infile.split('_') month = month.capitalize() try: remote_dir = ConfigParam['ftp_old_path'] remote_dir = remote_dir.rstrip('/') except: print 'Oops! FTP Download directory path not set correctly in config file.' sys.exit() [download_status, down_filename] = FtpDownload.download(infile, ftp, remote_dir, work_dir) if download_status == 1: t1_input_file = Zipper.unzipper(down_filename, ConfigParam) elif download_status == -1: if re.search('.gz', down_filename): t1_input_file = Zipper.unzipper(down_filename, ConfigParam) else: t1_input_file = down_filename else: input_basename = basename(infile) if os.path.exists(work_dir + '/' + input_basename): t1_input_file = input_basename elif os.path.exists(infile): shutil.move(infile, work_dir) t1_input_file = basename(infile) else: print infile + ' is not available.' sys.exit(1) if re.search('\.gz$', t1_input_file): extracted_file = t1_input_file.replace('.gz', '') if os.path.exists(work_dir + '/' + extracted_file): t1_input_file = '' t1_input_file = extracted_file elif os.path.exists(extracted_file): shutil.move(extracted_file, work_dir) t1_input_file = '' t1_input_file = extracted_file else: extracted_file = Zipper.unzipper(t1_input_file, ConfigParam) t1_input_file = '' t1_input_file = extracted_file #Add the Format Checker Module return t1_input_file
def main(): try: test = False compress = True recipientsDirectory = 'C:' + os.sep + 'PythonScripts' + os.sep + 'SelinaReports' + os.sep if not test: recipientsFile = open(recipientsDirectory + 'recipients.txt', 'r') else: recipientsFile = open(recipientsDirectory + 'recipients_old.txt', 'r') recips = readRecipientsIntoMemory(recipientsFile) if not test: dateFolder = str(datetime.date.today()) else: dateFolder = str(datetime.date.today()+ datetime.timedelta(days = -1)) dateFolder = dateFolder[:4] + dateFolder[5:7] + dateFolder[8:10] named_date = datetime.date.today().strftime("%b %d.%y") subject = 'First Coverage Daily Update-'+ named_date #create the name of the output directory EOD_ReportsFolder = 'C:\\EOD-Reports\\' todaysFolder = '%s%s' %(EOD_ReportsFolder, dateFolder) #find all the reports generated on a given day Reports = os.listdir(todaysFolder) #add the path to the beginning of every report name todaysReports = [] for report in Reports: todaysReports.append(todaysFolder + os.sep + report) #give a name to the zip file where the reports will be archived #and zip all the files. if compress: if not os.path.isdir(todaysFolder + '_sent'): os.mkdir(todaysFolder + '_sent') if not os.path.isdir(todaysFolder + os.sep + 'zips'): os.mkdir(todaysFolder + os.sep + 'zips') if not os.path.isdir(todaysFolder + '_sent' + os.sep + 'zips'): os.mkdir(todaysFolder + '_sent' + os.sep + 'zips') zipFolder = todaysFolder + os.sep + 'zips' print '!!COMPRESS LOOP!!' for report in todaysReports: print 'report', report #f.write('report' + report) f = report[:-4] + '.zip' if not os.path.isdir(report): print 'report is: ' + report + ' file is: ' + f Zipper.main([report],f, True) #[:-4] + "_" + str(x) + ".zip") #todaysZipFolder = zipFolder print 'move %s to %s' %(f, zipFolder) shutil.move(f, zipFolder) msg = '''Please find a copy of today's First Coverage report attached. It includes all open and closed ideas entered into First Coverage for you since inception along with total return, vs sector, stop, target and comments. Regards, First Coverage www.firstcoverage.com 888-473-7836''' sterlingFiles = [] sendDirectory = todaysFolder + os.sep + 'zips' #if test: # zipFolder = todaysFolder + os.sep + 'zips' #if compress or test: # sendDirectory = zipFolder print 'looping over', os.listdir(sendDirectory) for report in os.listdir(sendDirectory): #print 'Todays Folder: ', sendDirectory + os.sep + report #Find the client name in the published reports. If a report isn't published for the client, #the client will not receive anything. for name in clientList: if 'SterlingJohnston' in report: sterlingFiles.append(todaysFolder + os.sep + report) elif name in report: sendReportToRecipient(name,[sendDirectory + os.sep + report], subject, msg, test, recips) #if test: print 'current report is: ', report print 'moving : ' + sendDirectory + os.sep + report + ' to : ' + todaysFolder + '_sent' + os.sep + 'zips' shutil.move(sendDirectory + os.sep + report,\ todaysFolder + '_sent' + os.sep + 'zips') #if test : print 'moving : ' + todaysFolder + os.sep + report[:-4] + '.xls' + ' to : ' + todaysFolder + '_sent' shutil.move(todaysFolder + os.sep + report[:-4] + '.xls', todaysFolder + '_sent') if len(sterlingFiles) == 2: #!!untested - sending the sterling formatted reports is discouraged going forward. sendReportToRecipient('Sterling Johnston',sterlingFiles, subject, msg, test, recips) for f in sterlingFiles: shutil.move(sendDirectory + os.sep + f, todaysFolder + '_sent' + os.sep + 'zips') shutil.move(todaysFolder + os.sep + f[:-4] + '.xls', todaysFolder + '_sent') everythingLeft = os.listdir(todaysFolder) leftovers = [] for thing in everythingLeft: if not os.path.isdir(todaysFolder + os.sep + thing): leftovers.append(thing) if leftovers !=[]: Email.notify(['email'],\ 'Problem with Selina/EOD/Daily Update XLS report',\ 'The following reports could not be sent for some reason. Most likely, the name of the file\nand the name in recipients.txt do not match up.'\ + '\n\n' + '\n'.join(leftovers) ) else: shutil.rmtree(todaysFolder) except: traceback.print_exc(file=open(r'c:\temp\EOD-XL_log.txt', 'a')) raise exit(1)
def save(self): if self.Fname == "": self.Fname = tkFileDialog.asksaveasfilename(filetypes=[('Raspberry Pi Game','*.rpg')]) if self.Fname <> ".rpg": z= Zipper.zipper() z.savefile(os.path.dirname(__file__) + "/Project", self.Fname+".rpg")
def parse(infile, ConfigParam=defaultdict): date_regex = ConfigParam['ftp_date'] file_start_regex = ConfigParam['ftp_file_start'] work_dir = ConfigParam['workdir'] t1_input_file = None if (re.match(date_regex,infile)) or (re.match('current', infile, re.IGNORECASE)): try: ftp = FTP(ConfigParam['ftp_host']) except: print 'Oops! FTP_HOST parameter has not been set correctly in the config file.' sys.exit() ftp.login() if infile == 'current': try: remote_dir = ConfigParam['ftp_curr_path'] remote_dir = remote_dir.rstrip('/') except: print 'Oops! FTP Download directory path not set correctly in config file.' sys.exit() else: [month,year] = infile.split('_') month = month.capitalize() try: remote_dir = ConfigParam['ftp_old_path'] remote_dir = remote_dir.rstrip('/') except: print 'Oops! FTP Download directory path not set correctly in config file.' sys.exit() [download_status,down_filename] = FtpDownload.download(infile,ftp, remote_dir, work_dir) if download_status == 1: t1_input_file = Zipper.unzipper(down_filename, ConfigParam) elif download_status == -1: if re.search('.gz', down_filename): t1_input_file = Zipper.unzipper(down_filename, ConfigParam) else: t1_input_file = down_filename else: input_basename = basename(infile) if os.path.exists(work_dir + '/' + input_basename): t1_input_file = input_basename elif os.path.exists(infile): shutil.move(infile,work_dir) t1_input_file = basename(infile) else: print infile + ' is not available.' sys.exit(1) if re.search('\.gz$',t1_input_file): extracted_file = t1_input_file.replace('.gz','') if os.path.exists(work_dir + '/' + extracted_file): t1_input_file = '' t1_input_file = extracted_file elif os.path.exists(extracted_file): shutil.move(extracted_file,work_dir) t1_input_file = '' t1_input_file = extracted_file else: extracted_file = Zipper.unzipper(t1_input_file, ConfigParam) t1_input_file = '' t1_input_file = extracted_file #Add the Format Checker Module return t1_input_file
def main(): try: test = False compress = True recipientsDirectory = 'C:' + os.sep + 'PythonScripts' + os.sep + 'SelinaReports' + os.sep if not test: recipientsFile = open(recipientsDirectory + 'recipients.txt', 'r') else: recipientsFile = open(recipientsDirectory + 'recipients_old.txt', 'r') recips = readRecipientsIntoMemory(recipientsFile) if not test: dateFolder = str(datetime.date.today()) else: dateFolder = str(datetime.date.today())#+ datetime.timedelta(days = -1)) dateFolder = dateFolder[:4] + dateFolder[5:7] + dateFolder[8:10] named_date = datetime.date.today().strftime("%b %d.%y") subject = 'First Coverage Daily Update-'+ named_date #create the name of the output directory EOD_ReportsFolder = 'C:\\EOD-Reports\\' todaysFolder = '%s%s' %(EOD_ReportsFolder, dateFolder) #find all the reports generated on a given day Reports = os.listdir(todaysFolder) #add the path to the beginning of every report name todaysReports = [] for report in Reports: todaysReports.append(todaysFolder + os.sep + report) #give a name to the zip file where the reports will be archived #and zip all the files. if compress: zipFolder = todaysFolder + os.sep + 'zips' os.mkdir(todaysFolder + os.sep + 'zips') print todaysReports for report in todaysReports: print 'report', report #f.write('report' + report) f = report[:-4] + '.zip' Zipper.main([report],f, True) #[:-4] + "_" + str(x) + ".zip") #todaysZipFolder = zipFolder print 'move %s to %s' %(f, zipFolder) shutil.move(f, zipFolder) #email the reports to everyone in the list sendTo if not test: sendTo = ['email'] else: sendTo = ['email'] msg = '''Please find a copy of today's First Coverage report attached. It includes all open and closed ideas entered into First Coverage for you since inception along with total return, vs sector, stop, target and comments. Regards, First Coverage www.firstcoverage.com 888-473-7836''' sterlingFiles = [] sendDirectory = todaysFolder if test: zipFolder = todaysFolder + os.sep + 'zips' if compress or test: sendDirectory = zipFolder for report in os.listdir(sendDirectory): print 'Todays Folder: ', sendDirectory + os.sep + report #Find the client name in the published reports. If a report isn't published for the client, #the client will not receive anything. ##redacted time.sleep(5) if len(sterlingFiles) == 2: sendReportToRecipient('Sterling Johnston',sterlingFiles, subject, msg, test, recips) except: traceback.print_exc(file=open(r'c:\temp\EOD-XL_log.txt', 'a')) raise exit(1)