Ejemplo n.º 1
0
def append_new_asin():
    new_asin_list = AmzWatchedAsin.get_not_watched_asin()
    if len(new_asin_list) > 0:
        i = 1
        for marketplace_asin in new_asin_list:
            amz_watched_asin = AmzWatchedAsin()
            amz_watched_asin.account_id = 13
            amz_watched_asin.marketplace_id = marketplace_asin.id
            amz_watched_asin.asin = marketplace_asin.asin
            amz_watched_asin.rule_list = '1111111111111111'
            amz_watched_asin.asin_status = 1
            amz_watched_asin.add(False)
            print('adding the %d th asin ' % i, amz_watched_asin.id,
                  amz_watched_asin.asin)
            i = i + 1
        try:
            BaseMethod.commit()
        except Exception as ex:
            raise ex
        else:
            print(
                "append_new_asin-----------------------------------successfully!--------------------------------------------->"
            )
    else:
        pass
Ejemplo n.º 2
0
 def _save_available_shipments(shipment_list):
     for data in shipment_list:
         AmzShipmentInfo.save(
             market_id=mws_acct.marketplace_id,
             name=mws_acct.name,
             shipment_id=data.ShipmentId,
             shipment_name=data.ShipmentName,
             shipment_status=data.ShipmentStatus,
             label_prep_type=data.LabelPrepType,
             shipment_fc=data.DestinationFulfillmentCenterId,
             commit=False)
         #resp1 = _list_ib_shipment_items(api, ShipmentId=data.ShipmentId)
         resp1 = _list_ib_shipment_items(api, data.ShipmentId)
         items = resp1.ListInboundShipmentItemsResult.ItemData
         for item in items:
             AmzShipmentItem.save(market_id=mws_acct.marketplace_id,
                                  name=mws_acct.name,
                                  shipment_id=item.ShipmentId,
                                  sku=item.SellerSKU,
                                  fnsku=item.FulfillmentNetworkSKU,
                                  qty_in_case=item.QuantityInCase,
                                  qty_shipped=item.QuantityShipped,
                                  qty_received=item.QuantityReceived,
                                  commit=False)
         BaseMethod.commit()
Ejemplo n.º 3
0
 def append_new_asin():
     new_asin_list = AmzWatchedAsin.get_not_watched_asin()
     for marketplace_asin in new_asin_list:
         amz_watched_asin = AmzWatchedAsin()
         amz_watched_asin.account_id = 13
         amz_watched_asin.marketplace_id = marketplace_asin.marketplace_id
         amz_watched_asin.asin = marketplace_asin.asin
         amz_watched_asin.rule_list = '1111111111111111'
         amz_watched_asin.asin_status = 1
         amz_watched_asin.add(False)
     BaseMethod.commit()
Ejemplo n.º 4
0
def check_report():
    #get ongoning report requests which is _SUBMITTED_ and  _IN_PROGRESS_
    ongoing_report_list = AmzReportRequest.find_ongoing_report()
    rep_map = {}
    for rep in ongoing_report_list:
        #bound (marketplace_id,name) as key
        key = (rep.marketplace_id, rep.name)
        #if the key is not in dict,define a list as the value of key
        if key not in rep_map:
            rep_map[key] = []
        #append the record of rep into  rep_map[(rep.marketplace_id, rep.name)]
        #rep includes marketplace_id,name,rep_type,request_id,report_id,start_date,end_date,status,create_at
        rep_map[key].append(rep)

    # for k, v in rep_map.iteritems():   python3 用items()替换iteritems()
    # for k, v in rep_map.items(): 用于遍历字典的(key-value)元组数组
    for k, v in rep_map.items():
        if len(v) == 0:
            continue
        market_id, name = k
        #get the api by offering market_id、name
        api = make_mws_api(market_id, name)
        #get list of alerdy generated request_id by generator
        req_id_list = [data.request_id for data in v]
        req_resp = api.get_report_request_list(ReportRequestIdList=req_id_list)
        report_info_list = req_resp.GetReportRequestListResult\
                                   .ReportRequestInfo
        #just for test
        print(
            'check_report:-------------------------------------------------------->'
        )
        print(report_info_list)

        if not report_info_list:
            continue
        #create a generator ReportRequestId as key,rep as value
        rep_info_map = {rep.ReportRequestId: rep for rep in report_info_list}
        #将v(即rep)的结果赋值给rep_db_list
        rep_db_list = v
        for rep_db in rep_db_list:
            rep_info = rep_info_map[rep_db.request_id]
            rep_db.status = rep_info.ReportProcessingStatus
            if rep_db.status == AmzReportRequest.ST_DONE:
                rep_db.report_id = rep_info.GeneratedReportId
                rep_db.update(False)

        BaseMethod.commit()
Ejemplo n.º 5
0
def do_sync_report_data(report_list, model):
    
    def _get_report(api, report_id):
        while True:
            try:
                return api.get_report(ReportId=report_id)
            except Exception as ex:
                for arg in ex.args:
                    if 'hrottled' in arg:
                        log.warning('get_report, RequestThrottled')
                        time.sleep(120)
                        continue
                raise ex

    for rep in report_list:
        api = make_mws_api(rep.marketplace_id, rep.name)
        rep_data = _get_report(api, rep.report_id)
        
        # process the text
        lines = rep_data.decode('utf-8','ignore').split('\r\n')
        # process the headrer of text
        header_line = lines[0]
        header = header_line.split('\t')
        header = [token.lower().replace('-', '_').replace(' ', '_').strip()
                  for token in header]

        for i in range(1, len(lines)):
            data = {}
            line = lines[i].strip()
            if not line:
                continue
            tokens = line.split('\t')
            for j in range(0, len(tokens)):
                data[header[j]] = tokens[j].strip()
            model.save(rep.marketplace_id, rep.name, rep.rep_type, data,
                       commit=False)

        rep.downloaded(commit=False)
        BaseMethod.commit()
