Selaa lähdekoodia

Merge branch 'yifan' of ASJ_ADS/sync_amz_data into master

yifan_huang96 1 vuosi sitten
vanhempi
commit
074d7d1a4f
1 muutettua tiedostoa jossa 77 lisäystä ja 34 poistoa
  1. 77 34
      sync_amz_data/public/sp_api_client.py

+ 77 - 34
sync_amz_data/public/sp_api_client.py

@@ -32,6 +32,7 @@ class SpApiRequest:
         database="amz_sp_api",
         port=3306)
         return conn
+
     def timeToLocalTime(self,para_time=None):
         if para_time is not None:
             if ":" not in para_time:
@@ -107,32 +108,6 @@ class SpApiRequest:
 
             print("please wait...")
 
-    def test_(self):
-        conn = self.mysql_connect()
-        cursor = conn.cursor()
-        sql = "select * from amz_sp_api.productInfo"
-
-        # query_rel = conn.query(sql)
-        # cursor.execute(sql)
-        # col = [i[0] for i in cursor.description]
-        # rel = cursor.fetchall()
-        # print(col)
-        # print(rel)
-
-        sql1 = "select * from amz_sp_api.orderReport where `promotion-ids` in ['', Null]"
-        query_rel1 = conn.query(sql1)
-        cursor.execute(sql1)
-        col = [i[0] for i in cursor.description]
-        rel1 = cursor.fetchall()
-        df = pd.DataFrame(rel1,columns=col)
-        df['ReportDate'] = df['ReportDate'].astype("datetime64[ns]")
-        print(df.info())
-        # print(df)
-        bondary_date = (datetime.today() + timedelta(days=7))
-        list_ = ['',None]
-        df1 = df.query("ReportDate>@bondary_date or `promotion-ids` in @list_")
-        print(df1)
-
     def data_deal(self,decom_df):
         decom_df['mainImageUrl'] = decom_df['seller-sku'].map(lambda x: self.get_mainImage_url(x))
         url_columns = [i for i in decom_df.columns if "url" in i.lower()]
@@ -285,8 +260,7 @@ class SpApiRequest:
     def load_order_items(self,**kwargs):
         return Orders(credentials=self.credentials).get_order_items(**kwargs)
 
-
-    def insert_(self, sleep_time=0.8):
+    def order_instant(self, sleep_time=0.8):
         insert_list_orderBasic = []
         insert_list_orderDetail = []
         orderId_list = []
@@ -441,10 +415,79 @@ if __name__ == '__main__':
         'role_arn': 'arn:aws:iam::070880041373:role/Amazon_SP_API_ROLE'
     }
     sp_ = SpApiRequest(aws_credentials,Marketplaces.US,'3006125408623189')
-    # sp_.GET_MERCHANT_LISTINGS_ALL_DATA()
     sp_.GET_MERCHANT_LISTINGS_ALL_DATA()
-    # sp_.mysql_connect().commit()
-    # sp_.decompression("1532408019678")
-    # sp_.GET_MERCHANT_LISTINGS_ALL_DATA()
-    # sp_.timeToLocalTime()
-    # print(type(sp_))
+    """
+    create database amz_sp_api;
+    """
+    """
+            create table amz_sp_api.productInfo
+            (
+            `item-name`	VARCHAR(300),
+            `item-description`	VARCHAR(1000),
+            `listing-id`	VARCHAR(50),
+            `seller-sku`	VARCHAR(50),
+            `price`	FLOAT,
+            `quantity`	INT,
+            `open-date`	VARCHAR(70),
+            `image-url`	VARCHAR(300),
+            `item-is-marketplace`	VARCHAR(50),
+            `product-id-type`	INT,
+            `item-note`	VARCHAR(300),
+            `item-condition`	INT,
+            `asin1`	VARCHAR(50),
+            `asin2`	VARCHAR(50),
+            `asin3`	VARCHAR(50),
+            `will-ship-internationally`	VARCHAR(50),
+            `expedited-shipping`	VARCHAR(50),
+            `product-id`	VARCHAR(50),
+            `bid-for-featured-placement`	FLOAT,
+            `add-delete`	VARCHAR(50),
+            `pending-quantity`	INT,
+            `fulfillment-channel`	VARCHAR(50),
+            `merchant-shipping-group`	VARCHAR(50),
+            `status`	VARCHAR(50),
+            `mainImageUrl`	VARCHAR(300),
+            `opendate_date`	Date,
+            `updateTime`	Date,
+            `timezone`	VARCHAR(30)
+            )
+    """
+    """
+    create table amz_sp_api.orderReport
+    (`amazon-order-id` VARCHAR(40),
+    `merchant-order-id` VARCHAR(40),
+    `purchase-date` DATETIME,
+    `last-updated-date` DATETIME,
+    `order-status` VARCHAR(40),
+    `fulfillment-channel` VARCHAR(40),
+    `sales-channel` VARCHAR(40),
+    `order-channel` VARCHAR(40),
+    `ship-service-level` VARCHAR(40),
+    `product-name` VARCHAR(250),
+    `sku` VARCHAR(50),
+    `asin` VARCHAR(40),
+    `item-status` VARCHAR(40),
+    `quantity` INT,
+    `currency` VARCHAR(40),
+    `item-price` FLOAT,
+    `item-tax` FLOAT,
+    `shipping-price` FLOAT,
+    `shipping-tax` FLOAT,
+    `gift-wrap-price` FLOAT,
+    `gift-wrap-tax` FLOAT,
+    `item-promotion-discount` FLOAT,
+    `ship-promotion-discount` FLOAT,
+    `ship-city` VARCHAR(40),
+    `ship-state` VARCHAR(40),
+    `ship-postal-code` VARCHAR(40),
+    `ship-country` VARCHAR(40),
+    `promotion-ids` VARCHAR(50),
+    `cpf` VARCHAR(40),
+    `is-business-order` BOOL,
+    `purchase-order-number` VARCHAR(50),
+    `price-designation` VARCHAR(40),
+    `signature-confirmation-recommended` BOOL,
+    `ReportDate` DATE not null,
+    `timezone` VARCHAR(20) not null
+    );
+    """