예제 #1
0
def pull(config_file):
    # TODO 日志重复写入问题,待解决(重复写入也可以)
    # TODO git模块增加debug模式
    try:
        global logger
        logger = log.Logger(log_name="compile.log", logger="test").get_log()
        global code_path
        code_path = func.config_from_json(config_file,
                                          "run_config")["sourcecode_path"]
        global flags
        flags = []
    except Exception, e:
        logger.error("read config error @git_pull")
        send_email.send_email()
예제 #2
0
파일: views.py 프로젝트: kebo24/Django-shop
    def post(self, request):
        register_form = RegisterForm(request.POST)
        if register_form.is_valid():
            username = request.POST.get('email', '')
            # 判断邮箱是否存在
            if UserProfile.objects.filter(email=username):
                return render(request, 'users/register.html', {
                    'register_form': register_form,
                    'msg': '邮箱已存在'
                })

            # from django.contrib.auth.models import User
            # user = User.object.create_user('bin', '*****@*****.**', 'password')
            # user.save()
            # 创建新用户
            user = UserProfile()
            user.username = username
            user.email = user.username
            user.password = make_password(request.POST.get('password',
                                                           ''))  # 对密码进行加密
            user.is_active = False  # 新用户是未激活的

            # 发送激活邮件
            if (send_email(username, 'register')):
                user.save()
                return render(request, 'users/login.html',
                              {'msg': '请前往邮箱进行邮箱认证'})

            return render(request, 'users/login.html', {'msg': '激活邮件发送失败'})
        else:
            return render(request, 'users/register.html',
                          {'register_form': register_form})
예제 #3
0
    def post(self, request):
        render_data = dict()
        forget_form = ForgetForm(request.POST)
        email = request.POST.get('email', None)
        render_data['forget_form'] = forget_form
        render_data['email'] = email if email else ''
        if forget_form.is_valid():
            user_profile = UserProfile.objects.filter(email=email,
                                                      is_active=True)
            if user_profile:
                send_status = send_email(email_address=email,
                                         email_type='forget')
                if send_status:

                    # 写入发送找回邮件消息
                    person_message = UserMessage()
                    person_message.user = user_profile
                    person_message.message = '你已发送找回密码邮件(email)哦'.format(
                        email=email)
                    person_message.save()

                    # 自动跳转到邮箱登录页面
                    email_url = get_mail_url(email=email)
                    return redirect(to=email_url)
            else:
                render_data['email_error'] = '该邮箱未注册'
                return render(request, 'user/forgetpwd.html', render_data)
        else:
            render_data['email_error'] = ''
            return render(request, 'user/forgetpwd.html', render_data)
예제 #4
0
def main():
    script_mode, config_file, output_path, debug_switch = func.get_parser()
    # if func.config_from_json(config_file, 'run_config')["compile code"] == "ON":
    #     if mygit.pull(config_file):
    #         send_email.send_email(config_file, 'msg')
    #         os.chdir(sys.path[0])
    #         cases_set_dict = func.config_from_json(config_file, "cases_config")
    #         for k in cases_set_dict:
    #             log_file_name = ''.join([time.strftime('%Y-%m-%d_%H_%M_%S', time.localtime(
    #                 time.time())), '_', os.path.basename(cases_set_dict[k][0]), '.log'])
    #             logger = log.Logger(log_name=log_file_name, logger=k).get_log()
    #             coloredlogs.install(level='DEBUG', logger=logger)
    #             date_now = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
    #             output_dir = os.path.join(output_path,
    #                                       date_now + "_debug_" + func.config_from_json(config_file, "run_config")[
    #                                           "owner"] + "_" + func.config_from_json(config_file, "run_config")[
    #                                           "branch"] + "_" + k)
    #             run_SLAM_in_debug.main_flow(
    #                 cases_set_dict[k], logger, script_mode, config_file, output_path, debug_switch, output_dir)
    #     else:
    #         print "没有更新,没有触发自动测试"
    # else:
    os.chdir(sys.path[0])
    cases_set_dict = func.config_from_json(config_file, "cases_config")
    for k in cases_set_dict:
        os.chdir(sys.path[0])
        log_file_name = ''.join([
            time.strftime('%Y-%m-%d_%H_%M_%S', time.localtime(time.time())),
            '_',
            os.path.basename(cases_set_dict[k][0]), '.log'
        ])
        logger = log.Logger(log_name=log_file_name, logger=k).get_log()
        coloredlogs.install(level='DEBUG', logger=logger)
        date_now = datetime.datetime.now().strftime('%Y%m%d_%H%M%S')
        output_dir = os.path.join(
            output_path, date_now + "_debug_" +
            func.config_from_json(config_file, "run_config")["owner"] + "_" +
            func.config_from_json(config_file, "run_config")["branch"] + "_" +
            k)
        run_SLAM_in_debug.main_flow(cases_set_dict[k], logger, script_mode,
                                    config_file, output_path, debug_switch,
                                    output_dir)
    send_email.send_email(config_file, "msg", func.get_ip())
