def main(): settings = { 'cookie_secret': '66oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=', 'login_url': r'/login', 'debug': True, } #load config xml and init logger conf = Config() conf.load('./wm.xml') LOG().setlogger('./wm.log') print conf.to_string() html_mgn().start(conf.bnum) wx_mongo.WxMongo().start() omgn = order_mgn.OrderMgn() omgn.init() onotify = order_notify.OrderNotify() onotify.start(wx_mongo.WxMongo(), conf) discount_mgn.DiscountMgn().start('./dc.xml') print 'server ip[%s],port[%d]' % (conf.ip, conf.port) # Start server app = tornado.web.Application([ (r'/wm', WMHandler), (r'/openid', OrderHandler), (r'/shopping', ShoppingHandler), (r'/test', TestHandler), ], **settings) app.listen(conf.port) tornado.ioloop.IOLoop.instance().start()
def start(self, path=None): if path is None: pinfo = 'input path is null of WxServer' raise err.IException(err.ErrCode.ParamErr, pinfo) self.conf.load(path) wx_mongo.WxMongo().start() self.log = LOG().getlogger() self.mprocessor = msg_processor.MsgProcessor(wx_mongo.WxMongo(), self.log) self.eprocessor = event_processor.EventProcessor( wx_mongo.WxMongo(), self.log) self.wx_crypto = WXBizMsgCrypt(self.conf.token, self.conf.enc_key, self.conf.appid)
def order_test(): conf = config.Config() conf.load('./unit/test.xml') print conf.to_string() print("%s,%d", conf.mongo_ip, conf.mongo_port) conn = pymongo.Connection(host=conf.mongo_ip, port=conf.mongo_port, network_timeout=10) print 'connection ok' try: db = mongodb.WxDatabase(conn) db_user = user.User(db.get_collection(conf.user)) except IException as e: e.detail() return None print 'user coll ok' db_user.update('zhengyang', 0, '18757571517', 'xl area') db_user.update('zhengyang', 0, '18757571517', 'xf street') db_user.update('jianglili', 0, '15268526565', 'xl area') db_user.update('jianglili', 0, '15268526565', 'xf street') cursor = db_user.coll.find({}) for ele in cursor: print ele wx_mongo.WxMongo().start() omgn = OrderMgn() omgn.init() access_text = {'openid': 'zhengyang'} access_input = json.dumps(access_text) print omgn.get_order_html(access_input)
def order_history_test(): conf = config.Config() conf.load('./unit/test.xml') mongo = wx_mongo.WxMongo() mongo.start() oid = 'zhengyang' odtime = mytime.today2str() oprice = '14' ocounts = [1, 2, 3, 4, 5, 6, 7, 8] for i in ocounts: omenu_arr = [] omenu = {} omenu['m'] = 'menu' + str(i) omenu['n'] = i omenu['t'] = 'title' + str(i) omenu_arr.append(omenu) mongo.order.add_order(id=oid, dtime=odtime, count=i, menu=omenu_arr, price=oprice) mongo.shopping.add_shopping(id=oid, dtime=odtime, count=i) omgn = OrderMgn() omgn.init() access_text = {'openid': 'zhengyang'} access_input = json.dumps(access_text) print omgn.get_order_history_html(access_input) mongo.shopping.drop() mongo.order.drop()
def menu_del(): conf = config.Config() conf.load('./unit/test.xml') print conf.to_string() mongo = wx_mongo.WxMongo() mongo.start() mmgn = menu_mgn.MenuMgn() mmgn.load('./test_m.xml') mmgn.remove_menu()
def __init__(self, log_path, conf_path): LOG().setlogger(log_path) self.conf = Config() self.conf.load(conf_path) self.app_id = self.conf.appid self.app_secret = self.conf.appsecret self.mongo = wx_mongo.WxMongo() self.mongo.start() print 'app_id=%s,key=%s' % (self.app_id, self.app_secret) self.tool = api_tool.ApiTool(self.conf.appid, self.conf.appsecret, 3000)
def order_token(): conf = config.Config() conf.load('./unit/test.xml') log = LOG() mongo = wx_mongo.WxMongo() log.setlogger('./test.log') mongo.start() refresher = order_notify.TokenRefresher() refresher.start_refresh(LOG().getlogger(), mongo, conf) time.sleep(60) refresher.stop_refresh()
def menu_test(): conf = config.Config() conf.load('./unit/test.xml') print conf.to_string() mongo = wx_mongo.WxMongo() mongo.start() mmgn = menu_mgn.MenuMgn() mmgn.load('./menu.xml') mmgn.update() hmgn = html_mgn.html_mgn() html = hmgn.get_week_now() print html.encode('utf-8')
def order_and_shopping(): conf = config.Config() conf.load('./unit/test.xml') log = LOG() mongo = wx_mongo.WxMongo() log.setlogger('./test.log') mongo.start() oid = 'zhengyang' odtime = mytime.today2str() oprice = '14' ocounts = [1, 2, 3, 4, 5, 6, 7, 8] for i in ocounts: omenu = {} omenu['m'] = 'menu' + str(i) omenu['n'] = i omenu['t'] = 'title' + str(i) mongo.order.add_order(id=oid, dtime=odtime, count=i, menu=omenu, price=oprice) mongo.shopping.add_shopping(id=oid, dtime=odtime, count=i) nums = mongo.shopping.get_shopping(oid) print nums id_arrays = nums['history'] for id in id_arrays: id_order = mongo.order.get_order(id) print id_order arr_len = len(id_arrays) print id_arrays[arr_len - 4] print id_arrays[arr_len - 3] print id_arrays[arr_len - 2] mongo.shopping.drop() mongo.order.drop()
def user_find_test(): conf = config.Config() conf.load('./unit/test.xml') print conf.to_string() print("%s,%d", conf.mongo_ip, conf.mongo_port) conn = pymongo.Connection(host=conf.mongo_ip, port=conf.mongo_port, network_timeout=10) print 'connection ok' try: db = mongodb.WxDatabase(conn) db_user = user.User(db.get_collection(conf.user)) except IException as e: e.detail() return None print 'user coll ok' wx_mongo.WxMongo().start() omgn = OrderMgn() omgn.init() info = omgn.get_user_info('zzzz') print type(info) print info
def update(self): self.mongo = wx_mongo.WxMongo() self.update_stuff() self.update_menus() self.update_now() self.update_time()
def start(self, path): self.mongo = wx_mongo.WxMongo() self.load(path) self.update_db()
def __init__(self): self.week = {} self.bnum = 0 self.mongo = wx_mongo.WxMongo()
def init(self): self.log = LOG().getlogger() self.mongo = wx_mongo.WxMongo() self.counter = order_notify.OrderCounter() self.dm = discount_mgn.DiscountMgn()
def __init__(self, conf_path): self.conf = Config() self.conf.load(conf_path) self.mongo = wx_mongo.WxMongo() self.mongo.start()