def get_classify_zone(state, city, district, address='', session=None): """ 根据地址获取分拨中心 """ config = getconfig() open_branch = config.get('yunda', 'open_branch') web_host = config.get('url', 'web_host') branchzone_url = config.get('yunda', 'branchzone_url') % web_host if open_branch.lower() != 'y': return {} params = { 'province': state.encode('utf8'), 'city': city.encode('utf8'), 'district': district.encode('utf8') } if state.startswith(u'江苏') and district.startswith(u'吴江'): params.update({'address': address.encode('utf8')}) try: req = urllib2.urlopen(branchzone_url + '?' + urllib.urlencode(params)) bjson = json.loads(req.read()) except: raise Exception(u'获取集包规则超时') if bjson['code'] != 0: raise Exception(u'获取集包规则错误(%s)' % bjson['response_error']) bzone = bjson['response_content']['branch_zone'] return bzone
def printYUNDAPDF(trade_ids, direct=False, session=None): yd_customer = getYDCustomerByTradeId(trade_ids[0], session=session) trades = session.query(PackageOrder).filter( PackageOrder.pid.in_(trade_ids)).filter_by(is_express_print=True) to_yunda_ids = [t.id for t in trades] pdfdoc = print_order(to_yunda_ids, partner_id=yd_customer.qr_id, secret=yd_customer.qr_code) for fname in os.listdir(TEMP_FILE_ROOT): os.remove(os.path.join(TEMP_FILE_ROOT, fname)) file_name = os.path.join(TEMP_FILE_ROOT, '%d.pdf' % int(time.time())) with open(file_name, 'wb') as f: f.write(pdfdoc) # 更新订单打印状态 from taobao.dao.webapi import WebApi WebApi.print_express(trade_ids) if direct: conf = getconfig() gsprint_exe = conf.get('custom', 'gsprint_exe') p = subprocess.Popen([gsprint_exe, file_name], stdout=subprocess.PIPE, stderr=subprocess.PIPE) p.communicate() else: webbrowser.open(file_name)
def getFullWebUrl(uri, params={}): conf = getconfig() web_host = conf.get('url', 'web_host') if not params: return 'http://%s%s' % (web_host, uri) else: return 'http://%s%s?%s' % (web_host, uri, urllib.urlencode(params))
def getAsyncPDFPrintUrl(self,user_code,trade_ids): cfg = getconfig() host_name = cfg.get('url','web_host') async_print_url = cfg.get('print','async_print_url') print_params = {'user_code':user_code, 'trade_ids':','.join(trade_ids)} return '%s?%s'%(async_print_url%(host_name),urllib.urlencode(print_params))
def get_session2(): try: cf = getconfig() db_host = cf.get('db', 'db_host') db_port = cf.get('db', 'db_port') db_name = cf.get('db', 'db_name') db_user = cf.get('db', 'db_user') db_pwd = cf.get('db', 'db_pwd') engine = create_engine('mysql://%s:%s@%s:%s/%s?charset=utf8' % (db_user, db_pwd, db_host, db_port, db_name), encoding='utf8', echo=True) Session = sessionmaker(bind=engine, autoflush=True, expire_on_commit=True) # except Exception, exc: logger.error(exc.message, exc_info=True) raise exc
def handle_demon(action, xml_data, partner_id, secret): xml_data = base64.encodestring(xml_data).strip() validate = hashlib.md5(xml_data + partner_id + secret).hexdigest() config = getconfig() qrcode_url = config.get('yunda', 'qrcode_url') params = { 'partnerid': partner_id, 'version': '1.0', 'request': ACTION_DICT[action], 'xmldata': xml_data, 'validation': validate } req = urllib2.urlopen(qrcode_url + API_DICT[action], urllib.urlencode(params)) rep = req.read() print 'debug resp:', params, action, rep if action == REPRINT: return rep return minidom.parseString(rep)
class WebApi(object): conf = getconfig() web_host = conf.get('url', 'web_host') @staticmethod def operate_packages(package_order_ids, operator_id): uri = '/warehouse/operate/' params = { 'package_order_ids': ','.join([str(p) for p in package_order_ids]), 'operator': operator_id } try: url = getFullWebUrl(uri, params) req = urllib.urlopen(url) r = req.read() resp = json.loads(r) sign = resp['isSuccess'] except Exception, e: logging.error(r) raise Exception('get response error:' + r) if not sign: logging.error(r) raise Exception(resp['response_error']) return True
def getPreWeightStatus(self): conf = getconfig() is_need_check = conf.get('custom', 'check_barcode') if is_need_check.lower() == 'true': return (cfg.SYS_STATUS_WAITSCANWEIGHT, ) return (cfg.SYS_STATUS_WAITSCANWEIGHT, cfg.SYS_STATUS_WAITSCANCHECK)
def get_ware_id(): cfg = getconfig() return cfg.get('user','ware_id')
def get_seller_ids(): cfg = getconfig() return [i.strip() for i in cfg.get('user','seller_ids').split(',') if i.strip()]
def get_oparetor(): cfg = getconfig() return cfg.get('user','username')
return delivery_panel def CreateChargeView(self): charge_panel = ScanChargePanel(self,-1) return charge_panel def OnExit(self,event): self.Session.commit() self.Session.close() self.Close() #sys.setdefaultencoding('utf8') app = wx.PySimpleApp() # try: config = getconfig() db_host = config.get('db','db_host') dlg=wx.SingleChoiceDialog(None,u"请选择仓库!", "Single Choice", [u'上海仓',u'广州仓']) if dlg.ShowModal() == wx.ID_OK: message = dlg.GetStringSelection() if message == u"上海仓": config.set('user','ware_id',1) config.set('user','username','jiashuai.li') writeconfig(config) print message if message == u"广州仓": config.set('user','ware_id',2)
def isAsyncPDFPrint(self): cfg = getconfig() return cfg.get('print','invoice_pdf_print').lower() == 'true'