예제 #5
0
파일: views.py 프로젝트: kebo24/Django-shop
    def get(self, request):
        email = request.GET.get('email', '')
        # 判断邮箱是否存在
        if UserProfile.objects.filter(email=email):
            return HttpResponse('{"email": "邮箱已被注册"}',
                                content_type='application/json')

        if send_email(email, 'change'):
            return HttpResponse('{"status": "success", "msg": "验证码发送成功"}',
                                content_type='application/json')

        return HttpResponse('{"msg": "验证码发送失败"}',
                            content_type='application/json')
예제 #6
0
파일: views.py 프로젝트: kebo24/Django-shop
 def post(self, request):
     forget_pwd_form = ForgetPwdForm(request.POST)
     if forget_pwd_form.is_valid():
         email = request.POST.get('email', '')
         user = UserProfile.objects.filter(email=email)
         if user:
             if (send_email(email, 'forget')):  # send_email发送成功会返回 1
                 return render(request, 'users/forgetpwd.html',
                               {'msg': '邮件发送成功,请到邮箱确认'})
             else:
                 return render(request, 'users/forgetpwd.html',
                               {'msg': '邮件发送失败,请重试'})
         else:
             return render(request, 'users/forgetpwd.html', {
                 'forget_pwd_form': forget_pwd_form,
                 'msg': '邮箱不存在'
             })
     else:
         return render(request, 'users/forgetpwd.html',
                       {'forget_pwd_form': forget_pwd_form})
예제 #7
0
    def post(self, request):
        # 返回渲染模版数据字典
        render_data = dict()
        register_form = RegisterForm(request.POST)
        user_email = request.POST.get('email', None)
        user_pwd = request.POST.get('password', None)
        render_data['register_form'] = register_form
        if register_form.is_valid():
            # 判断这个邮箱是否注册
            if UserProfile.objects.filter(email=user_email):
                render_data['email_error'] = '该邮箱已经注册'
                return render(request, 'user/register.html', render_data)
            # 通过send_status判断是否发送成功判断这个邮箱是否存在
            send_status = send_email(email_address=user_email,
                                     email_type='register')
            if send_status:
                # 把注册的用户is_active为未激活状态
                user_profile = UserProfile()
                user_profile.username = user_email
                user_profile.email = user_email
                user_profile.password = make_password(user_pwd)
                user_profile.is_active = 0
                user_profile.save()

                # 写入消息
                person_message = UserMessage()
                person_message.user = user_profile
                person_message.message = '{username} 您好啊,欢迎注册!'.format(
                    username=user_email)
                person_message.save()

                # 跳转到登录邮箱验证页面?或者跳转到登录页面
                email_url = get_mail_url(email=user_email)
                return redirect(to=email_url)
            else:
                render_data['email_error'] = '该邮箱不存在'
                return render(request, 'user/register.html', render_data)
        else:
            render_data['email_error'] = ''
            return render(request, 'user/register.html', render_data)
