예제 #1
0
파일: main.py 프로젝트: midgithub/Quant2
def job():
    """
    执行当日任务
    :return:
    """
    try:
        db_data.add_money_flow_today()
    except Exception as err:
        print(err)

    # 当日股票现金流统计信息
    try:
        db_data.add_money_flow_statistic(today=True)
    except Exception as err:
        print(err)

    try:
        db_data.add_margin_info(today=True)
    except Exception as err:
        print(err)

    try:
        db_data.hsgt_add(today=True)
    except Exception as err:
        print(err)

    dataView.save_trade_figure()
    my_mail.send_mail()
def GetGlobalDatabase(export_arg,mail,number_base) :
	fileid=time.time()
	fileid=('%.*f' % (0, fileid))[:-1]
	export_to_xml.export(export_arg,fileid,number_base)
	#keywords=getkeyword.get()
	keywords=["all"]
	my_mail.send_mail(mail,keywords,fileid,2)
예제 #3
0
 def push_to_prd(self):
     if self.trans_files == []:
         logger.warn('no data to push')
         return False
     ip = envi['prd_sftp_ip']
     port = envi['prd_sftp_port']
     usr = envi['prd_sftp_user']
     pwd = envi['prd_sftp_pass']
     src = envi['data_src_name']
     rdir = envi['prd_data_dir']
     try:
         target = paramiko.Transport((ip, port))
         target.connect(username=usr, password=pwd)
         sftp = paramiko.SFTPClient.from_transport(target)
         # transfar via sftp put
         for f in self.trans_files:
             sftp.put(self.ldir + f, rdir + f)
         logger.info('pushing to prd finished')
     except Exception as e:
         logger.error(str(e))
         send_mail(src + u'自动同步失败', str(e))
         return False
     target.close()
     send_mail(src + u'自动同步成功', u'请使用md5文件校验数据文件*.tar.gz')
     return True
예제 #4
0
    def pull_from_cmm(self):
        ip = envi['cmm_sftp_ip']
        port = envi['cmm_sftp_port']
        usr = envi['cmm_sftp_user']
        pwd = envi['cmm_sftp_pass']
        src = envi['data_src_name']
        p = envi['cmm_data_pattern']
        try:
            target = paramiko.Transport((ip, port))
            target.connect(username=usr, password=pwd)
            sftp = paramiko.SFTPClient.from_transport(target)
            logger.debug("connect to cmm's sftp server")
            # to find files for transfaring
            for rdir in envi['cmm_data_dir']:
                for f in sftp.listdir(rdir):
                    if f not in self.loc_files and re.match(p, f) != None:
                        self.trans_files.append(f)
                        # transfar via sftp get
                        sftp.get(rdir + f, self.ldir + f)
                        logger.debug('file: <' + str(f) + '> transfared')

            if self.trans_files == []:
                logger.warn('no data to pull')
                send_mail(src + u'未更新', u'请咨询数据提供技术人员')
            else:
                logger.info('pulling finished: ' + str(self.trans_files))
        except Exception as e:
            logger.error(str(e))
            send_mail(src + u'自动同步失败', str(e))
            return False
        target.close()
        return True
def Scrap(mail,export_arg,keywords,databases):
	for i in databases : 
		if i=='f':
			print "googo"
			scrap_espace_fr.scrap_multi_keyword(keywords,"scrap")
		elif i =='w':
			scrap_espace_word.scrap_multi_keyword(keywords,"scrap")
		elif i=='a':
			scrap_all_espace.scrap_multi_keyword(keywords,data_all,"scrap")
	#export_to_xml.export(export_arg,1)
	my_mail.send_mail(mail,keywords,1)
def Scrap(mail,export_arg,keywords,databases,number_base):

	if not os.path.exists("./temp/Base/Base_brevet_"+str(number_base)+".db"):
		create_table.create_base(number_base)
		print "create new"
	for i in databases : 
		if i=='f':
			print "googo"
			scrap_espace_fr.scrap_multi_keyword(keywords,"scrap",number_base)
		elif i =='w':
			scrap_espace_word.scrap_multi_keyword(keywords,"scrap",number_base)
		elif i=='a':
			scrap_all_espace.scrap_multi_keyword(keywords,data_all,"scrap",number_base)
	fileid=time.time()
        fileid=('%.*f' % (0, fileid))[:-1]
	export_to_xml.export(export_arg,fileid,number_base)
	my_mail.send_mail(mail,keywords,fileid,1)
