Beispiel #1
0
def run():
    try:
        if date.today().weekday() not in (5, 6):
            logger.info("Starting ichimoku screener")
            start_time = datetime.now()
            logger.info("Filter Settings: {}".format(_get_filter_settings()))
            ichi_dict = (analyze_ichimoku())
            try:
                pickle.dump(
                    ichi_dict,
                    open(path.join(pickle_dir, pickle_file_name), 'wb'))
            except:
                logger.error('Pickle could not be saved')

            send_email(ichi_dict)
            end_time = datetime.now()
            logger.info(
                "Finished screening. Total time: {}".format(end_time -
                                                            start_time))
        else:
            logger.info("Not running screener on {}".format(
                date.today().isoformat()))
    except Exception as e:
        logger.info("Unpected Exception: {}".format(e))
def up(subject):
    # % 数据部分 %
    data = {
        "ymtys":
        "0",  # 一码通颜色
        "sfzx":
        "1",  # 是否在校
        "tw":
        "2",  # 体温范围:36.5°C~36.9°C
        "area":
        bytes(Settings.province, 'utf-8') + b'\x20' +
        bytes(Settings.city, 'utf-8') + b'\x20' +
        bytes(Settings.area, 'utf-8'),  # 省市区
        "city":
        bytes(Settings.city, 'utf-8'),  # 市
        "province":
        bytes(Settings.province, 'utf-8'),  # 省
        "address":
        bytes(Settings.address, 'utf-8'),  # 具体地点
        "sfcyglq":
        "0",  # 是否处于隔离期
        "sfyzz":
        "0",  # 是否出现乏力、干咳、呼吸困难等症状
        "qtqk":
        "",  # 其他情况
        "askforleave":
        "0"
    }

    result_main = conn.post(
        url="https://xxcapp.xidian.edu.cn/xisuncov/wap/open-report/save",
        data=data  # 填写数据
    )

    # @ 错误2:数据发送错误 @
    if result_main.status_code != 200:
        print("数据发送错误,错误代码:", result_main.status_code)
        send_email(
            subject,
            MainFunc.BJT + '\n' + '数据发送错误,错误代码:' + result_main.status_code)
        exit()
    else:
        try:
            # @ 程序完成 @
            result_json = json.loads(result_main.text)
            print(MainFunc.BJT + '\n程序完成。\n' + str(result_json['e']) + '-' +
                  result_json['m'])
            send_email(
                subject, MainFunc.BJT + '\n程序完成。\n' + str(result_json['e']) +
                '-' + result_json['m'])
        except json.decoder.JSONDecodeError:
            print('晨午晚检填报程序数据发送部分出现异常。请检查是否按照步骤进行配置。')
            send_email(subject,
                       MainFunc.BJT + '晨午晚检填报程序数据发送部分出现异常。请检查是否按照步骤进行配置。')
