def readFile(self,num): base_url = r'http://appimg2.qq.com/card/mk/card_info_v3.xml' response =self.myHttpRequest.get_response(base_url).read() if os.path.exists('card_info_v3.db'): dbFileTemp = open('card_info_v3_temp.db','w') dbFileTemp.write(response) dbFileTemp.close() if os.path.getsize('card_info_v3_temp.db')>os.path.getsize('card_info_v3.db'): os.remove('card_info_v3.db') os.rename('card_info_v3_temp.db', 'card_info_v3.db') try: os.remove('test.db') except WindowsError: pass else: print 'no need change' os.remove('card_info_v3_temp.db') else: dbFileTemp = open('card_info_v3.db','w') dbFileTemp.write(response) dbFileTemp.close() try: os.remove('test.db') except WindowsError: pass self.database = carddatabase.CardDataBase(self.cur_file_dir()) self.tipLabel.SetLabelText(u'更新完成,请登陆')
def readFile(self, num): response = urllib2.urlopen( 'http://appimg2.qq.com/card/mk/card_info_v3.xml').read() if os.path.exists('card_info_v3.db'): dbFileTemp = open('card_info_v3_temp.db', 'w') dbFileTemp.write(response) dbFileTemp.close() print 'write file ok' #fileTemp = open('card_info_v3_temp.db','r') #fileDB = open('card_info_v3.db','r') if os.path.getsize('card_info_v3_temp.db') >= os.path.getsize( 'card_info_v3.db'): os.remove('card_info_v3.db') os.rename('card_info_v3_temp.db', 'card_info_v3.db') try: os.remove('test.db') except WindowsError: pass else: os.remove('card_info_v3_temp.db') else: dbFileTemp = open('card_info_v3.db', 'w') dbFileTemp.write(response) dbFileTemp.close() if os.path.getsize('card_info_v3.db') < os.path.getsize( 'card_info_v3_bf.db'): os.remove('card_info_v3.db') os.rename('card_info_v3_bf.db', 'card_info_v3.db') print 'write file ok' self.database = carddatabase.CardDataBase(self.cur_file_dir()) self.tipLabel.SetLabelText(u'更新完成,请登陆')
def __init__(self, window, myHttpRequest, cardtheme, cardPrice, nodeItem, searchCardId): threading.Thread.__init__(self, ) self.window = window self.myHttpRequest = myHttpRequest self.cardtheme = cardtheme self.cardPrice = cardPrice self.nodeItem = nodeItem self.searchCardId = searchCardId self.thread_stop = False self.database = carddatabase.CardDataBase(self.window.path) logging.basicConfig(filename='error.log')
def __init__(self, window, myHttpRequest, cardtheme, cardPrice, nodeItem, searchCardId, is_show_flash_card): threading.Thread.__init__(self, ) self.window = window self.myHttpRequest = myHttpRequest self.cardtheme = cardtheme self.cardPrice = cardPrice self.nodeItem = nodeItem self.searchCardId = searchCardId self.thread_stop = False self.database = carddatabase.CardDataBase(self.window.path) self.hasFound = False self.is_show_flash_card = is_show_flash_card
def __init__(self, parent, title): wx.Frame.__init__(self, parent, title=title, size=(750,150)) self.cap_cd = '' self.isNeedCodePattern = re.compile(ur"\((.*?)\)") self.isNeedCode =0 self.loginCode = '' self.myHttpRequest = myhttp.MyHttpRequest() #if not os.path.exists(constant.DATABASE): #-------------用户信息---------- self.userInfoSizer = wx.BoxSizer(wx.HORIZONTAL) self.tidLabel = wx.StaticText(self,-1,u'QQ')#-1的意义为id由系统分配 self.tidInput = wx.TextCtrl(self,-1) self.tidInput.Bind(wx.EVT_KILL_FOCUS, self.OnKillFocus) self.tidInput.Bind(wx.EVT_KEY_DOWN, self.OnChar) self.aidLabel = wx.StaticText(self,-1,u'密码') self.aidInput = wx.TextCtrl(self,-1,style=wx.TE_PASSWORD) self.codeImage=wx.StaticBitmap(self, -1, pos=(30,50), size=(150,80)) self.codeLabel = wx.StaticText(self,-1,u'验证码')#-1的意义为id由系统分配 self.codeInput = wx.TextCtrl(self,-1) self.codeLabel.Show(False) self.codeInput.Show(False) self.codeImage.Show(False) self.loginButton = wx.Button(self,-1,u'登陆') self.Bind(wx.EVT_BUTTON, self.loginQQ, self.loginButton) self.tipLabel = wx.StaticText(self,-1,u'正在更新数据库,请稍后点击登陆') self.tipLabel.SetForegroundColour((255,0,0)) self.userInfoSizer.Add(self.tidLabel,0,wx.ALL,10) self.userInfoSizer.Add(self.tidInput,0,wx.ALL,10) self.userInfoSizer.Add(self.aidLabel,0,wx.ALL,10) self.userInfoSizer.Add(self.aidInput,0,wx.ALL,10) self.userInfoSizer.Add(self.codeImage,0,wx.TOP,10) self.userInfoSizer.Add(self.codeLabel,0,wx.TOP,10) self.userInfoSizer.Add(self.codeInput,0,wx.ALL,10) self.userInfoSizer.Add(self.loginButton,0,wx.ALL,10) self.userInfoSizer.Add(self.tipLabel,0,wx.ALL,10) #---------------总体布局---------- self.sizer = wx.BoxSizer(wx.VERTICAL) self.sizer.Add(self.userInfoSizer, 0, wx.EXPAND) #Layout sizers self.SetSizer(self.sizer) self.SetAutoLayout(1) '''显示在屏幕中间 ''' self.Center() self.Show(True) config = ConfigParser.ConfigParser() try: config.read('user_info.ini') constant.USERNAME = config.get('userinfo','username') constant.PASSWORD = config.get('userinfo','password') self.tidInput.SetValue(constant.USERNAME) self.aidInput.SetValue(constant.PASSWORD) self.get_code() except Exception: print 'user_info.ini not exist' try: configFile = ConfigParser.ConfigParser() configFile.read("config.ini") constant.CARDUSERNUM = configFile.get("MagicCardConfig","searchCardNum") constant.ISUPDATEDB = int(configFile.get("MagicCardConfig","isUpdateDB")) constant.ISSALEOFFCARD = int(configFile.get("MagicCardConfig","isSaleOffCard")) constant.ISCOMMITBYWEB = int(configFile.get("MagicCardConfig","isCommitByWeb")) constant.ISCOMPLETECOMMIT = int(configFile.get("MagicCardConfig","isCompleteCommit")) constant.ISSEARCHSTEALFRIEND = int(configFile.get("MagicCardConfig","isSearchStealFriend")) except : configFile = ConfigParser.ConfigParser() configFile.add_section("MagicCardConfig") configFile.set("MagicCardConfig","searchCardNum",constant.CARDUSERNUM) configFile.set("MagicCardConfig","isUpdateDB",1) configFile.set("MagicCardConfig","isSaleOffCard",0) configFile.set("MagicCardConfig","isCommitByWeb",1) configFile.set("MagicCardConfig","isCompleteCommit",0) configFile.set("MagicCardConfig","isSearchStealFriend",0) configFile.write(open('config.ini','w')) if constant.ISUPDATEDB ==1 : thread.start_new_thread(self.readFile,(1,)) else: self.database = carddatabase.CardDataBase(self.cur_file_dir()) self.tipLabel.SetLabel(u'更新完成,请登陆')