예제 #7
0
def my_alert(msg, tdes):

   #1.日志记录到link.log和syslog服务器
   link_logger.warn(msg)

   if envi['slog_server'] != '':
      syslog.error(msg.encode('gbk'))


   #2.发送邮件
   timestr = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime())
   t_hour = time.localtime().tm_hour
   phone    = []     #获取手机号码列表
   mail_int = []     #获取内部邮箱列表
   mail_ext = []     #获取外部邮箱列表
   detail = ''       #线路详细信息
   re = ()

   #获取该线路的单独告警邮箱和手机号码
   sql = "select mail1,mail2,phone,city,pri from target where tdes='%s'" % tdes
   (m1, m2, p, city, pri) = xgetone(sql)
   if m1 != '' and m1 != None:
      temp = (str(m1).strip(';')).split(';')
      mail_int.extend(temp)
   if m2 != '' and m2 != None:
      temp = (str(m2).strip(';')).split(';')
      mail_ext.extend(temp)
   if p != '' and p != None:
      temp = (str(p).strip(';')).split(';')
      phone.extend(temp)

   #获取用户所在城市的告警邮箱和手机号码
   sql="select mail1, mail2, phone from user where city='%s'" % city
   if xgetall(sql) != None:
      mlists = xgetall(sql)
      for mlist in mlists:
         if mlist[0] != '' and mlist[0] != None:
            mail1 = (str(mlist[0]).strip(';')).split(';')
            mail_int.extend(mail1)
         if mlist[1] != '' and mlist[1] != None:
            mail2 = (str(mlist[1]).strip(';')).split(';')
            mail_ext.extend(mail2)
         if mlist[2] != '' and mlist[2] != None:
            tmp_phone = (str(mlist[2]).strip(';')).split(';')
            phone.extend(tmp_phone)
         
   if mail_int != [] or mail_ext != []:
      sql = "select * from detail where tdes='%s'" % tdes
      if xgetone(sql) != None:
         re = xgetone(sql)
         #
         detail = detail + u"线路编号:" + re[1] + "\n"
         detail = detail + u"报障电话:" + re[2] + "\n"
         detail = detail + u"对端联系:" + re[4] + "\n"
         detail = detail + u"对端地址:" + re[3] + "\n"
         detail = detail + u"应用名称:" + re[5] + "\n"
         detail = detail + u"应用联系:" + re[6] + "\n"
         detail = detail + u"线路资费:" + re[7] + "\n"
         detail = detail + u"线路所属:" + re[8] + "\n"
         detail = detail + u"其他信息:" + re[9] + "\n"

   #print mail_int
   #print mail_ext
   #print phone
   if mail_int != []:
      send_mail(timestr+msg, detail, mail_int)
   if mail_ext != []:
      if (pri > 1 or (t_hour>6 and t_hour<21)):
         send_mail_ext(timestr+msg, detail, mail_ext)

   #print phone
   #3.发送到短信平台
   if envi['ftp_server'] != '' and phone != []:
      if (pri > 1 or (t_hour>6 and t_hour<21)):
         ftp_alert(timestr+msg, phone)

   return
예제 #8
0
if __name__ == "__main__":
    # typical ussage: python app.py -u "my name" -n "mynetid"
    PARSER = argparse.ArgumentParser(
        description="Python test script. Save a message")
    PARSER.add_argument('-u', help="Give me a username")
    PARSER.add_argument('-n', help="Give me a netid")
    PARSER.add_argument('-email', help="t or true to send email")
    ARGS = PARSER.parse_args()
    UNAME = ARGS.u if ARGS.u else "John Doe"
    UNETID = ARGS.n if ARGS.n else "jd123"

    LOGGER.debug("starting App")
    APP = App()

    LOGGER.debug("setting user %s with netid %s", UNAME, UNETID)
    APP.set_row(UNAME, UNETID)

    RET = APP.get_row()
    LOGGER.info("fetched message: %s", RET)

    APP.close()
    if ARGS.email and (ARGS.email.lower() == "t"
                       or ARGS.email.lower() == "true"):
        #send email with attached application log
        my_mail.send_mail(
            settings.EMAIL_FROM, settings.EMAIL_TO, "succesful app run",
            "see attached logs of example postgres db connection",
            settings.EMAIL_HOST_SERVER, settings.EMAIL_PORT,
            settings.EMAIL_PWORD, settings.LOG_FILE)
    print("finished with success")