本文整理汇总了Python中inventory.Inventory.processGameBasket方法的典型用法代码示例。如果您正苦于以下问题:Python Inventory.processGameBasket方法的具体用法?Python Inventory.processGameBasket怎么用?Python Inventory.processGameBasket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类inventory.Inventory
的用法示例。
在下文中一共展示了Inventory.processGameBasket方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Ingressbot
# 需要导入模块: from inventory import Inventory [as 别名]
# 或者: from inventory.Inventory import processGameBasket [as 别名]
class Ingressbot(JabberBot):
def __init__(self, pwd, cfg, logHandler=None):
super(Ingressbot, self).__init__(username=pwd["jabber"]["user"], password=pwd["jabber"]["password"], acceptownmsgs=True, command_prefix=".")
self.pwd = pwd
self.cfg = cfg
self.stdin_path = '/dev/null'
self.stdout_path = '/dev/null'
self.stderr_path = '/dev/null'
self.pidfile_path = '/var/lock/ingressbot.pid'
self.pidfile_timeout = 5
self.logger = logging.getLogger("ingressbot")
self.inventory = Inventory()
self.inventoryLock = Lock()
self.playerHistory = dict()
self.threads = []
self.lastChatTimestamp = -1
if logHandler is not None:
self.log.addHandler(logHandler)
def run(self):
self.api = Api(self.pwd["ingress"]["userEmail"], self.pwd["ingress"]["userPassword"])
try:
with open(os.path.expanduser("~/.ingressbot.pkl"), "rb") as f:
unpickler = Unpickler(f)
self.inventory = unpickler.load()
except:
pass
self.threads.append(TimerThread(interval=10, target=self.refreshInventory))
self.threads.append(TimerThread(interval=10, setup=self.setupRefreshChat, target=self.refreshChat))
self.threads.append(Thread(target=self.serve_forever))
self.send(self.cfg["master"], "IngressBot is up and running")
for t in self.threads:
t.start()
for t in self.threads:
while t.is_alive():
t.join(timeout=3600.0)
def callback_presence(self, conn, presence):
presence.getFrom().setResource(None)
return super(Ingressbot, self).callback_presence(conn, presence)
def callback_message(self, conn, message):
message.getFrom().setResource(None)
return super(Ingressbot, self).callback_message(conn, message)
def serve_forever(self, connect_callback=None, disconnect_callback=None):
try:
return super(Ingressbot, self).serve_forever(connect_callback, disconnect_callback)
except Exception as e:
self.logger.critical("Exception: " + str(type(e)) + ": " + e.message)
self.logger.critical("Stacktrace: " + traceback.format_exc())
def stop(self):
try:
for t in self.threads:
try:
t.interrupt()
except:
pass
for t in self.threads:
try:
t.join()
except:
pass
self.inventoryLock.acquire()
with open(os.path.expanduser("~/.ingressbot.pkl"), "wb") as f:
pickler = Pickler(f)
pickler.dump(self.inventory)
finally:
self.inventoryLock.release()
self.logger.info("stopped")
def refreshInventory(self):
try:
result = self.api.getInventory(self.inventory.lastQueryTimestamp);
if("gameBasket" in result):
try:
self.inventoryLock.acquire()
self.inventory.processGameBasket(result)
finally:
self.inventoryLock.release()
except Exception as e:
self.logger.critical("Exception: " + str(type(e)) + ": " + e.message)
self.logger.critical("Stacktrace: " + traceback.format_exc())
def setupRefreshChat(self):
try:
result = self.api.getMessages(self.cfg["bounds"], -1, -1, 1, False)["result"]
self.lastChatTimestamp = result[0][1]
Thread(target=self.chatLookback, args=(long(self.lastChatTimestamp)-(long(self.cfg["chatLookbackHours"])*3600000), self.lastChatTimestamp)).start()
except Exception as e:
self.logger.critical("Exception: " + str(type(e)) + ": " + e.message)
self.logger.critical("Stacktrace: " + traceback.format_exc())
def refreshChat(self):
try:
response = self.api.getMessages(self.cfg["bounds"], self.lastChatTimestamp, -1, 100, False)
#.........这里部分代码省略.........