Beispiel #3
0
def report():
    # % 数据部分 %
    data = {
        "sfzx": "0",  # 是否在校:否0是1
        "sfzgn": "1",  # 所在地点:中国大陆为1
        "area": bytes(Settings.province, 'utf-8') + b'\x20' + bytes(Settings.city, 'utf-8') + b'\x20' + bytes(
            Settings.area,
            'utf-8'),  # 省市区
        "city": bytes(Settings.city, 'utf-8'),  # 市
        "province": bytes(Settings.province, 'utf-8'),  # 省
        "address": bytes(Settings.address, 'utf-8'),  # 具体地点
        "zgfxdq": "0",  # 是否在中高风险地区:否0是1
        "tw": "3",  # 体温范围:36.5°C~36.9°C
        "sfcxtz": "0",  # 是否出现症状:否0是1
        "sfjcbh": "0",  # 是否接触接触无症状感染/疑似/确诊人群:否0是1
        "mjry": "0",  # 是否接触密接人员:否0是1
        "csmjry": "0",  # 是否去过疫情场所:否0是1
        "sfcyglq": "0",  # 是否处于隔离期:否0是1
        "sfjcjwry": "0",  # 是否接触境外人员:否0是1
        "sfcxzysx": "0",  # 是否有特别情况:否0是1
        "multiText": "",  # 其他情况
    }

    result_main = conn.post(
        url="https://xxcapp.xidian.edu.cn/ncov/wap/default/save",
        data=data  # 填写数据
    )

    # @ 错误2:数据发送错误 @
    if result_main.status_code != 200:
        print("数据发送错误,错误代码:", result_main.status_code)
        send_email('疫情通', MainFunc.BJT + '\n' + '数据发送错误,错误代码:' + result_main.status_code)
        exit()
    else:
        try:
            # @ 程序完成 @
            result_json = json.loads(result_main.text)
            print(MainFunc.BJT + '\n程序完成。\n' + str(result_json['e']) + '-' + result_json['m'])
            send_email('疫情通', MainFunc.BJT + '\n程序完成。\n' + str(result_json['e']) + '-' + result_json['m'])
        except json.decoder.JSONDecodeError:
            print('疫情通填报程序数据发送部分出现异常。请检查是否按照步骤进行配置。')
            send_email('疫情通', MainFunc.BJT + '疫情通填报程序数据发送部分出现异常。请检查是否按照步骤进行配置。')
 def runCMD(self, cmd):
     cmdDict = eval(cmd)
     command = cmdDict['CMD']
     if command == 'login':
         result = self.login_user(cmdDict['USERNAME'], cmdDict['PASSWORD'])
         if result['RESULT']:
             outputData = '{},{},{}\n'.format(result['ID'], result['FIRST'],
                                              result['LAST'])
             self.log_event(command, result['ID'])
             send_email(result['EMAIL'], 'Login Notice',
                        'You have loged in to the system.')
             self.connection.sendall(outputData.encode())
         elif result['REASON'] == 'invalid-password':
             self.log_event(command + '-Failed', result['ID'])
             send_email(
                 result['EMAIL'], 'Login Attempt Notice',
                 'Your account was trying to login with a wrong password. Is that you?'
             )
             self.connection.sendall(b'Invalid Password\n')
         else:
             self.connection.sendall(b'Invalid Username\n')
     elif command == 'create':
         result = self.create_user(
             cmdDict['USERNAME'],
             self.encrypt_password(cmdDict['PASSWORD']),
             cmdDict['FIRST_NAME'], cmdDict['LAST_NAME'], cmdDict['EMAIL'])
         if result == 0:
             send_email(cmdDict['EMAIL'],
                        'Created New Account on House IoT',
                        'Thank you for creating account in House IoT.')
             self.connection.sendall(b'User created\n')
         elif result == 1:
             self.connection.sendall(b'Failed to create user\n')
         else:
             self.connection.sendall(b'Username is used\n')
     elif command == 'run':
         cmdRec = command + '-' + cmdDict['OP']
         self.log_event(cmdRec, cmdDict['ID'])
         self.connection.sendall(b'Command Ran\n')
     else:
         self.connection.sendall(b'Invalid Command Entered...\n')
if __name__ == '__main__':
    with open(
            os.path.dirname(os.path.realpath(__file__)) +
            '/../FBM Utility/database_info.json') as f:
        database_info = json.load(f)

    db = mysql.connector.connect(**database_info)
    cur = db.cursor()

    cur.execute("SELECT * FROM report_emails")
    email_list = cur.fetchall()
    email_list = tuple(i[1] for i in email_list)

    now = datetime.datetime.now()
    # Reset to first of last month
    rdate = datetime.datetime(now.year, now.month,
                              1) + relativedelta(months=-1)

    report_filename = WriteExcelSheet(os.path.abspath(
        "../FBM Utility/out/Report {}-{}".format(rdate.month, rdate.year)),
                                      month=rdate.month,
                                      year=rdate.year)

    for email in email_list:
        send_email(
            email,
            "Matthews Crossing Report for {}".format(rdate.strftime("%Y-%m")),
            email_body, report_filename)

    os.remove(report_filename)
Beispiel #6
0
        url='https://xxcapp.xidian.edu.cn/uc/wap/login/check',
        # username 学号,password 统一登录密码
        data={
            'username': Settings.stu_no,
            'password': Settings.stu_pass
        })
    login_json = json.loads(result_login.text)
    print(login_json['m'])
except requests.exceptions.ConnectionError:
    print("网络连接中断,请检查网络连接。")
    exit()

# @ 错误1:登录错误 @
if result_login.status_code != 200:
    print('登录连接错误,HTTP状态码:', result_login.status_code)
    send_email('登录错误',
               BJT + '\n' + '登录连接错误,HTTP状态码:' + result_login.status_code)
    exit()
else:
    try:
        if login_json['e'] != 0:
            print('登录错误,错误信息:' + str(login_json['e']) + '-' + login_json['m'])
            send_email(
                '登录错误', BJT + '\n' + '登录错误,错误信息:' + str(login_json['e']) +
                '-' + login_json['m'])
            exit()
        else:
            print('登录成功。')
    except json.decoder.JSONDecodeError:
        print('疫情通及晨午晚检填报程序登录部分出现异常。请检查是否按照步骤进行配置。')
        send_email('填报程序出现异常', BJT + '疫情通及晨午晚检填报程序登录部分出现异常。请检查是否按照步骤进行配置。')
        exit()