示例#1
0
 def run(self):
     self.request.include.logger.info(u"兵力不足10000")
     '''
     # 请求征兵操作
     url = "http://s%d.as.yaowan.com/root/mainCity!preDraught.action?%d" %(self.serverid,int(time.time()*1000))
     reqinfo = self.request.request(url)
     res = zlib.decompress(reqinfo.read())
     print 'preDraught res:',res
     '''
     
     '''
     补充兵力
     '''
     url = "http://s%d.as.yaowan.com/root/mainCity!draught.action?%d" %(self.serverid,int(time.time()*1000))
     data = {"forceNum":10000}
     reqinfo = self.request.request(url,data)
     res = zlib.decompress(reqinfo.read())
     if res:
         res = res[res.find("<?xml"):]
         infoXML = etree.XML(res)
         updateinfo = PlayerUpdateInfo()
         for child in infoXML.getchildren():
             if child.tag=="playerupdateinfo":
                 food = child.find("food").text
                 forces = child.find("forces").text
                 kfzonestate = child.find("kfzonestate").text
                 updateinfo.food = food
                 updateinfo.forces = forces
                 updateinfo.kfzonestate =kfzonestate
                 if updateinfo.forces:
                     self.request.include.logger.info(u"补充10000兵力成功")
                 else:
                     self.request.include.logger.info(u"补充10000兵力失败")
示例#2
0
 def getPreFoodBandC(self):
     url = "http://s%d.as.yaowan.com/root/mainCity!preFoodBandC.action?%d" %(self.serverid,int(time.time()*1000))
     reqinfo = self.request.request(url)
     res = zlib.decompress(reqinfo.read())
     #print 'preFoodBandC res:',res
     if res:
         if res.find("<?xml")<0:
             self.request.include.logger.warning(u"获取粮食买卖信息失败,重新请求...")
             time.sleep(2)
             return self.getPreFoodBandC()
         res = res[res.find("<?xml"):]
         infoXML = etree.XML(res)
         foodbandc = FoodBandC()
         for child in infoXML.getchildren():
             if child.tag=="state":
                 foodbandc.state = child.text
             if child.tag=="buyprice":
                 foodbandc.buyprice = float(child.text)
             if child.tag=="price":
                 foodbandc.price = float(child.text)
             if child.tag=="isup":
                 foodbandc.isup = bool(child.text)
             if child.tag=="bsmax":
                 foodbandc.bsmax = int(child.text)
             if child.tag=="crutrade":
                 foodbandc.crutrade = int(child.text)
             if child.tag=="maxtrade":
                 foodbandc.maxtrade = int(child.text)
             if child.tag=="playerupdateinfo":
                 updateinfo = PlayerUpdateInfo()
                 updateinfo.food = child.findtext("food")
                 updateinfo.kfzonestate = child.findtext("kfzonestate")
                 foodbandc.playerupdateinfo = updateinfo        
         return foodbandc
     return None