Ejemplo n.º 6
0
    def _process_file(state):
        YEAR_MONTH = "2017Nov"
        #read the every state csv and write into database
        with open(
                file=
                'C:\\Users\\ACEEC\\Desktop\\amz_payment\\%sMonthlyTransaction_%s.csv'
                % (YEAR_MONTH, state),
                mode='r',
                encoding='utf-8') as csv_file:

            reader = csv.reader(csv_file)
            print(type(reader))
            #type of reader is _csv.reader
            NO = 1
            rows = [row for row in reader]

            # first of row North Amecia different with EU
            if state in _North_America:
                state_rows = rows[8:]
            if state in _EU:
                state_rows = rows[7:]

            for row in state_rows:
                amz_trans_info = AmzTransactionInfo()
                amz_trans_info.year_month = YEAR_MONTH[:4] + _MONTH_2_NO_Eg[
                    YEAR_MONTH[4:]]
                amz_trans_info.date_time = _formate_datetime(state, row[0])
                amz_trans_info.settlement_id = row[1]
                # unify as English
                amz_trans_info.type = _formate_type(row[2])
                amz_trans_info.order_id = row[3]
                amz_trans_info.sku = row[4]
                amz_trans_info.description = row[5]
                #some of type's quantity is null but databsa doesn't allow to be null
                if row[6]:
                    amz_trans_info.quantity = row[6]
                else:
                    amz_trans_info.quantity = -1
                # marketplace must be not null and must modify and unify as lower_case
                if row[7]:
                    amz_trans_info.marketplace = row[7].lower()
                else:
                    amz_trans_info.marketplace = _STATE_2_AMZ[state]
                amz_trans_info.fulfillment_channel = row[8]
                amz_trans_info.order_city = row[9]
                amz_trans_info.order_state = row[10]
                amz_trans_info.order_postal = row[11]
                amz_trans_info.product_sales = _formate_money(state, row[12])
                amz_trans_info.shipping_credits = _formate_money(
                    state, row[13])
                amz_trans_info.gift_wrap_credits = _formate_money(
                    state, row[14])
                amz_trans_info.promotional_rebates = _formate_money(
                    state, row[15])
                #de not have sales_tax_collected
                if state in _EU:
                    amz_trans_info.sales_tax_collected = 0
                    amz_trans_info.selling_fees = _formate_money(
                        state, row[16])
                    amz_trans_info.fba_fees = _formate_money(state, row[17])
                    amz_trans_info.other_transaction_fees = _formate_money(
                        state, row[18])
                    amz_trans_info.other = _formate_money(state, row[19])
                    amz_trans_info.total = _formate_money(state, row[20])
                if state in _North_America:
                    amz_trans_info.sales_tax_collected = row[16]
                    amz_trans_info.selling_fees = _formate_money(
                        state, row[17])
                    amz_trans_info.fba_fees = _formate_money(state, row[18])
                    amz_trans_info.other_transaction_fees = _formate_money(
                        state, row[19])
                    amz_trans_info.other = _formate_money(state, row[20])
                    amz_trans_info.total = _formate_money(state, row[21])
                amz_trans_info.add(False)
                #just for check out
                print("the %s record" % NO)
                NO += 1
            try:
                BaseMethod.commit()
            except Exception as e:
                raise
            else:
                print(
                    '--------------------------------byebye :transaction details of %s write to database is done !------------------------'
                    % state)
Ejemplo n.º 7
0
def do_sync_report_data(report_list, model):
    def _get_report(api, report_id):
        while True:
            try:
                return api.get_report(ReportId=report_id)
            except Exception as ex:
                for arg in ex.args:
                    if 'hrottled' in arg:
                        log.warning('get_report, RequestThrottled')
                        time.sleep(120)
                        continue
                raise ex
                # if 'hrottled' in ex.message: python3去除了异常类的序列行为和.message属性
                # if 'hrottled' == ex:
                #     log.warning('get_report, RequestThrottled')
                #     time.sleep(120)
                #     continue
                # print(type(ex))
                # raise ex

    for rep in report_list:
        api = make_mws_api(rep.marketplace_id, rep.name)
        rep_data = _get_report(api, rep.report_id)

        print(
            '_download_%s_data:-------------------------------------------------------->'
            % rep.rep_type)
        print(rep.marketplace_id, rep.name)

        # #save data to file
        # with open('./%s_%s.csv' % (rep.rep_type, rep.report_id),'w',encoding='utf-8') as fp:
        #     fp.write(rep_data.decode('utf8','ignore'))
        # print(type(rep_data))
        # # rep_data.decode('utf8')
        # print(rep_data.decode('utf8','ignore'))

        # process the text
        lines = rep_data.decode('utf-8', 'ignore').split('\r\n')
        # process the headrer of text
        header_line = lines[0]
        header = header_line.split('\t')
        header = [
            token.lower().replace('-', '_').replace(' ', '_').strip()
            for token in header
        ]

        for i in range(1, len(lines)):
            data = {}
            line = lines[i].strip()
            if not line:
                continue
            tokens = line.split('\t')
            for j in range(0, len(tokens)):
                data[header[j]] = tokens[j].strip()
            model.save(rep.marketplace_id,
                       rep.name,
                       rep.rep_type,
                       data,
                       commit=False)

        rep.downloaded(commit=False)
        BaseMethod.commit()