Example #1
0
    def login_click(self, event):

        # 判断是否输入用户名和密码
        username_val = self.username.GetValue()
        password_val = self.password.GetValue()
        if not username_val:
            wx.MessageBox(u"请输入用户名")
            self.username.SetFocus()
            return
        if not password_val:
            wx.MessageBox(u"请输入密码")
            self.password.SetFocus()
            return

        if not self.pos:
            wx.MessageBox(u"请选择验证码")
            return

        # 让当前窗口焦点聚焦在验证码上
        self.codeBitMap.SetFocus()
        self.refresh_btn.Disable()
        self.login_btn.Disable()
        self.login_btn.SetLabel(u'准备校验验证码...')

        # 调用12306登录
        Common.startWorkFunc(self.to_12306_login,
                             self.login_success,
                             wargs=(username_val, password_val))
def getAllKindProductMaps():
    productMaps = {}
    day = 2
    pathdir = PRODUCT_DICT_PATH % Common.getPreDay(day)
    while not os.path.exists(pathdir):
        day = day + 1
        print "get pre %d day product info." % (day)
        pathdir = PRODUCT_DICT_PATH % Common.getPreDay(day)
    if os.path.exists(pathdir):
        files = os.listdir(pathdir)
        for productFile in files:
            file = open(os.path.join(pathdir, productFile), 'r')
            # print productFile + " ----" + productFile.split('.')[0]
            productMaps[productFile.split('.')[0]] = json.load(file)
            # break # for test
    else:
        print str(productMaps)
    return productMaps
def saveProduct(category, content):
    print "saving..."
    pathdir = PRODUCT_DICT_PATH % Common.getTimeDayStr()
    if not os.path.exists(pathdir):
        os.makedirs(pathdir)
    saveFile = pathdir + str(category) + ".json"
    file = open(saveFile, 'w')
    json.dump(content, file)
    # saveStr = "\n".join(str(app) for app in  content)
    # file.writelines(saveStr)
    file.close()
    print "saved"
Example #4
0
    def start():
        # Get log file
        log_file = "{}/{}".format(Common.get_proj_root_path(),
                                  "res/conf/log.ini")
        # Get configuration file
        if len(sys.argv) > 1:
            config_file = sys.argv[1]
        else:
            config_file = "{}/{}".format(Common.get_proj_root_path(),
                                         "res/conf/conf.ini")

        # Validation
        try:
            Main.__validate((3, 7), log_file, config_file)
        except Exception as e:
            print("Error: " + str(e))
            exit(1)

        # Loading log's configuration file
        logging.config.fileConfig(fname=log_file)
        log = logging.getLogger()

        # Load configuration file
        config = Config.get_instance()
        config.load_from(config_file)

        log.info("Starting...")
        log.debug(config)

        # Start observing directory for strategy
        try:
            observer = MediaObserver(config.observing_timeout)
            observer.observe()
        except Exception as e:
            log.fatal("Error occurred: {}".format(e))

        log.info("Exiting.")
        logging.shutdown()
def getAppsAddres(category):
    print "getApps..."
    rowsList = []
    try:
        timeStamp = Common.getYesterday_(
        )  #"2019-03-30"#time.strftime("%Y-%m-%d", time.localtime())#
        path = AppAnnieAppAddr % (category, timeStamp)
        print "path->" + path
        GET_HEADERS["path"] = path
        response = requests.get(AppAnnieAppAddr % (category, timeStamp),
                                data=None,
                                headers=GET_HEADERS)
        result = response.text
        # print result
        resultJson = json.loads(result)
        rowsList = resultJson["table"]['rows']
        # print "result->" + result
        print "code->" + str(response.status_code)
    except Exception as e:
        print str(e)
    return rowsList
