def get_report(reportid): x = mws.Reports(access_key=access_key, secret_key=secret_key, account_id=merchant_id, region=region) report = x.get_report(report_id=reportid) response_data = report.original print response_data
def get_reports(): x = mws.Reports(access_key=access_key, secret_key=secret_key, account_id=merchant_id, region=region) report = x.get_report_list(max_count='10') response_data = report.original print response_data
def getreportrequeststatus(reporttype, reportrequestid): x = mws.Reports(access_key=access_key, secret_key=secret_key, account_id=merchant_id, auth_token=auth_token) reportrequeststatus = x.get_report_request_list(reportrequestid, reporttype) return reportrequeststatus
def requestreport(report_type, start_date, end_date): x = mws.Reports(access_key=access_key, secret_key=secret_key, account_id=merchant_id, auth_token=auth_token) report = x.request_report(report_type=report_type, start_date=start_date, end_date=end_date) return report
def _build_mws(): """ Returns relevant secrets for accessing the MWS API. Current implementation expects them as environment variables. """ access_key = os.environ['MWS_ACCESS_KEY'] secret_key = os.environ['MWS_SECRET_KEY'] account_id = os.environ['MWS_SELLER_ID'] return mws.Reports( access_key=access_key, secret_key=secret_key, account_id=account_id)
def getreport(generatedreportid, start_date, end_date): app_path = os.getcwd() os.chdir(os.getcwd()) filepath = app_path + filesep + 'kopari' + filesep + 'amazonmws' + filesep reportid = generatedreportid x = mws.Reports(access_key=access_key, secret_key=secret_key, account_id=merchant_id, auth_token=auth_token) report = x.get_report(report_id=reportid) df = pd.read_csv(StringIO(report.original.decode('ISO-8859-1')), sep="\t") source_file_name = filepath + 'orders_' + start_date + '_' + end_date + '.csv' dest_file_name = gspath + gssep + 'kopari' + gssep + 'amazonmws' df.to_csv(source_file_name) loadlocalfiletogooglestorage(batfile, source_file_name, dest_file_name)
def get_items(): x = mws.Reports(access_key=settings.MWS_ACCESS_KEY, secret_key=settings.MWS_SECRET_KEY, account_id=settings.MWS_ACCOUNT_ID, region='UK') resp = x.request_report(report_type='_GET_MERCHANT_LISTINGS_ALL_DATA_') request_id = resp.parsed.ReportRequestInfo.ReportRequestId sleep(50) resp = x.get_report_request_list(requestids=(request_id, )) report_id = resp.parsed.ReportRequestInfo.GeneratedReportId resp = x.get_report(report_id=report_id) csv_string = resp.parsed f = StringIO.StringIO(csv_string) reader = csv.reader(f, delimiter='\t') reader.next() _save_items(reader)
def fetch_reports_and_insert_data(seller_record): seller_id = seller_record[0] seller_data = seller_record[1] report_retriever = mws.Reports(access_key=seller_data["aws_acc_key"], secret_key=seller_data["aws_sec_key"], account_id=seller_id) requested_report_types = seller_data["requested_report_types"] requested_report_ids = [] for report_type in requested_report_types: print("Getting data for report type: {}".format(report_type)) # create_table_if_not_exists(report_retriever, report_type) # dates_list = get_dates_needed(seller_id, report_type) # print ("The following days reports will be requested: {}".format(dates_list)) dates_list = ['2019-06-18'] print("The following days reports will be requested: {}".format( dates_list)) get_and_insert_report_data(report_retriever, seller_record, report_type, dates_list)
from mws import mws access_key = '' #replace with your access key merchant_id = '' #replace with your merchant id secret_key = '' #replace with your secret key reportid = '' #replace with report id x = mws.Reports(access_key=access_key, secret_key=secret_key, account_id=merchant_id) report = x.get_report(report_id=reportid) response_data = report.original print(response_data)