def process(content, ip_to_prod):
    for line in content: 
        if not line:
            continue
        act = ActionLog.deserialize(json.loads(line))
        if act.method == 'POST' and act.url.endswith('pedido'):
            inv = Invoice.deserialize(json.loads(act.body))
            for x in inv.items:
                ip_to_prod[act.ip_address].add(x.prod.codigo.upper())
示例#2
0
def main():
    root = 'http://45.55.88.99:99/'
    auth = ('test', 'han')
    processor = ForwardRequestProcessor(dbapi, root, auth, codename='test')

    start = datetime.datetime(2015, 12, 1)
    end = datetime.datetime(2016, 1, 1)
    with dbapi.session:
        for meta in invapi.search_metadata_by_date_range(start, end, status=Status.COMITTED):
            r = requests.get('http://192.168.0.23/api/nota/{}'.format(meta.uid), auth=('yu', 'yu'))
            if r.status_code != 200:
                print r.status_code
                continue
            inv = Invoice.deserialize(r.json())
            work = doc_to_workobject(inv, action=WorkObject.CREATE, objtype=WorkObject.INV)
            processor.exec_work(work)
            print inv.meta.uid,  'created'
            work2 = doc_to_workobject(inv, action=WorkObject.CREATE, objtype=WorkObject.INV_TRANS)
            processor.exec_work(work2)
            print inv.meta.uid,  'commited'
示例#3
0
 def forward_request(self, work):
     print 'work', work['work'], type(work['work'])
     work = work['work']
     work = WorkObject.deserialize(json.loads(work))
     if work.objtype == WorkObject.INV:
         if work.action == WorkObject.DELETE:
             work.content = InvMovementMeta(uid=work.objid)
         else:
             work.content = InvMetadata.deserialize(work.content)
     elif work.objtype == WorkObject.INV_TRANS:
         work.content = Invoice.deserialize(work.content)
     elif work.objtype == WorkObject.TRANS:
         work.content = Transferencia.deserialize(work.content)
     else:
         print 'ERROR'
         return -1 # RETRY
     r = self.exec_work(work)
     if r.status_code == 200:
         return -2  # OK
     else:
         return -1  # RETRY
示例#4
0
def get_sources(directory):
    for fname in os.listdir(directory):
        if fname.startswith('sale-2015') or fname.startswith('sale-2016'):
            with open(os.path.join(directory, fname)) as f:
                for x in f.xreadlines():
                    yield Invoice.deserialize(json.loads(x))
示例#5
0
 def decode(line):
     j = json_loads(line)
     return Invoice.deserialize(j)
示例#6
0
def get_saved_inv():
    for x in os.listdir(JSON_DIR):
        with open(os.path.join(JSON_DIR, x)) as f:
            yield Invoice.deserialize(json.loads(f.read()))
示例#7
0
 def decode(line):
     j = json_loads(line)
     return Invoice.deserialize(j)
示例#8
0
def get_saved_inv():
    for x in os.listdir(JSON_DIR):
        with open(os.path.join(JSON_DIR, x)) as f:
            yield Invoice.deserialize(json.loads(f.read()))