Example #6
0
    def __init__(self, *args, **kwargs):
        # user, headers, passenger_data, login_frame,two_isOpenClick=two_isOpenClick, other_isOpenClick=other_isOpenClick
        wx.Frame.__init__(self,
                          parent=None,
                          title=kwargs['user'].username,
                          pos=(100, 100),
                          size=(1080, 650),
                          style=wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX
                          | wx.TAB_TRAVERSAL)

        TicketWin.Init(self, *args, **kwargs)
        self.Centre()
        self.Show(True)

        # 设置隐藏到托盘
        self.taskBarIcon = Common.TaskBarIcon(self)
        # 右上角关闭
        self.Bind(wx.EVT_CLOSE,
                  lambda evt, fram_obj=kwargs['login_frame']: self.
                  on_close_window(evt, fram_obj))
        self.Bind(wx.EVT_ICONIZE, self.on_icon_fiy)
def saveLog(contentMap):
    print "save map..."
    logFile = open(CHECK_LOG + Common.getTimeStr() + ".json", 'w')
    json.dump(contentMap, logFile, encoding='UTF-8', ensure_ascii=False)
    logFile.close()
Example #8
0
 def on_launch(self):
     wx.Locale(wx.LANGUAGE_CHINESE_SIMPLIFIED)
     Common.IsLocalSaleTimeExists()
     Common.IsLocalStationExists()
Example #9
0
 def refresh_click(self, event):
     self.refresh_btn.Disable()
     self.refresh_btn.SetLabel(u'正在获取...')
     self.refreshImg.Hide()
     Common.startWorkFunc(self.refresh_click_req, self.refresh_click_res)
Example #10
0
    def login_12306(self, url, username, password):
        # 开始登录
        self.login_btn.SetLabel(u'开始登录...')
        randCode = ','.join(self.pos)
        data = {
            'randCode': randCode,
            'loginUserDTO.user_name': username,
            'userDTO.password': password
        }

        login_res = Req.post(url, data, Common.headers)
        res_data_obj = Req.zippedDecompress(login_res)
        print(res_data_obj)

        if res_data_obj:
            res_rs = json.loads(res_data_obj)
            data, msg = res_rs.get('data'), res_rs.get('messages')
            #
            if data and data.get('loginCheck') == 'Y':
                self.login_btn.SetLabel(u'登录成功...')
                # 登录
                self.login_btn.SetLabel(u'正在初始化...')
                Req.post(Common.ulogin_url, {}, Common.headers)
                # 初始化my12306
                Req.get(Common.init_my12306_url, Common.headers)
                print(Common.headers)

                # 初始化leftTicket init
                Common.headers['Referer'] = Common.init_my12306_url
                print(Common.headers)
                left_res = Req.get(Common.left_ticket_url, Common.headers)
                if left_res:
                    left_res_html = Req.zippedDecompress(left_res)
                    html_reg = r'</title>(.*?)</head>'
                    all_list = re.findall(html_reg, left_res_html, re.S | re.M)

                    # 查找到动态js,找到,执行
                    if all_list:
                        script_reg = r'(?<=src=\").+?(?=\")|(?<=src=\').+?(?=\')'
                        script_list = re.findall(script_reg, all_list[0],
                                                 re.S | re.M)
                        if script_list:
                            self.dynamic_js_init(Common.headers['Origin'] +
                                                 script_list[-1])
                            # Req.get(HEADERS['Origin'] + script_list[-1], HEADERS)

                # self.Close(True)
                self.login_btn.SetLabel(u'正在获取联系人...')
                user = u.User(username, password)

                # 获取当前登录帐号的联系人
                passenger_data, two_isOpenClick, other_isOpenClick = Common.GetPassenger(
                    Common.headers)
                self.login_btn.SetLabel(u'获取联系人成功...')

                return dict(user=user,
                            passenger_data=passenger_data,
                            login_frame=self,
                            two_isOpenClick=two_isOpenClick,
                            other_isOpenClick=other_isOpenClick)

                # 显示登录后主窗体
                # wx.CallAfter(MainFrame, user=user, headers=Common.headers, passenger_data=passenger_data,
                #              login_frame=self,
                #              two_isOpenClick=two_isOpenClick, other_isOpenClick=other_isOpenClick)
                # MainFrame(user, HEADERS, passenger_data, self)

            else:
                # wx.CallAfter(self.maintenance_time, msg[0])
                return self.maintenance_time(msg[0])