def get_wo(plant, wo, host='localhost', port=6379, db=0): logger = logging.getLogger('flask.app') key = '%s:%s' % (plant, wo) logger.debug(key) ser = redis.Redis(host=host, port=port, db=db) try: value = ser.hgetall(key) # print(value) wo = workOrder.Workorder() wo.plant = key.split(':')[0] wo.wo_no = key.split(':')[1] wo.status = json.loads(value['status']) # pn total wo.pn = value['pn'] wo.total = wo.total() # print(wo.total) wo.rev = value['rev'] wo.qty = value['qty'] wo.desc = value['desc'] wo.remark = value['remark'].strip() wo.units = json.loads(value['units']) wo.last_update = value['last_update'] except KeyError: pass return wo
def get_all_wo_status(plant, host='localhost', port=6379, db=0): wos = {} regex = re.compile(r'\w{4}:\d{12}') ser = redis.Redis(host=host, port=port, db=db) keys = ser.keys('%s:*' % plant) for key in keys: if not regex.match(key): continue try: wo = workOrder.Workorder() wo.plant = key.split(':')[0] wo.wo_no = key.split(':')[1] # res = ser.hmget(key, {'status':'', 'pn':'', 'desc':'', 'remark':'' }) res = ser.hmget(key, ['status', 'pn', 'desc', 'remark', 'rev', 'qty']) wo.status = json.loads(res[0]) wo.pn = res[1] wo.desc = res[2] wo.remark = res[3].strip() wo.rev = res[4] wo.qty = res[5] # wo.status = json.loads(ser.hget(key, 'status')) # wo.pn = ser.hget(key, 'pn') # wo.desc = ser.hget(key, 'desc') # wo.remark = ser.hget(key, 'remark') wos[wo.wo_no] = wo except KeyError: continue return wos
def main(): wos = {} ol = open(r'.\static\inputs.txt') lines = ol.readlines() ol.close() for line in lines: tokens = line.split(',') wo = workOrder.Workorder() wo.plant = tokens[0] wo.wo_no = tokens[1] info = sfc.get_wo_info(wo.plant, wo.wo_no, sfc.url_switch(wo.plant)) print(info) wo.pn = info['pn'] wo.rev = info['rev'] wo.qty = info['qty'] wo.rev = info['rev'] wo.desc = info['desc'] if (len(tokens) > 2): wo.remark = tokens[2].strip() if len(wo.pn) > 0: (wo.status, wo.units) = sfc.get_workOrder_status_units( wo.plant, wo.wo_no, sfc.url_switch(wo.plant)) wos[wo.wo_no] = wo print('%s==%s' % (wo.key, repository.set_wo(wo, HOST, PORT, DB))) else: print('%s Skiped' % wo.key) print('Done')
def api_add_wo(): logger.debug('api_add_wo') plant = '' wo = '' remark = '' result = 0 if 'plant' in request.form: plant = request.form['plant'] if 'wo' in request.form: wo = request.form['wo'] if 'remark' in request.form: remark = request.form['remark'] # logger.debug('%s==%s==%s' % (plant, wo, remark)) order = workOrder.Workorder() order.plant = str(plant) order.wo_no = str(wo) order.remark = str(remark) # logger.debug('key:%s' % order.key) info = sfc.get_wo_info(plant, wo, sfc.url_switch(plant)) order.pn = info['pn'] order.desc = info['desc'] order.rev = info['rev'] order.qty = info['qty'] (order.status, order.units) = sfc.get_workOrder_status_units(plant, wo, sfc.url_switch(plant)) repository.set_wo(order, host=HOST, port=PORT, db=DB) result = 1 return str(result)
def __init__(self): self.plants = [(u'MSFT', 'GHUO'), (u'ALI', 'GHUX'), (u'TC/BD', 'GHUD'), (u'HPE', 'GHUB'), (u'SG RSS', 'GHUC'), (u'SG OSS', 'GHGG')] self.plant = '' self.wo_no = '' self.station = '' self.wo = workOrder.Workorder()
def wos_upload_redis(): order = workOrder.Workorder() i = 0 result = [] vm = MaintainVM() vm.plant = 'GHUO' if 'plant' in request.form: vm.plant = request.form['plant'] wos = repository.get_all_wo_status(vm.plant, host=HOST, port=PORT, db=DB) vm.wos = wos try: f = request.files.get('excelFile').read() data = xlrd.open_workbook(file_contents=f) table = data.sheet_by_index(i) keys = table.row_values(0) if keys: row_num = table.nrows col_num = table.ncols for i in range(1, row_num): sheet_data = {} for j in range(0, col_num): sheet_data['DESC'] = table.row_values(i)[0] sheet_data['PN'] = table.row_values(i)[1] sheet_data['WO'] = table.row_values(i)[2] sheet_data['Qty'] = table.row_values(i)[5] sheet_data['Remark'] = table.row_values(i)[6] if sheet_data not in result: result.append(sheet_data) for info in result: order._plant = vm.plant order.desc = info['DESC'] order.pn = info['PN'] if str(int(info['WO'])).startswith('6'): order.wo_no = '0000' + str(int(info['WO'])) elif str(int(info['WO'])).startswith('1') or str(int( info['WO'])).startswith('4'): order.wo_no = '000' + str(int(info['WO'])) order.qty = info['Qty'] order.remark = info['Remark'] (order.status, order.units) = sfc.get_workOrder_status_units( vm.plant, order.wo_no, sfc.url_switch(vm.plant)) # print(order._plant, order.desc, order.pn, order.wo_no, order.qty, order.remark) repository.set_wos(order, host=HOST, port=PORT, db=DB) return render_template('addwos.html', vm=vm) except Exception: return render_template('error.html')
def get_all_wo(plant, host='localhost', port=6379, db=0): wos = {} ser = redis.Redis(host=host, port=port, db=db) keys = ser.keys('%s:*' % plant) for key in keys: try: value = ser.hgetall(key) wo = workOrder.Workorder() wo.plant = key.split(':')[0] wo.wo_no = key.split(':')[1] wo.rev = value['rev'] wo.pn = value['pn'] wo.desc = value['desc'] wo.qty = value['qty'] wo.status = json.loads(value['status']) wo.units = json.loads(value['units']) wo.last_update = value['last_update'] wos[wo.wo_no] = wo except KeyError: continue return wos
def get_redis_from_six(): wos = {} values = repository.get_all_keys(host=HOST, port=PORT, db=get_DB) # time_key = str(datetime.now().strftime('%Y%m%d%H')) s_time = str(datetime.now().strftime('%Y%m%d%H')) # s_time = str((datetime.now() + timedelta(hours=1)).strftime('%Y%m%d%H')) wo = workOrder.Workorder() ser = redis.Redis(host=HOST, port=PORT, db=store_DB) sers = redis.Redis(host=HOST, port=PORT, db=get_DB) pipe = ser.pipeline() for value in values: wo.plant = value.split(':')[0] wo.wo_no = value.split(':')[1] # keys = sers.keys('%s:*' % wo.plant) keys = sers.keys('%s' % value) for key in keys: res = sers.hmget(key, ['status', 'pn', 'desc', 'remark', 'rev', 'qty']) wo.status = json.loads(res[0]) # wo.status = res[0] wo.pn = res[1] wo.desc = res[2] wo.remark = res[3].strip() wo.rev = res[4] wo.qty = res[5] wos['plant'] = wo.plant wos['wo'] = wo.wo_no wos['pn'] = wo.pn wos['desc'] = wo.desc wos['rev'] = wo.rev wos['qty'] = wo.qty wos['remark'] = wo.remark wos['status'] = wo.status pipe.sadd(s_time, wos) # pipe.zadd(s_time, wos) # pipe.hset(s_time, wo.wo_no, wos) pipe.expire(s_time, max_time) pipe.execute()