예제 #8
0
 def get(self, request):
     render_data = dict()
     email = request.GET.get('email', '')
     if email:
         # 检查邮箱是否注册过
         if UserProfile.objects.filter(email=email):
             render_data['email'] = '邮箱已经注册'
             return HttpResponse(json.dumps(render_data),
                                 content_type='application/json')
         # 发邮件
         send_status = send_email(email_address=email, email_type='update')
         if send_status:
             # 写入消息
             message = UserMessage()
             message.user = request.user.id
             message.message = '哇,人家已经把你验证邮件发送出去了哦'
             message.save()
             render_data['email'] = '已发送邮箱验证码'
             return HttpResponse(json.dumps(render_data),
                                 content_type='application/json')
     else:
         render_data['email'] = '邮箱输入错误'
         return HttpResponse(json.dumps(render_data),
                             content_type='application/json')
예제 #9
0
def main():
    try:
        predict_or_test = "test"
        print(sys.argv[1])

        # 读取数据库数据
        psql_tools = PSQLToos()
        prediction_data = psql_tools.get_data(True)

        # 本地读取数据
        # prediction_data = pd.read_csv('treb_toronto_11.csv')

        # 数据处理
        print('prediction data shape', prediction_data.shape)
        total_data_number = prediction_data.shape[0]
        # auto_ml只需要处理一次,keras需要处理两次
        dp = DataProcess()
        prediction_data_after_process = dp.data_process(
            prediction_data, predict_or_test)
        # 然后保存与处理过后的文件
        origin_data = prediction_data_after_process.reset_index(drop=True)
        # 去掉daysOnMarket 和不用的预测特征
        prediction_data_after_process = prediction_data_after_process.drop(
            columns=[
                'daysOnMarket', 'estateMasterId', 'realtorDataId',
                'realtorHistoryId', 'mlsNumber'
            ])
        print('prediction_data_after_process shape:',
              prediction_data_after_process.shape)
        prediction_data_number = prediction_data_after_process.shape[0]
        my_prediciton = MyPrediction()
        # auto_ml 预测
        if sys.argv[1] == 'auto_ml':
            result_auto_ml = my_prediciton.my_predict_auto_ml(
                prediction_data_after_process)
            result_auto_ml_df = transform_data_to_dataframe(
                result_auto_ml, 'predictions')
            print(result_auto_ml_df.head())
            # result_auto_ml_df.to_csv('./auto_ml_result.csv')
            # 保存到本地数据库
            save_data_to_database(result_auto_ml_df, origin_data, 'ch_test',
                                  [])
            # 保存到产品数据库
            # 。。。

            # 计算比例
            merge_prediction_orgin_auto_ml = pd.concat(
                (origin_data, result_auto_ml_df), axis=1)
            # compute_ratio(merge_prediction_orgin_auto_ml, 'predictions')

        # keras 预测
        if sys.argv[1] == 'keras':
            keras_process = dp.keras_data_process(
                prediction_data_after_process)
            result_keras = my_prediciton.my_predict_keras(keras_process)
            # 转化成DataFrame格式
            result_keras_df = transform_data_to_dataframe(
                result_keras, 'predictions')
            print(result_keras_df.head())
            # 保存到本地数据库:
            save_data_to_database(result_keras_df, origin_data, 'ch_test', [])
            # 保存到产品数据库
            # 。。。。

            # 计算比例
            merge_prediction_origin_keras = pd.concat(
                (origin_data, result_keras_df), axis=1)
            # compute_ratio(merge_prediction_origin_keras, 'predictions')

        send_email(
            "AI预测",
            '总共查询:{0}条数据,使用{1}方法预测了:{2}'.format(total_data_number, sys.argv[1],
                                                prediction_data_number))
    except Exception as e:
        print(e)
        send_email("AI预测", '预测失败:{}'.format(e))