def main(): id = (input('Enter the ID: ')) #eval function to be added in py3 print("For checking acb status type acb" + '\n') print("For checking backlogs status type backlogs" + '\n') print("For sending student mail enter send mail" + '\n') print("For checking PS status, type PS " + '\n') print("For checking CGPA, type CGPA" + '\n') print( "For checking grade in a particular subject, type grade followed by concerned subject abbreviation and course code, for example : PHY F110" + '\n') #id="2018A1PS0002G" if (True): query = (input()) #if(query=="done"): #break if (query == "backlogs"): getBacklogs(id) if (query == "acb"): checkstatus(id) if (query == "sendmail"): sendMail("*****@*****.**") if (query == "grade"): subject = (input('Enter the subject: ')) catalog = (input('Enter the catalog: ')) getGrade(id, subject, catalog) if (query == "CGPA"): getCGPA(id) if (query == "PS"): checkPS(id)
def parse(url, alreadyNotified): print("Getting posts from ", url) a = requests.get(url).text tree = BeautifulSoup(a, "lxml") items = tree.find_all('li', attrs={'class': 'result-list__listing'}) print("Found", len(items) / 2, "posts (assuming every 2nd is hidden)") sentEmailsCounter = 0 for item in items: # check if this is some hidden post hidden = (len(item.get('class')) > 1) if hidden: continue # check if we already covered this post id = item.get('data-id') try: ind = alreadyNotified.index(id) continue except ValueError: justgo = "on" # just go on # if this post is new, parse it post = Post(item) sendMail(post) logId(id) sentEmailsCounter += 1 print("Sent", sentEmailsCounter, "emails")
def printMail(msg, file=sys.stdout, body=''): print(msg, file=file) if body == None: # sendmail barfs if body is missing body = '' if body == '': body=msg try: sendmail.sendMail(msg, body=body) except ConnectionRefusedError: print("*** Failed to send the email", file=file)
def printAtticMail(msg, file=sys.stdout): print(msg, file=file) import datetime # Only send the mail once a month if datetime.datetime.now().day != 14: print("Not sending the email to '" + str(ATTIC) +"'" , file=file) return try: sendmail.sendMail(msg,recipients=ATTIC, replyTo=None) except ConnectionRefusedError: print("*** Failed to send the email to '" + str(ATTIC) +"'" , file=file)
def mailAlert(to, sip): try: sendmail.sendMail( 'Tech.Support@tg', to, """Subject: Power down on row %s, switch (%s)\n\r Switch: %s at row %s is possible indicating a power surge!!\n\r\n\r""" % (rowFromIp(sip), switchFromIp(sip), switchFromIp(sip),rowFromIp(sip)) ) except Exception as e: print e, ", Pidgeon did not fly!"
def __init__(self): self.__cfg = configparser.ConfigParser() self.__cfg.read('config.ini') self.__TO = self.__cfg['DEFAULT']['TO'] self.__SUBJECT = self.__cfg['DEFAULT']['SUBJECT'] self.__mailer = sendmail.sendMail() self.__backuppath = self.__readBackupPath() self.__configpath = self.__configPath()
def main(): id = (input('Enter the ID: ')) #eval function to be added in py3 print("For checking acb status type acb" + '\n') print("For checking backlogs status type backlogs" + '\n') print("For sending student mail enter send mail") #id="2018A1PS0002G" if (True): query = (input()) #if(query=="done"): #break if (query == "backlogs"): getBacklogs(id) if (query == "acb"): checkstatus(id) if (query == "sendmail"): sendMail("*****@*****.**")
def ping(address): while True: time.sleep(10) p = os.system('ping ' + address + ' -c 5') if p == 0: print('UP') else: print('DOWN'), sendmail.sendMail() # .sendMail() call function in module sendmail (file in directory)
def ping(address): while True: time.sleep(10) p = os.system('ping ' + address + ' -c 5') if p == 0: print('UP') else: print('DOWN'), sendmail.sendMail( ) # .sendMail() call function in module sendmail (file in directory)
def display_result(clobj, reportFile): scan = clobj() with open(os.getcwd() + '/tmp/' + '%s' % reportFile, 'rb') as sfile: task_lists = pickle.load(sfile) tem = {} for project in task_lists: for pro_id, tasks_id in project.items(): results = scan.show_scan_result(tasks_id) tem[pro_id] = {pro_id: pro_id, 'ip_port': results} for project in list(tem.keys()): # 剔除扫描结果中为空的项目 if not tem[project]['ip_port']: tem.pop(project) if tem: # 使用jinja2模板 env = Environment(loader=PackageLoader('portScan', 'templates')) template = env.get_template('report.html') try: report = template.render(tem=tem) except Exception as e: print(e) times = time.strftime("%Y-%m-%d_%H:%M:%S", time.localtime()) # print(report) # 发送邮件 sendMail(mailto, '端口告警-%s' % times, report) # 微信 data = [] for project in tem: for ip, port in tem[project]['ip_port'].items(): data1 = ip + '%s' % port data.append(data1) message = '端口告警:' + project + '\t' + '%s' % data weixin_alert(Alertuserlist, message)
def checkRqrdNamespace(xml_file): logger.info( 'verifying that this "body" namespace url in document.xml matches our template' ) namespace_check = True ns_url = compareElementNamespace(cfg.doc_xml, cfg.template_document_xml, 'body') # log alert as needed if ns_url != 'expected' and ns_url != 'unavailable': namespace_check = False setup_cleanup.setAlert('error', 'unexpected_namespace') # send notification to wf team so we can keep an eye on these subject = usertext_templates.subjects()["ns_notify"] bodytxt = usertext_templates.emailtxt()["ns_notify"].format( inputfilename=cfg.inputfilename, ns_url=ns_url, submitter=cfg.submitter_email, alert_text=usertext_templates.alerts()['unexpected_namespace'], support_email_address=cfg.support_email_address, helpurl=cfg.helpurl) sendmail.sendMail([cfg.alert_email_address], subject, bodytxt) return namespace_check
def main(): d = sys.stdin.read() log = file('/home/jonathan/forward/log','a') #log.write(d) p = Parser() m = p.parsestr(d, headersonly=True) f = m.get('From').split(' ')[-1].strip('<>') t = m.get('To').split(' ')[-1].strip('<>') if 'one-hour-mail' in t: expire = time.strftime(TFORMAT,time.localtime(time.time()+VALIDTIME)) service = 'One-hour forward mail service' alias = False elif 'forward-mail' in t: expire = '9999-01-01 00:00:00' service = 'Forward mail service' alias = getPersistentAlias(f) else: log.write('Unknown destination (%s)\n'%t) return #check if new alias already in db while not alias: alias = get_alias() while aliasExists(alias): alias = get_alias() insert(alias, f, expire) log.write('INSERT %s -> %s\n'%(alias,f)) text = 'New alias:\n%s\n\n' % (alias+'@'+DOMAIN) text += 'Love,\nForwardBot\n' sendmail.sendMail([f],FROM,service,text)
def start_automation(self, userid, pwd, lesson_id, weekday, time_range): import ctypes # save user settings cur_path = os.path.dirname(os.path.abspath(__file__)) input_file_path = os.path.join(cur_path, "input.txt") if os.path.exists(input_file_path): os.remove(input_file_path) f = open(input_file_path, "w") f.write("{0} {1} {2} {3} {4}\n".format(userid, pwd, lesson_id, weekday, time_range)) f.close() # run auto id_array = [] for key in self.cur_lesson_data: id_array.append(self.cur_lesson_data[key]) if int(lesson_id) < 0 and int(lesson_id) > len(id_array): write_log_file(log_file_path, "レッスンの番号が無効です") return result_status = execute_auto(userid, pwd, id_array[int(lesson_id) - 1], weekday, self.get_time_range(time_range)) if result_status == "true": write_log_file(log_file_path, "予約が成功しました") if self.user_email != "": sendMail("成功", "楽しい時間をお過ごしください。", self.user_email) ctypes.windll.user32.MessageBoxW(0, "予約が成功しました", "予約成功", 0x40000) elif result_status == "false": write_log_file(log_file_path, "予約が失敗しました") if self.user_email != "": sendMail("失敗", "予約が失敗しました。", self.user_email) ctypes.windll.user32.MessageBoxW(0, "予約が失敗しました", "予約失敗", 0x40000) elif result_status == "driver": write_log_file(log_file_path, "ドライバーを更新してください") if self.user_email != "": sendMail("失敗", "ドライバーを更新してください。", self.user_email) ctypes.windll.user32.MessageBoxW(0, "ドライバーを更新してください", "予約失敗", 0x40000) elif result_status == "account": write_log_file(log_file_path, "正確なアカウントを入力してください") if self.user_email != "": sendMail("失敗", "正確なアカウントを入力してください。", self.user_email) ctypes.windll.user32.MessageBoxW(0, "ログイン失敗", "予約失敗", 0x40000)
tagsList.append(tagStr) videoCount = videoCount + 1 count = len(playCountList) if save == True: for i in range(count): addCount = addCount + store.storeVideo(titleList[i], hrefList[i], log_vidList[i], uploaderList[i], playCountList[i], pubdateList[i], "4", gameidx, tagsList[i], thumbImgSrc) print log_vidList[i], uploaderList[i], playCountList[i], pubdateList[i], thumbImgSrc time.sleep(5) return videoCount, addCount startdatestr = datetime.strftime(datetime.now(),'%a %b %d %H:%M:%S %z %Y') ftest, atest = fetchaipai("手机", 1, 2, -1, False) print ftest, atest if ftest <= 0: sendMail("aipai Spider error", "aipai spider is error, check it.") store.connect() gameList = store.getGameList() todayFetch = 0 todayAdd = 0 for aGame in gameList: print "###", aGame[1].decode("utf-8") fet, add = fetchaipai(aGame[1].strip(), 1, 10, aGame[0]) todayFetch = todayFetch + fet todayAdd = todayAdd + add time.sleep(1) store.close() sendMail("aipai Spider Success", "aipai spider success, start at %s fetch %d videos, add %d videos" % (startdatestr, todayFetch, todayAdd))
resultado = sorted(resultado, key=lambda x: x[0]) if (i[21] == "venta"): if (i[37] == "venta"): resultado = sorted(resultado, key=lambda x: x[9], reverse=True) columnNames = [ "Precio", "Útil", "Tot", "D", "B", "E", "Metro", "Dist-est.", "P.P", "Rent.V", "Arriendo", "Rent.A", "Link" ] else: columnNames = [ "Precio", "Útil", "Tot", "D", "B", "E", "Metro", "Dist-est.", "Arriendo", "Rent.A", "Link" ] today = datetime.today().strftime('%Y-%m-%d') nombreArchivo = i[1] + " propiedades usadas VA " + str( tipo) + " " + today pdfC.createPdfReport(i[1], "reporte " + nombreArchivo + ".pdf", resultado, columnNames, operacion) if ((int(i[36])) == 1): sendmail.sendMail(i[3], i[1], ("reporte " + str(nombreArchivo) + ".pdf")) print("Enviando reporte a cliente " + str(i[1])) else: print("No se han encontrado propiedades para el cliente " + i[1]) #insertarClientes_Propiedades(subresultado)
def runpaytest(request): #先清空日志文件 f=open('log/payautotest.log',"w") try: f.truncate(0) finally: f.close() remote_http = request.META['HTTP_HOST'] mailto = request.GET.get('mail') user = mailto.split('@')[0] jobid = request.GET.get('jobid').strip() runtype=request.GET.get('runtype').strip() #result_link = "/static/paytestresult/%s_paytestresult/%s/surefire-reports/index.html" % (user, jobid) result_link="/static/paytestresult/%s_paytestresult/%s/result.html" % (user,jobid) try: logger.info("runpaytest is called ......") file_path = '%s/%s_PayAutoTest' % (paytest_path, user) logger.info(file_path) if runtype =='newpay': file_path='%s/%s_PayAutoTestNew' % (paytest_path,user) if runtype=='smoke': file_path='%s/%s_PayAutoTestSmoke' % (paytest_path,user) if not os.path.exists(file_path): cmd = 'mkdir %s' % (file_path) os.system(cmd) else: cmd='cd %s;rm -rf *' % (file_path) os.system(cmd) if runtype =='newpay': cmd="cd %s; svn co http://svn.meilishuo.com/repos/qa/PayAutoTestNew/ %s" % (paytest_path,file_path) re=os.popen(cmd).read() if runtype=='smoke': cmd="cd %s; svn co http://svn.meilishuo.com/repos/qa/PaySmokeTest/ %s" % (paytest_path,file_path) re=os.popen(cmd).read() else: cmd = "cd %s; svn co http://svn.meilishuo.com/repos/qa/PayAutoTest/ %s" % (paytest_path, file_path) re = os.popen(cmd).read() logger.info("checkout svn code......") dbconf = request.GET.get('dbconf') conf = request.GET.get('config') #任务id,创建文件夹保存结果 #jobid=request.GET.get('jobid').strip() user_result="%s/static/paytestresult/%s_paytestresult" % (BASE_DIR,user) if not os.path.exists(user_result): cmd="cd %s/static/paytestresult/;mkdir %s_paytestresult" % (BASE_DIR,user) re=os.popen(cmd).read() cmd = "cd %s/static/paytestresult/%s_paytestresult;mkdir %s" % (BASE_DIR, user, jobid) re = os.popen(cmd).read() logger.info("make resultfile dir......") env=str(conf).split('username')[0].split('labn=')[1] logger.info("executed env:%s" % (env)) cmd = 'cd %s/src/main/resources/; echo "%s" > ./interface.properties; echo "%s" > ./db.properties' % (file_path, str(conf), str(dbconf)) re = os.popen(cmd).read() logger.info("executed cmd:mvn clean install......") cmd = "cd %s; mvn clean install" % (file_path) ctime=gettime() re = os.popen(cmd).read() logger.info("executed result: \n %s" % (re)) cmd = 'cd %s/target/surefire-reports; cat testng-results.xml | grep "<testng-results"' % (file_path) re = os.popen(cmd).read() test_result = re cmd = 'cp -rf %s/result.html %s/static/paytestresult/%s_paytestresult/%s' % (file_path, BASE_DIR, user, jobid) re = os.popen(cmd).read() #结果链接保存到数据库 etime=gettime() caselink = "/static/paytestresult/%s_paytestresult/%s/result.html" % (user, jobid) pr = PayResult(jobid=jobid, result=caselink, author=user,env=env,ctime=ctime,etime=etime) pr.save() except: test_result = str(sys.exc_info()) mail_result_link = "%s%s" % (remote_http, result_link) mail_content = getContent(test_result, mail_result_link, dbconf, conf) subj = "%s PayAutoTest run result" % (user) sendMail([mailto], subj, mail_content) redict = {"status": test_result, "r_link": result_link} return JsonResponse(redict)
def crearFicha(sitio,id,mail,tipoficha): links=[] text2='' auxPhone=0 #Determinar tipo de informe pro=False interna=False full=False if tipoficha==2: pro=True elif tipoficha==3: interna=True elif tipoficha==4: interna=True pro=True #Chequear que sitio este bien sitio=sitio.lower() if('portal' in sitio): sitio='portal' elif('yapo' in sitio): sitio='yapo' else: text='Sitio ingresado es incorrecto. Favor ingresar portalinmobiliario o yapo.' return(text) #Chequear que mail este bien if ('@' not in mail): text='Email incorrecto. Favor ingresar correo válido.' return(text) if ('.' not in mail): text='Email incorrecto. Favor ingresar correo válido.' return(text) #sacar informacion de bbdd, y chequear que propiedad existe: propiedad=obtenerProp(id,sitio) if len(propiedad)<1: text='¨Propiedad no se encuentra en la base de datos.' return(text) else: propiedad=list(propiedad) nombre=str(propiedad[0]) region=str(propiedad[1]) regionP=region regionY=region if region=='15': regionP='metropolitana' if region=='metropolitana': regionY='15' operacion=str(propiedad[2]) tipo=str(propiedad[3]) precio=float(propiedad[4]) dormitorios=str(propiedad[5]) banos=str(propiedad[6]) metrosmin=str(propiedad[7]) metrosmax=str(propiedad[8]) estacionamientos=str(propiedad[9]) bodegas=str(propiedad[10]) lat=str(propiedad[11]) lon=str(propiedad[12]) link=str(propiedad[13]) if sitio=='portal': if operacion=='venta': comuna=str(link.split('/')[5]) comuna=comuna.replace('-'+str(regionP),'') comuna=comuna.replace('-',' ') comuna=comuna.capitalize() propiedad.append(comuna) else: comuna=str(link.split('/')[6]) comuna=comuna.replace('-metropolitana','') comuna=comuna.replace('-',' ') comuna=comuna.capitalize() propiedad.append(comuna) else: comuna=str(propiedad[14]) #Revisar si existe aun la publicacion if not pubPortalExiste.publicacionExiste(link): text='Propiedad ya no se encuentra disponible en el sitio.' return(text) #sacar informacion de la publicacion #sacar urls fotos portal matrixdescripcion=[] matrixcounter=0 matrixdescripcion.append('') if sitio=='portal': first=True url=[] page = requests.get(link, headers={'User-Agent': agentCreator.generateAgent()}) metatext=page.text metatext=metatext.split(' ') descripcion=[] savedescripcion=False for texto in metatext: if 'propiedad-descr' in texto: savedescripcion=True if '/div' in texto: savedescripcion = False if savedescripcion: descripcion.append(str(texto)) descripcion=descripcion[2:] print(descripcion) if not interna: for desc in descripcion: desc=desc.replace(' ','') desc=desc.replace('<br />',' ') desc=desc.replace('<br/>',' ') desc=desc.replace('<br>',' ') desc=desc.replace('<b/>','') desc=desc.replace('<b>','') desc=desc.replace('</b>','') desc=desc.replace('<br','') desc=desc.replace('/>','') desc=desc.replace('í','í') desc=desc.replace('é','é') desc=desc.replace('ó','ó') desc=desc.replace('á','á') desc=desc.replace('ú','ú') desc=desc.replace('ñ','ñ') desc=desc.replace('Ñ','Ñ') if "+56" in desc: desc="**" if len(desc)>=6: try: desc.replace('\n',"") int(desc) desc="**" except: pass if "@" in desc: desc="***" if ((len(matrixdescripcion[matrixcounter])+len(desc))>=78): matrixcounter+=1 matrixdescripcion.append('') if desc!= '': matrixdescripcion[matrixcounter]=matrixdescripcion[matrixcounter]+str(desc) else: if first: if desc!= '': matrixdescripcion[matrixcounter]=matrixdescripcion[matrixcounter]+str(desc) first=False else: if desc!= '': matrixdescripcion[matrixcounter]=matrixdescripcion[matrixcounter]+' '+str(desc) print(matrixdescripcion) for x,matrix in enumerate(matrixdescripcion): matrix=matrix.replace('<br />','\n') matrix=matrix.replace('<br/>','\n') matrix=matrix.replace('<br>','\n') matrix=matrix.replace('<b/>','') matrix=matrix.replace('<b>','') matrix=matrix.replace('</b>','') matrixdescripcion[x]=matrix descripcion='\n'.join(matrixdescripcion) propiedad.append(descripcion) else: descripcion=' '.join(descripcion) descripcion=descripcion.replace(' ','') descripcion=descripcion.replace('<br />','\n') descripcion=descripcion.replace('<br/>','\n') descripcion=descripcion.replace('<br>','\n') descripcion=descripcion.replace('<b/>','') descripcion=descripcion.replace('<b>','') descripcion=descripcion.replace('</b>','') descripcion=descripcion.replace('<br','') descripcion=descripcion.replace('/>','') descripcion=descripcion.replace('í','í') descripcion=descripcion.replace('é','é') descripcion=descripcion.replace('ó','ó') descripcion=descripcion.replace('á','á') descripcion=descripcion.replace('ú','ú') descripcion=descripcion.replace('ñ','ñ') descripcion=descripcion.replace('Ñ','Ñ') propiedad.append(descripcion) for meta in metatext: if 'https://image.portalinmobiliario.cl/Portal/Propiedades' in meta and '1200' in meta: meta=meta.split('"') url.append(str(meta[1])) #Sacar urls fotos yapo else: url=[] page = requests.get(link, headers={'User-Agent': agentCreator.generateAgent()}) metatext=page.text metatext=metatext.split(' ') descripcion=[] savedescripcion=False saveimg=False og=True for texto in metatext: if '<h4>Descripción</h4>' in texto: savedescripcion=True if og and 'og:image' in texto: saveimg=True og=False if 'img/yapo' in texto: saveimg=False if savedescripcion: descripcion.append(str(texto)) if '</div>' in texto: savedescripcion = False if saveimg and 'img.yapo.cl/images' in texto: texto=texto.replace('content="','') texto.replace('"','') url.append(texto) if 'phone-url' in texto: texto=texto.split('"') texto=texto[1] auxPhone=texto auxPhone='https://www.yapo.cl'+auxPhone descripcion=descripcion[1:] first=True print(descripcion) for desc in descripcion: desc=desc.replace('\n',' ') desc=desc.replace('<br />','\n') desc=desc.replace('</div>','\n') desc=desc.replace('<br>','\n') desc=desc.replace('<br','') desc=desc.replace('/>','') desc=desc.replace('itemprop="description">',"") desc=desc.replace('</p>','\n') desc=desc.replace("\t","") desc=desc.replace('<!','') desc=desc.replace('--','') desc=desc.replace(' ','') desc=desc.replace('\n',' ') if ((len(matrixdescripcion[matrixcounter])+len(desc))>=78): matrixcounter+=1 matrixdescripcion.append('') matrixdescripcion[matrixcounter]=matrixdescripcion[matrixcounter]+str(desc) else: if first: matrixdescripcion[matrixcounter]=matrixdescripcion[matrixcounter]+str(desc) first=False else: matrixdescripcion[matrixcounter]=matrixdescripcion[matrixcounter]+' '+str(desc) print(matrixdescripcion) descripcion='\n'.join(matrixdescripcion) propiedad.append(descripcion) try: print(auxPhone) response = requests.get(auxPhone, headers={'User-Agent': agentCreator.generateAgent()}) auxphone2=auxPhone img = Image.open(BytesIO(response.content)) img=img.convert('L') img=img.convert('1') img.save("auxphone.gif") auxPhone=1 except: pass lenfotos=len(url) if len(url)==0: print("la propiedad no cuenta con fotografias") else: print('total fotos: '+str(len(url))) for x,u in enumerate (url): u=u.replace('"','') response = requests.get(u) img = Image.open(BytesIO(response.content)) img.save(str(x)+" foto.jpg") if not interna: imagenDescripcion = Image.new('RGB', (456, 345), color = (255, 255, 255)) d = ImageDraw.Draw(imagenDescripcion) f= ImageFont.truetype('arial.ttf',12) d.text((0,0), descripcion,font=f, fill=(0,0,0)) imagenDescripcion.save('imagenDescripcion.png') datospro = [] if pro: comunaP = (comuna.replace(' ', '-') + '-'+str(region)).lower() listacomunas=[] listacomunas.append(comuna) propsP = reportes.from_portalinmobiliario(tipo, regionP,listacomunas, True) propsY = reportes.from_yapo(tipo, regionY,listacomunas, True, True) props = propsP + propsY if operacion=='venta': print("la comuna para calcular la rentabilidad promedio es:") print(comunaP) rentaPromedio = reportes.rentaPProm(tipo, float(dormitorios), float(banos), float(estacionamientos), comunaP) print("input tasacion ficha") print(tipo) print(float(lat)) print(float(lon)) print(float(metrosmin)) print(float(metrosmax)) print(float(dormitorios)) print(float(banos)) print(float(estacionamientos)) tasacionVenta = tb2.calcularTasacionData("venta", tipo, float(lat), float(lon), float(metrosmin),float(metrosmax),float(dormitorios), float(banos), float(estacionamientos), props) tasacionArriendo = tb2.calcularTasacionData("arriendo", tipo, float(lat), float(lon), float(metrosmin),float(metrosmax),float(dormitorios), float(banos), float(estacionamientos), props) precioV = tasacionVenta[0] * uf.getUf() precioA = tasacionArriendo[0] print("el precio tasado de venta inicial es: "+str(precioV)) print("el precio tasado de arriendo inicial es: "+str(precioA)) links=tasacionVenta[3] if precioV is None or precioV < 0.1: pro=False try: precioA = tasacionArriendo[0] rentaV = ((precioV - precio) / precio) except: pro=False text2='No se ha podido realizar tasación' print('fail 1') if precioA is None or precioA < 0.01: pro=False try: rentaA = (precioA * 12 / precio) print('succes 2.1') print(precioA) print(precioV) rentaPP = (precioA * 12 / precioV) print('succes 2.2') except: pro=False text2='No se ha podido realizar tasación' print('fail 2') if pro: if rentaA > 0.2: pro=False print('fail 3') if rentaPP < 1.2*rentaPromedio: try: print("[GeneradorReportes] renta pp muy baja, recalculando precio") print("precio anterior:"+str(precioV)) precioV = precioA * 12 / rentaPromedio rentaV = ((precioV - precio) / precio) rentaPP = (precioA * 12 / precioV) print("precio nuevo:"+str(precioV)) except: pro=False text2='No se ha podido realizar tasación' print('fail 4') if rentaPP > 0.15: try: precioV = precioA * 12 / 0.15 rentaV = ((precioV - precio) / precio) except: pro=False text2='No se ha podido realizar tasación' print('fail 52') if rentaA < 0: pro=False if pro: # precio venta tasado datospro.append(precioV) # rentabilidad de venta datospro.append(float(rentaV)) # precio arriendo tasado datospro.append(precioA) # rentabilidad de arriendo datospro.append(float(rentaA)) else: try: tasacionArriendo = tb2.calcularTasacionData("arriendo", tipo, float(lat), float(lon), float(metrosmin),float(metrosmax),float(dormitorios), float(banos), float(estacionamientos), props) except: pro=False text2='No se ha podido realizar tasación' print('fail 6') try: precioA = tasacionArriendo[0] links=tasacionArriendo[3] except: pro=False text2='No se ha podido realizar tasación' print('fail 72') if pro: if precioA is None or precioA < 0.01: pro = False text2='No se ha podido realizar tasación' print('fail 8') if pro: # precio arriendo tasado datospro.append(precioA) # rentabilidad de arriendo datoscontacto = [] if interna: if sitio=='portal': try: email, telefono, dueno = reportes.getDatosDueno(str(id)) except: email = "NN" telefono = "NN" dueno = "NN" else: email = "NN" if auxPhone == 1: telefono=auxphone2 else: telefono = "NN" dueno = 'NN' datoscontacto.append(email) datoscontacto.append(telefono) datoscontacto.append(dueno) #Crear PDF if interna: nombrearchivo="Ficha Propiedad Sitio:"+str(sitio)+" Id:"+str(id)+".pdf" else: nombrearchivo="Ficha Propiedad Sitio:"+str(sitio)+", "+str(operacion)+", "+str(tipo)+", "+str(region)+", "+str(comuna)+".pdf" print(nombrearchivo) pdfCreatorFichas.crearPdfFicha(nombrearchivo,id,propiedad,lenfotos,pro,datospro,interna,datoscontacto,regionP,links) print("pdf generado con exito") #Enviar PDF sendmail.sendMail(mail,"",nombrearchivo) #Eliminar del servidor if len(url)==0: pass else: for x,u in enumerate (url): os.remove(str(x)+" foto.jpg") try: os.remove("auxphone.gif") except: pass if not interna: try: os.remove("imagenDescripcion.png") except: pass os.remove(nombrearchivo) #Retornar exito text = "Ficha creada para la propiedad: "+str(id)+" obtenida del sitio: "+str(sitio)+", enviada con éxito al correo: "+str(mail)+"." if text2!='': text=text2+'. '+text return(text)
def commonHandler(self): mgl.myLog("commonHandler()") lines = [] args = {} for argKey in self.request.arguments(): argVal = self.request.get(argKey) args[argKey] = argVal lines.append(argKey + " = " + argVal) mgl.myLog(args) if not validateInput(args): lines.extend([ "Bad attributes: email is not sent", ]) # Good attributes else: #Real email sending sendmail.sendMail( self.request.get("from"), self.request.get("to"), self.request.get("subject"), self.request.get("message"), self.request.get("name"), #args["from"], args["to"], args["subject"], args["message"], args["name"] ) #TBD test #sendmail.sendMailTest() redirectURL = self.request.get("redirect").encode('ascii', 'ignore') if len(redirectURL) > 0: mgl.myLog("Performing redirection to " + redirectURL) self.redirect(redirectURL) else: # Normal page display self.response.headers["Content-Type"] = "text/html; charset=utf-8" self.response.write( '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"\n' ) self.response.write(' "http://www.w3.org/TR/html4/loose.dtd">\n') self.response.write( '<html>\n' + '<head>\n' + '<title>Mailer</title>\n' + '<meta http-equiv="Content-type" content="text/html;charset=UTF-8">\n' + '</head>\n' + '<body>\n\n') for l in lines: mgl.myLog(l) self.response.write(mgl.processLine(l)) self.response.write('\n') self.response.write( '<div><img alt="Powered by Google" src="powered-by-google-on-white.png" width="104" height="16"></div>\n' ) self.response.write('\n') self.response.write(r"""<script type="text/javascript">""" + "\n") self.response.write( r""" (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){""" + "\n") self.response.write( r""" (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),""" + "\n") self.response.write( r""" m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)""" + "\n") self.response.write( r""" })(window,document,'script','//www.google-analytics.com/analytics.js','ga');""" + "\n") self.response.write( r""" ga('create', 'UA-1787000-3', 'mgouin.appspot.com');""" + "\n") self.response.write(r""" ga('send', 'pageview');""" + "\n") self.response.write(r"""</script>""" + "\n") self.response.write("\n</body>\n</html>\n")
def tasador(client): textmail="" regionYapoAux=client["region"] regYapoDict={ "Metropolitana":"15", "Valparaiso":"6", "Valparaíso":"6", "Arica":"1", "Iquique":"2", "Antofagasta":"3", "Atacama":"4", "Coquimbo":"5", "Ohiggins":"7", "Maule":"8", "Ñuble":"16", "Biobio":"9", "Araucania":"10", "Los Rios":"11", "Los Lagos":"12", "Aysen":"13", "Magallanes":"14", } regionYapo=regYapoDict[regionYapoAux] print("Diccionario de Regiones para Yapo Creado") if "bodegas" not in client: client["bodegas"]=0 if "estacionamientos" not in client: client["estacionamientos"]=0 if "baños" not in client: client["baños"]=0 if "dormitorios" not in client: client["dormitorios"]=0 comuna=client["comuna"] if comuna=="Santiago Centro": comuna="Santiago" listacomunas=[] listacomunas.append(comuna) propsPV = reportes.from_portalinmobiliario(client["tipo"].lower(),client["region"].lower(),listacomunas,"venta",True) propsYV = reportes.from_yapo(client["tipo"].lower(),regionYapo,listacomunas,True,"venta",True) propsV = propsPV + propsYV # aca deberiamos hacer el GB m2=reportes.m2prom(client["tipo"].lower(),comuna,client["region"].lower()) m2V=m2[0] m2A=m2[1] clfHV = ensemble.GradientBoostingRegressor(n_estimators=400, max_depth=5, min_samples_split=2, learning_rate=0.1, loss='huber') #id2,fechapublicacion,fechascrap,operacion,tipo,precio,dormitorios,banos,metrosmin,metrosmax,lat,lon,estacionamientos,link preciosV = [row[5] for row in propsV] trainingV = propsV.copy() for row in trainingV: del row[13] if client["tipo"].lower()=="comercial": del row[7] del row[6] del row[5] del row[4] del row[3] del row[2] del row[1] del row[0] # x_train , x_test , y_train , y_test = train_test_split(trainingV , preciosV , test_size = 0.10,random_state = 2) # # #obtain scores venta: # clfHV.fit(x_train, y_train) # print("-----------") # print("Score Huber:") # print(clfHV.score(x_test,y_test)) # scoreV=clfHV.score(x_test,y_test) clfHV.fit(trainingV, preciosV) propsPA = reportes.from_portalinmobiliario(client["tipo"].lower(),client["region"].lower(),listacomunas,"arriendo",True) propsYA = reportes.from_yapo(client["tipo"].lower(),regionYapo,listacomunas,True,"arriendo",True) propsA = propsPA + propsYA # aca deberiamos hacer el GB clfHA = ensemble.GradientBoostingRegressor(n_estimators=400, max_depth=5, min_samples_split=2, learning_rate=0.1, loss='huber') #id2,fechapublicacion,fechascrap,operacion,tipo,precio,dormitorios,banos,metrosmin,metrosmax,lat,lon,estacionamientos,link preciosA = [row[5] for row in propsA] trainingA = propsA.copy() for row in trainingA: del row[13] if client["tipo"].lower()=="comercial": del row[7] del row[6] del row[5] del row[4] del row[3] del row[2] del row[1] del row[0] # x_train , x_test , y_train , y_test = train_test_split(trainingA , preciosA , test_size = 0.10,random_state = 2) # # #obtain scores arriendo: # clfHA.fit(x_train, y_train) # print("-----------") # print("Score Huber:") # print(clfHA.score(x_test,y_test)) # scoreA=clfHA.score(x_test,y_test) clfHA.fit(trainingA, preciosA) textmail+="Resultados comuna "+str(comuna)+":\nPrecio m2 Venta: UF "+'{:,}'.format((int(10*(m2V/ufn)))/10).replace(",",".")+"\nPrecio m2 Arriendo: $ "+'{:,}'.format(int(m2A)).replace(",",".")+"\n\n" ufventacomuna='{:,}'.format((int(10*(m2V/ufn)))/10).replace(",",".") arriendocomuna='{:,}'.format(int(m2A)).replace(",",".") if client["tipo"].lower()=="comercial": tasacionVenta = clfHV.predict([[ int(client["metros"]),int(client["total"]), client["lat"],client["lon"], int(client["estacionamientos"])]]) tasacionArriendo = clfHA.predict([[int(client["baños"]), int(client["metros"]),int(client["total"]), client["lat"],client["lon"], int(client["estacionamientos"])]]) else: tasacionVenta = clfHV.predict([[int(client["dormitorios"]),int(client["baños"]), int(client["metros"]),int(client["total"]), client["lat"],client["lon"], int(client["estacionamientos"])]]) tasacionArriendo = clfHA.predict([[int(client["dormitorios"]),int(client["baños"]), int(client["metros"]),int(client["total"]), client["lat"],client["lon"], int(client["estacionamientos"])]]) precioV = tasacionVenta precioA = tasacionArriendo print("Tasacion Check") if precioV==None: text="No se ha podido realizar la tasación." return text else: print("precio de venta es de: "+str(precioV)) print("precio de arriendo es de: "+str(precioA)) if client["tipotasacion"]=="Full": linksVenta=obtenerLinks(client,precioV,True) linksArriendo=obtenerLinks(client,precioA,False) print("links obtenidos") fileName = "Tasacion " + client["tipo"] + " en " + client["comuna"] + ", " + client[ "region"] + " cliente " + client["firstname"] + " " + client["lastname"]+".pdf" pdfc.crearPdfTasacion(client,precioV,precioA,linksVenta,linksArriendo,fileName,ufventacomuna,arriendocomuna) print("pdf creado") print(client["mail"],client["firstname"]+" "+client["lastname"],fileName) sendmail.sendMail(client["mail"],client["firstname"]+" "+client["lastname"],fileName) print('mandando correo con tasacion') textmail+="Su propiedad se ha tasado a un valor de venta de UF "+'{:,}'.format(int(precioV/ufn)).replace(",",".")+"\n" textmail+="Su propiedad se ha tasado a un valor de arriendo de $ "+'{:,}'.format(int(precioA)).replace(",",".")+"\n" print("Texto Full, Check") return textmail
return 2 try: if mc['log_file_path']: logger.debug("Adding log file in %s folder for logging purposes." % (mc['log_file_path'])) initLogFile(mc['log_file_path']) logger.debug("Successfully added log file in %s folder for logging purposes." % (mc['log_file_path'])) else: logger.info("No log file specified. Skipping initLogFile().") except Exception, e: logger.error("Failed to initialize log file %s. Reason: %s" % (mc['log_file_path'], str(e))) traceback.print_exc() # sendMail( mc['smtp_server'], mc['sender'], mc['admin_recipients'], "FAILURE - AUTOSYS - Autosys Monitor Script on %s. [%s]" % ( (datetime.datetime.now()).strftime("%Y-%m-%d %H:%M"), mc['hostname'] ), "%s" % ( str(e) ),None ) sendmail.sendMail(mc['smtp_server'], None, None, mc['sender'], "FAILURE - AUTOSYS - Autosys Monitor Script on %s. [%s]" % ( (datetime.datetime.now()).strftime("%Y-%m-%d %H:%M"), mc['hostname']), mc['admin_recipients'], None, "%s" % (str(e)), [], "plain", None) return 2 # load the list and settings for remote agents to be tested try: agents = loadAgents(mc['remote_agent_list_path'], mc['agent_retries']) except Exception, e: logger.error("Failed to complete loadAgents. Reason: %s" % (str(e))) traceback.print_exc() # sendMail( mc['smtp_server'], mc['sender'], mc['admin_recipients'], "FAILURE - AUTOSYS - Autosys Monitor Script on %s. [%s]" % ( (datetime.datetime.now()).strftime("%Y-%m-%d %H:%M"), mc['hostname'] ), "%s" % ( str(e) ),None ) sendmail.sendMail(mc['smtp_server'], None, None, mc['sender'], "FAILURE - AUTOSYS - Autosys Monitor Script on %s. [%s]" % ( (datetime.datetime.now()).strftime("%Y-%m-%d %H:%M"), mc['hostname']), mc['admin_recipients'],
def POST(self): sendmail.sendMail()
def GET(self): sendmail.sendMail()
newPriceMsg = u"没有可转债满足 买入条件。" HPriceMsg = u"没有可转债满足 高价折扣法。" now_time = datetime.now() today_year = now_time.year today_month = now_time.month today_day = now_time.day #print today_year, today_month, today_day start_time = datetime(today_year, today_month, today_day, 9, 29, 59) # 设定开始时间9:29:59。 end_time = datetime(today_year, today_month, today_day, 14, 59, 59) # 设定结束时间到当天的14:59:59。 #print end_time print sysMsg print sendMail(sysMsg) while datetime.now() < end_time: if datetime.now() > start_time and datetime.now() < end_time: #print datetime.now() print time.asctime(time.localtime(time.time())) #显示查询时间 # 三线分析: msglist = getCB() #查询是否有CB满足三线买入条件 if len(msglist) == 0: #没有满足条件的CB print newPriceMsg else: for msg in msglist: #有满足条件的CB print msg
cmd = 'cp -rf %s/target/surefire-reports %s/static/paytestresult/%s_paytestresult/%s' % (file_path, BASE_DIR, user, jobid) re = os.popen(cmd).read() logger.info("executed cmd: \n %s" % (cmd)) logger.info("executed result: \n %s" % (re)) #结果链接保存到数据库 caselink = "/static/paytestresult/%s_paytestresult/%s/surefire-reports/index.html" % (user, jobid) pr = PayResult(jobid=jobid, result=caselink, author=user) pr.save() except Exception, e: logger.exception(e) mail_result_link = "%s%s" % (remote_http, result_link) mail_content = getContent(test_result, mail_result_link, dbconf, conf) subj = "%s PayAutoTest run result" % (user) sendMail([user], subj, mail_content) redict = {"status": test_result, "r_link": result_link} return JsonResponse(redict) # def getContent(result, link, dbconf, conf): # mail_content = """ # run result: \n # %s \n # result link: \n # %s \n # dbconf: \n # %s \n # Case conf: \n # %s \n # """ % (result, link, dbconf, conf)
logger.info( "File mtime unchanged. Sleeping..." ) time.sleep( 3 ) logger.debug( "File mtime has changed." ) last_mtime = getmtime( mc['src_file_path'] ) with open( mc['src_file_path'] ) as file: lines = file.readlines() current_linecount = getLineCount( mc['src_file_path'] ) logger.debug( "last_linecount: %d current_linecount: %d" % ( last_linecount,current_linecount) ) if last_linecount < current_linecount: newlines = lines[last_linecount:] last_linecount = current_linecount for line in newlines: if pattern.search( line ): print "Line contains oracle error. Line = %s" % ( line ) #sendmail.sendMail( smtp_server, smtp_user,smtp_pwd,sender, subject, nts, cc, body, files, encoding,replyto=None): sendmail.sendMail('smtpext.maxcorp.maximus', None, None, '*****@*****.**', 'FAILURE - ASYS - ORACLE Error Detected.', mc['recipients'], None, 'Oracle error detected in event_demon.PRD file. Send logs to CA.', [], 'text') return 0 else: logger.debug( "line does not contain error message. Line = %s" % ( line ) ) #check lines for watched text except Exception, err: logger.error( "Failed to monitor file %s. Reason: %s." % ( mc['src_file_path'], str(err) ) ) traceback.print_exc() return 2 return if __name__ == "__main__": sys.exit(main())
def printMail(msg): print(msg) try: sendmail.sendMail(msg) except ConnectionRefusedError: print("*** Failed to send the email")
def main(diff_file, new_file, noquery): # Load old data with open(OLD_DATA_FILE, 'r') as f: old_data = json.load(f) # Load new data if noquery: with open(new_file, 'r') as f: new_data = json.load(f) else: # Copy previous backup to old data copyfile(new_file, OLD_DATA_FILE) # Build new backup new_data = query_api(new_file) # Report of activity message = '' # New words items_id = set(old_data['items'].keys()) ^ set(new_data['items'].keys()) if items_id: message += u"<h1>New words added:</h1><ul>" for i in list(items_id): item = new_data['items'][i]['thing']['columns'] if len(item.keys()) == 3: message += u'<li><b>{}</b>({}): {}</li>'.format( item['1']['val'], item['3']['val'], item['2']['val']) elif len(item.keys()) == 5: message += u'<li><b>{}</b>({}): {}</li>'.format( item['1']['val'], item['6']['val'], item['5']['val']) if items_id: message += '</ul>' # words changed if old_data['items'] != new_data['items']: message += u"<h1>Words modified:</h1><ul>" for i in list(set(new_data['items'].keys()) - items_id): col1 = old_data['items'][i]['thing']['columns'] col2 = new_data['items'][i]['thing']['columns'] att1 = old_data['items'][i]['thing']['attributes'] att2 = new_data['items'][i]['thing']['attributes'] mes = '' if att1 != att2 or col1 != col2: if att1 != att2: mes += '<br /><i>Different attributes:</i>{}'.format( BLOCKQUOTE) mes += '<br />'.join([ u' → '.join([att1[k]['val'], att2[k]['val']]) for k in att1.keys() if att1[k]['val'] != att2[k]['val'] ]) mes += '</blockquote>' if col1 != col2: for k in col1.keys(): if col1[k]['alts'] != col2[k]['alts']: mes += '<br /><i>New alts:</i> ' mes += ', '.join( set([d['val'] for d in col1[k]['alts'] ]).symmetric_difference( set([d['val'] for d in col2[k]['alts']]))) if col1[k]['val'] != col2[k]['val']: mes += u'<br /><i>Different val:</i> {}{}→ {}'\ '</blockquote>'.format(col1[k]['val'], BLOCKQUOTE, col2[k]['val']) if mes: message += u'<li><b>{}</b> ({}):{}</li>'.format( col1['1']['val'], i, mes) if old_data['items'] != new_data['items']: message += '</ul>' sendMail(message)
def crearFicha(sitio, id, mail, tipoficha): links = [] text2 = '' auxPhone = 0 #Determinar tipo de informe pro = False interna = False financiera = False textmail = '' ufn = uf.getUf() if tipoficha > 4: financiera = True tipoficha = tipoficha - 4 if tipoficha == 2: pro = True elif tipoficha == 3: interna = True elif tipoficha == 4: interna = True pro = True #Chequear que sitio este bien sitio = sitio.lower() if ('portal' in sitio): sitio = 'portal' elif ('yapo' in sitio): sitio = 'yapo' else: text = 'Sitio ingresado es incorrecto. Favor ingresar portalinmobiliario o yapo.' return (text) #Chequear que mail este bien if ('@' not in mail): text = 'Email incorrecto. Favor ingresar correo válido.' return (text) if ('.' not in mail): text = 'Email incorrecto. Favor ingresar correo válido.' return (text) #sacar informacion de bbdd, y chequear que propiedad existe: propiedad = obtenerProp(id, sitio) print(propiedad) if len(propiedad) < 1: if sitio == 'portal': link = "https://www.portalinmobiliario.com/" + str(id) else: link = "https://www.yapo.cl/region_metropolitana/" + str(id) if not pubPortalExiste.publicacionExiste( link) and not pubYapoExiste.publicacionExiste(link): text = '¨Propiedad no se encuentra en la base de datos.' return (text) elif sitio == "portal": pass else: if obtainPropFromYapo(link) is not False: propiedad = obtainPropFromYapo(link) else: regYapoDict = { "metropolitana": "15", "valparaiso": "6", "Valparaíso": "6", "arica": "1", "iquique": "2", "antofagasta": "3", "atacama": "4", "coquimbo": "5", "ohiggins": "7", "maule": "8", "ñuble": "16", "biobio": "9", "araucania": "10", "los Rios": "11", "los Lagos": "12", "aysen": "13", "magallanes": "14", } propiedad = list(propiedad) region = str(propiedad[1]) regionP = region regionY = regYapoDict[region.lower()] if region == '15': regionP = 'metropolitana' if region == 'metropolitana': regionY = '15' operacion = str(propiedad[2]) tipo = str(propiedad[3]) precio = float(propiedad[4]) dormitorios = str(propiedad[5]) banos = str(propiedad[6]) metrosmin = str(propiedad[7]) metrosmax = str(propiedad[8]) estacionamientos = str(propiedad[9]) bodegas = str(propiedad[10]) lat = str(propiedad[11]) lon = str(propiedad[12]) link = str(propiedad[13]) if sitio == 'portal': if operacion == 'venta': comuna = str(link.split('/')[5]) comuna = comuna.replace('-' + str(regionP), '') comuna = comuna.replace('-', ' ') comuna = comuna.capitalize() propiedad.append(comuna) else: comuna = str(link.split('/')[6]) comuna = comuna.replace('-metropolitana', '') comuna = comuna.replace('-', ' ') comuna = comuna.capitalize() propiedad.append(comuna) else: comuna = str(propiedad[14]) #Revisar si existe aun la publicacion if not pubPortalExiste.publicacionExiste(link): text = 'Propiedad ya no se encuentra disponible en el sitio.' return (text) #sacar informacion de la publicacion #sacar urls fotos portal matrixdescripcion = [] matrixcounter = 0 matrixdescripcion.append('') if sitio == 'portal': first = True url = [] page = requests.get( link, headers={'User-Agent': agentCreator.generateAgent()}) metatext = page.text metatext = metatext.split(' ') descripcion = [] savedescripcion = False for texto in metatext: if 'item-description__text' in texto: savedescripcion = True if '/div' in texto: if savedescripcion: descripcion.append(str(texto)) savedescripcion = False if savedescripcion: descripcion.append(str(texto)) descripcion2 = descripcion.copy() first = (descripcion2[0]) first = first.split(">") print(first) first = first[2] descripcion[0] = first last = descripcion2[-1] last = last.split("<") last = last[0] descripcion[-1] = last #descripcion=descripcion[2:] print(descripcion) descripcion = list(descripcion) if not interna: for desc in descripcion: desc = desc.replace(' ', '') desc = desc.replace('<br />', ' ') desc = desc.replace('<br/>', ' ') desc = desc.replace('<br>', ' ') desc = desc.replace('<b/>', '') desc = desc.replace('<b>', '') desc = desc.replace('</b>', '') desc = desc.replace('<br', '') desc = desc.replace('/>', '') desc = desc.replace('í', 'í') desc = desc.replace('é', 'é') desc = desc.replace('ó', 'ó') desc = desc.replace('á', 'á') desc = desc.replace('ú', 'ú') desc = desc.replace('ñ', 'ñ') desc = desc.replace('Ñ', 'Ñ') if "+56" in desc: desc = "**" if len(desc) >= 6: try: desc.replace('\n', "") int(desc) desc = "**" except: pass if "@" in desc: desc = "***" if ((len(matrixdescripcion[matrixcounter]) + len(desc)) >= 78): matrixcounter += 1 matrixdescripcion.append('') if desc != '': matrixdescripcion[matrixcounter] = matrixdescripcion[ matrixcounter] + str(desc) else: if first: if desc != '': matrixdescripcion[ matrixcounter] = matrixdescripcion[ matrixcounter] + str(desc) first = False else: if desc != '': matrixdescripcion[ matrixcounter] = matrixdescripcion[ matrixcounter] + ' ' + str(desc) print(matrixdescripcion) for x, matrix in enumerate(matrixdescripcion): matrix = matrix.replace('<br />', '\n') matrix = matrix.replace('<br/>', '\n') matrix = matrix.replace('<br>', '\n') matrix = matrix.replace('<b/>', '') matrix = matrix.replace('<b>', '') matrix = matrix.replace('</b>', '') matrixdescripcion[x] = matrix descripcion = '\n'.join(matrixdescripcion) propiedad.append(descripcion) else: descripcion = ' '.join(descripcion) descripcion = descripcion.replace(' ', '') descripcion = descripcion.replace('<br />', '\n') descripcion = descripcion.replace('<br/>', '\n') descripcion = descripcion.replace('<br>', '\n') descripcion = descripcion.replace('<b/>', '') descripcion = descripcion.replace('<b>', '') descripcion = descripcion.replace('</b>', '') descripcion = descripcion.replace('<br', '') descripcion = descripcion.replace('/>', '') descripcion = descripcion.replace('í', 'í') descripcion = descripcion.replace('é', 'é') descripcion = descripcion.replace('ó', 'ó') descripcion = descripcion.replace('á', 'á') descripcion = descripcion.replace('ú', 'ú') descripcion = descripcion.replace('ñ', 'ñ') descripcion = descripcion.replace('Ñ', 'Ñ') propiedad.append(descripcion) print(propiedad) for meta in metatext: if 'data-full-images' in meta: meta = meta.split(';') for met in meta: if 'mlstatic' in met: met = met.split('&') met = met[0] met = met.replace(".webp", ".jpg") url.append(str(met)) #Sacar urls fotos yapo else: url = [] page = requests.get( link, headers={'User-Agent': agentCreator.generateAgent()}) metatext = page.text metatext = metatext.split(' ') descripcion = [] savedescripcion = False saveimg = False og = True for texto in metatext: if '<h4>Descripción</h4>' in texto: savedescripcion = True if og and 'og:image' in texto: saveimg = True og = False if 'img/yapo' in texto: saveimg = False if savedescripcion: descripcion.append(str(texto)) if '</div>' in texto: savedescripcion = False if saveimg and 'img.yapo.cl/images' in texto: texto = texto.replace('content="', '') texto.replace('"', '') url.append(texto) if 'phone-url' in texto: texto = texto.split('"') texto = texto[1] auxPhone = texto auxPhone = 'https://www.yapo.cl' + auxPhone descripcion = descripcion[1:] first = True print(descripcion) for desc in descripcion: desc = desc.replace('\n', ' ') desc = desc.replace('<br />', '\n') desc = desc.replace('</div>', '\n') desc = desc.replace('<br>', '\n') desc = desc.replace('<br', '') desc = desc.replace('/>', '') desc = desc.replace('itemprop="description">', "") desc = desc.replace('</p>', '\n') desc = desc.replace("\t", "") desc = desc.replace('<!', '') desc = desc.replace('--', '') desc = desc.replace(' ', '') desc = desc.replace('\n', ' ') if ((len(matrixdescripcion[matrixcounter]) + len(desc)) >= 78): matrixcounter += 1 matrixdescripcion.append('') matrixdescripcion[matrixcounter] = matrixdescripcion[ matrixcounter] + str(desc) else: if first: matrixdescripcion[matrixcounter] = matrixdescripcion[ matrixcounter] + str(desc) first = False else: matrixdescripcion[matrixcounter] = matrixdescripcion[ matrixcounter] + ' ' + str(desc) print(matrixdescripcion) descripcion = '\n'.join(matrixdescripcion) propiedad.append(descripcion) try: print(auxPhone) response = requests.get( auxPhone, headers={'User-Agent': agentCreator.generateAgent()}) auxphone2 = auxPhone img = Image.open(BytesIO(response.content)) img = img.convert('L') img = img.convert('1') img.save("auxphone.gif") auxPhone = 1 except: pass lenfotos = len(url) if len(url) == 0: print("la propiedad no cuenta con fotografias") else: print('total fotos: ' + str(len(url))) for x, u in enumerate(url): u = u.replace('"', '') response = requests.get(u) img = Image.open(BytesIO(response.content)) img.save(str(x) + " foto.jpg") if not interna: imagenDescripcion = Image.new('RGB', (456, 345), color=(255, 255, 255)) d = ImageDraw.Draw(imagenDescripcion) f = ImageFont.truetype('arial.ttf', 12) d.text((0, 0), descripcion, font=f, fill=(0, 0, 0)) imagenDescripcion.save('imagenDescripcion.png') datospro = [] if pro: propsPV = reportes.from_portalinmobiliario(tipo, regionP, [comuna], "venta", True) propsYV = reportes.from_yapo(tipo, regionY, [comuna], True, "venta", True) propsV = propsPV + propsYV # aca deberiamos hacer el GB m2 = reportes.m2prom(tipo, comuna, region) m2V = m2[0] m2A = m2[1] clfHV = ensemble.GradientBoostingRegressor(n_estimators=400, max_depth=5, min_samples_split=2, learning_rate=0.1, loss='huber') #id2,fechapublicacion,fechascrap,operacion,tipo,precio,dormitorios,banos,metrosmin,metrosmax,lat,lon,estacionamientos,link preciosV = [row[5] for row in propsV] trainingV = propsV.copy() for row in trainingV: del row[13] if tipo not in ["departamento", "Casa", "Oficina"]: del row[12] del row[7] if tipo != "local": del row[6] del row[5] del row[4] del row[3] del row[2] del row[1] del row[0] x_train, x_test, y_train, y_test = train_test_split(trainingV, preciosV, test_size=0.10, random_state=2) #obtain scores venta: clfHV.fit(x_train, y_train) print("-----------") print("Score Huber:") print(clfHV.score(x_test, y_test)) scoreV = clfHV.score(x_test, y_test) clfHV.fit(trainingV, preciosV) propsPA = reportes.from_portalinmobiliario(tipo, regionP, [comuna], "arriendo", True) propsYA = reportes.from_yapo(tipo, region, [comuna], True, "arriendo", True) propsA = propsPA + propsYA # aca deberiamos hacer el GB clfHA = ensemble.GradientBoostingRegressor(n_estimators=400, max_depth=5, min_samples_split=2, learning_rate=0.1, loss='huber') #id2,fechapublicacion,fechascrap,operacion,tipo,precio,dormitorios,banos,metrosmin,metrosmax,lat,lon,estacionamientos,link preciosA = [row[5] for row in propsA] trainingA = propsA.copy() for row in trainingA: del row[13] if tipo not in ["departamento", "Casa", "Oficina"]: del row[12] del row[7] if tipo != "local": del row[6] del row[5] del row[4] del row[3] del row[2] del row[1] del row[0] x_train, x_test, y_train, y_test = train_test_split(trainingA, preciosA, test_size=0.10, random_state=2) #obtain scores arriendo: clfHA.fit(x_train, y_train) print("-----------") print("Score Huber:") print(clfHA.score(x_test, y_test)) scoreA = clfHA.score(x_test, y_test) clfHA.fit(trainingA, preciosA) textmail += "Resultados comuna " + str( comuna) + ":\n" + "Score Ventas: " + str( (int(10000 * scoreV)) / 100) + "%\nScore Arriendos: " + str( (int(10000 * scoreA)) / 100) + "%\nPrecio m2 Venta: UF." + str( (int(10 * (m2V / ufn))) / 10) + "\nPrecio m2 Arriendo: $" + str( (int(m2A))) + "\n\n" if tipo not in ["departamento", "Casa", "Oficina"]: prop = [banos, metrosmin, metrosmax, lat, lon] if tipo != "local": prop = [metrosmin, metrosmax, lat, lon] else: prop = [ dormitorios, banos, metrosmin, metrosmax, lat, lon, estacionamientos ] tasacionVenta = clfHV.predict([prop]) tasacionArriendo = clfHA.predict([prop]) precioV = tasacionVenta precioA = tasacionArriendo print("el precio tasado de venta inicial es: " + str(precioV)) print("el precio tasado de arriendo inicial es: " + str(precioA)) if operacion == 'venta': if precioV is None or precioV < 0.1: pro = False financiera = False try: rentaV = ((precioV - precio) / precio) except: pro = False financiera = False text2 = 'No se ha podido realizar tasación' print('fail 1') if precioA is None or precioA < 0.01: pro = False financiera = False try: rentaA = (precioA * 12 / precio) except: pro = False financiera = False text2 = 'No se ha podido realizar tasación' print('fail 2') if pro: if rentaA > 0.2: pro = False financiera = False print('fail 3') if rentaA < 0: pro = False financiera = False if pro: # precio venta tasado datospro.append(precioV) # rentabilidad de venta datospro.append(float(rentaV)) # precio arriendo tasado datospro.append(precioA) # rentabilidad de arriendo datospro.append(float(rentaA)) else: try: precioA = tasacionArriendo except: pro = False text2 = 'No se ha podido realizar tasación' print('fail 72') if pro: if precioA is None or precioA < 0.01: pro = False text2 = 'No se ha podido realizar tasación' print('fail 8') if pro: # precio arriendo tasado datospro.append(precioA) # rentabilidad de arriendo datoscontacto = [] if interna: if sitio == 'portal': try: email, telefono, dueno = reportes.getDatosDueno(str(id)) except: email = "NN" telefono = "NN" dueno = "NN" else: email = "NN" if auxPhone == 1: telefono = auxphone2 else: telefono = "NN" dueno = 'NN' datoscontacto.append(email) datoscontacto.append(telefono) datoscontacto.append(dueno) #Crear PDF if interna: nombrearchivo = "Ficha Propiedad Sitio:" + str(sitio) + " Id:" + str( id) + ".pdf" else: nombrearchivo = "Ficha Propiedad Sitio:" + str(sitio) + ", " + str( operacion) + ", " + str(tipo) + ", " + str(region) + ", " + str( comuna) + ".pdf" print(nombrearchivo) links = [] if financiera: pro = "financiera" print("entering pdfCreator") pdfCreatorFichas.crearPdfFicha(nombrearchivo, id, propiedad, lenfotos, pro, datospro, interna, datoscontacto, regionP, links) print("pdf generado con exito") #Enviar PDF sendmail.sendMail(mail, "", nombrearchivo) #Eliminar del servidor if len(url) == 0: pass else: for x, u in enumerate(url): os.remove(str(x) + " foto.jpg") try: os.remove("auxphone.gif") except: pass if not interna: try: os.remove("imagenDescripcion.png") except: pass os.remove(nombrearchivo) #Retornar exito text = "Ficha creada para la propiedad: " + str( id) + " obtenida del sitio: " + str( sitio) + ", enviada con éxito al correo: " + str(mail) + "." if text2 != '': text = text2 + '. ' + text return (text)
def main(diff_file, new_file, noquery): # Load old data with open(OLD_DATA_FILE, 'r') as f: old_data = json.load(f) # Load new data if noquery: with open(new_file, 'r') as f: new_data = json.load(f) else: # Copy previous backup to old data copyfile(new_file, OLD_DATA_FILE) # Build new backup new_data = query_api(new_file) # Report of activity message = '' # New words items_id = set(old_data['items'].keys()) ^ set(new_data['items'].keys()) if items_id: message += u"<h1>New words added:</h1><ul>" for i in list(items_id): item = new_data['items'][i]['thing']['columns'] if len(item.keys()) == 3: message += u'<li><b>{}</b>({}): {}</li>'.format(item['1']['val'], item['3']['val'], item['2']['val']) elif len(item.keys()) == 5: message += u'<li><b>{}</b>({}): {}</li>'.format(item['1']['val'], item['6']['val'], item['5']['val']) if items_id: message += '</ul>' # words changed if old_data['items'] != new_data['items']: message += u"<h1>Words modified:</h1><ul>" for i in list(set(new_data['items'].keys()) - items_id): col1 = old_data['items'][i]['thing']['columns'] col2 = new_data['items'][i]['thing']['columns'] att1 = old_data['items'][i]['thing']['attributes'] att2 = new_data['items'][i]['thing']['attributes'] mes = '' if att1 != att2 or col1 != col2: if att1 != att2: mes += '<br /><i>Different attributes:</i>{}'.format(BLOCKQUOTE) mes += '<br />'.join([u' → '.join([att1[k]['val'], att2[k]['val']]) for k in att1.keys() if att1[k]['val'] != att2[k]['val']]) mes += '</blockquote>' if col1 != col2: for k in col1.keys(): if col1[k]['alts'] != col2[k]['alts']: mes += '<br /><i>New alts:</i> ' mes += ', '.join(set([d['val'] for d in col1[k]['alts']]) .symmetric_difference( set([d['val'] for d in col2[k]['alts']]))) if col1[k]['val'] != col2[k]['val']: mes += u'<br /><i>Different val:</i> {}{}→ {}'\ '</blockquote>'.format(col1[k]['val'], BLOCKQUOTE, col2[k]['val']) if mes: message += u'<li><b>{}</b> ({}):{}</li>'.format( col1['1']['val'], i, mes) if old_data['items'] != new_data['items']: message += '</ul>' sendMail(message)
#!/usr/bin/env python # coding = utf-8 import sys, os import socket import sendmail path = sys.path[0] #print(path) localIP = socket.gethostbyname(socket.gethostname()) filename = path + "/latestip.txt" # if file does not exist, create it! if not os.path.exists(filename): open(filename, 'a').close() #read ip address with open(filename, 'r') as f: latestip = f.read() if localIP != latestip: with open(filename, 'w') as f: f.write(localIP) sendmail.sendMail("Newest IP: {0}".format(localIP), "Pi IP changed")