def ftpBaglanti(filename): host = 'xxxxxxx' user = '******' passw = 'xxxxxxx' try: ftp = ftplib.FTP(host, user, passw) print '*** FTP sunucuya bağlandı' except: sonuc = 'FTP error' print sonuc defMandrillRoot(sonuc, sonuc) sys.exit() try: #print ftp.retrlines('LIST') # ftp sunucudaki dosyanın tarihi datetimeftp = ftp.sendcmd('MDTM ' + filename) # makinedeki dosyanın tarihi datetimepc = os.path.getmtime('/home/python/xxxxxxx/fiyat_guncel/' + filename) modifiedTimeFtp = datetime.strptime( datetimeftp[4:], "%Y%m%d%H%M%S").strftime("%d %b %Y %H:%M:%S") modifiedTimePc = datetime.fromtimestamp(datetimepc).strftime( "%d %b %Y %H:%M:%S") if modifiedTimeFtp > modifiedTimePc: #print modifiedTimeFtp #print modifiedTimePc #print "FTP deki dosya yenidir" # Sunucudaki dosyayı download ediyoruz localfile = open( '/home/python/xxxxxxxxxx/fiyat_guncel/' + filename, 'wb') ftp.retrbinary('RETR ' + filename, localfile.write, 1024) localfile.close() else: #print modifiedTimeFtp #print modifiedTimePc #print "Makinedeki deki dosya yenidir" sys.exit() print '*** Dosya bulundu : "%s"' % filename except: print '*** İşlem durdu. Dizindeki dosya tarihi büyük "%s"' % filename ftp.quit() sys.exit() else: print '*** Dosya indirildi : "%s"' % filename ftp.quit()
def ftpBaglanti(filename): host = "xxxxxxx" user = "******" passw = "xxxxxxx" try: ftp = ftplib.FTP(host, user, passw) print "*** FTP sunucuya bağlandı" except: sonuc = "FTP error" print sonuc defMandrillRoot(sonuc, sonuc) sys.exit() try: # print ftp.retrlines('LIST') # ftp sunucudaki dosyanın tarihi datetimeftp = ftp.sendcmd("MDTM " + filename) # makinedeki dosyanın tarihi datetimepc = os.path.getmtime("/home/python/xxxxxxx/fiyat_guncel/" + filename) modifiedTimeFtp = datetime.strptime(datetimeftp[4:], "%Y%m%d%H%M%S").strftime("%d %b %Y %H:%M:%S") modifiedTimePc = datetime.fromtimestamp(datetimepc).strftime("%d %b %Y %H:%M:%S") if modifiedTimeFtp > modifiedTimePc: # print modifiedTimeFtp # print modifiedTimePc # print "FTP deki dosya yenidir" # Sunucudaki dosyayı download ediyoruz localfile = open("/home/python/xxxxxxxxxx/fiyat_guncel/" + filename, "wb") ftp.retrbinary("RETR " + filename, localfile.write, 1024) localfile.close() else: # print modifiedTimeFtp # print modifiedTimePc # print "Makinedeki deki dosya yenidir" sys.exit() print '*** Dosya bulundu : "%s"' % filename except: print '*** İşlem durdu. Dizindeki dosya tarihi büyük "%s"' % filename ftp.quit() sys.exit() else: print '*** Dosya indirildi : "%s"' % filename ftp.quit()
worksheet.write_formula('D15', '=C15/B15', cell_format_3) # Toplama worksheet.write_formula('D16', '=C16/B16', cell_format_3) # Insert an image. worksheet.insert_image('B19', '%slogo.png' %(filenameDirectory)) # Dosyaya yazdık. Şimdi kapatma zamanı. workbook.close() ###################################################################### # Execeli Mandrill üzerinden mail atabilmemiz için dosyayı base64’e # çevirmemiz gerekiyor. http://tr.wikipedia.org/wiki/Base64 ###################################################################### base64.encode(open('%s%s' %(filenameDirectory,filenameReport)), open('%sout.b64' %(filenameDirectory), "w")) # Oluşturduğumuz base64 ü açıp content değerine atıyoruz. content = open('%sout.b64' %(filenameDirectory)).read() # Maili gönderiyoruz. defMandrill.defMandrillUser(content) defMandrill.defMandrillRoot(content)
print sonuc def mailAt(): txt = '' for row in table: txt += "%s - %s TL - %s<br>" % (int(row[0]),row[1],int(row[2])) return txt html = """%s<br> -----------------------------------------------------------------<p> %s<p> Saygılarımızla.<p> <p><p><hr> <small> <b>Açıklama</b><br> Bu rapor otomatik olarak oluşturulmuştur.<br> xxxxxxxxxx.com sitesindeki dataların güncellenmesi 1 (bir) saat içinde gerçekleşir. </small> """ %(sonuc,mailAt()) defMandrill.defMandrillUser(html,sonuc) defMandrill.defMandrillRoot(html,sonuc)
defMySql.baglanti(int(row[0]), row[1], int(row[2])) print "%s - %s - %s" % (int(row[0]), row[1], int(row[2])) except: pass sonuc = '%s satırdan uygun olanlar update edildi.' % (len(table)) print sonuc def mailAt(): txt = '' for row in table: txt += "%s - %s TL - %s<br>" % (int(row[0]), row[1], int(row[2])) return txt html = """%s<br> -----------------------------------------------------------------<p> %s<p> Saygılarımızla.<p> <p><p><hr> <small> <b>Açıklama</b><br> Bu rapor otomatik olarak oluşturulmuştur.<br> xxxxxxxxxx.com sitesindeki dataların güncellenmesi 1 (bir) saat içinde gerçekleşir. </small> """ % (sonuc, mailAt()) defMandrill.defMandrillUser(html, sonuc) defMandrill.defMandrillRoot(html, sonuc)