sc-common-interface 2.6.4__tar.gz → 2.6.6__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sc-common-interface
3
- Version: 2.6.4
3
+ Version: 2.6.6
4
4
  Summary: SC贴文销售公用的接口
5
5
  Home-page: UNKNOWN
6
6
  Author: river
@@ -7,7 +7,6 @@ import random
7
7
  import hmac
8
8
  from hashlib import sha1
9
9
  import random
10
- # from PostCommonInterface import *
11
10
 
12
11
  def delete_post(data):
13
12
  env = data["env"]
@@ -17,6 +16,7 @@ def delete_post(data):
17
16
  res = requests.delete(url, headers=headers).json()
18
17
  return res
19
18
 
19
+
20
20
  def delete_relate_post(data):
21
21
  """删除串接的facebook或fb group 避免影响串接"""
22
22
  env = data["env"]
@@ -39,45 +39,55 @@ def delete_relate_post(data):
39
39
  # print("param", param)
40
40
  # print("response",response)
41
41
  sales_data = response["data"]["list"]
42
- print("sales_data",sales_data)
42
+ # print("sales_data",sales_data)
43
43
  status = [1,2]
44
44
  if "status" in data:
45
45
  status = data["status"]
46
46
  for i in sales_data:
47
47
  platforms = i["platforms"]
48
48
  post_sale_status = i["post_sale_status"]
49
- if platforms == [platform.upper()] and post_sale_status in status:
49
+ live_sdk = i["live_sdk"]
50
+ if (platforms==[platform.upper()] or live_sdk==platform.upper()) and post_sale_status in status:
50
51
  sales_id = i["id"]
51
52
  data["sales_id"] = sales_id
52
53
  # print(sales_id)
53
54
  response = get_live_info(data)
54
- relatedPostList = response["data"]["relatedPostList"]
55
+ # print("查询详情返回,",response)
56
+ global relatedPostList
57
+ if sales_type.lower()=="live":
58
+ relatedPostList = response["data"]["relatedPostList"]
59
+ elif sales_type.lower()=="post":
60
+ relatedPostList = response["data"]["related_post_list"]
55
61
  if platform.lower() == "facebook":
62
+ count=0
56
63
  for i in relatedPostList:
57
64
  fb_post_id = i["post_id"]
58
65
  # print("fb_post_id",fb_post_id)
59
66
  # print("post_id", post_id)
60
67
  if fb_post_id.strip() in post_id:
61
68
  print("找到串接的帖文:%s"%sales_id)
69
+ count+=1
62
70
  res = delete_post(data)
63
- # print(res)
64
- return res
71
+ if count>=len(post_id):
72
+ return res
65
73
  elif platform.lower()=="fb_group":
74
+ count = 0
75
+ id_list = []
76
+ for id in post_id:
77
+ idData = id.split("posts/")[-1]
78
+ id_list.append(idData)
66
79
  for i in relatedPostList:
67
80
  permalink_url = i["permalink_url"]
68
81
  permalink_url = permalink_url.split("permalink/")[-1]
69
- id_list = []
70
- for id in post_id:
71
- idData = id.split("posts/")[-1]
72
- id_list.append(idData)
82
+
73
83
  # print("permalink_url",permalink_url)
74
84
  # print("post_id", post_id)
75
85
  if permalink_url.strip() in id_list:
76
86
  print("找到串接的帖文:%s" % sales_id)
77
87
  res = delete_post(data)
78
- return res
79
-
80
-
88
+ count +=1
89
+ if count>=len(id_list):
90
+ return res
81
91
 
82
92
 
83
93
 
@@ -322,7 +332,10 @@ def get_live_info(data):
322
332
  env = data["env"]
323
333
  headers = data["headers"]
324
334
  sales_id = data["sales_id"]
325
- url = "%s/api/posts/live/sales/%s" % (env, sales_id)
335
+ sales_type = "live"
336
+ if "sales_type" in data:
337
+ sales_type = data["sales_type"]
338
+ url = "%s/api/posts/%s/sales/%s" % (env,sales_type.lower(), sales_id)
326
339
  count = 0
327
340
  while True:
328
341
  response = requests.get(url,headers=headers)
@@ -877,14 +890,14 @@ def add_live(data):
877
890
  return response
878
891
 
879
892
 
880
- def get_live_info(data):
881
- """查询直播间信息"""
882
- env = data["env"]
883
- headers = data["headers"]
884
- sales_id = data["sales_id"]
885
- url = "%s/api/posts/live/sales/%s" % (env, sales_id)
886
- response = requests.get(url,headers=headers).json()
887
- return response
893
+ # def get_live_info(data):
894
+ # """查询直播间信息"""
895
+ # env = data["env"]
896
+ # headers = data["headers"]
897
+ # sales_id = data["sales_id"]
898
+ # url = "%s/api/posts/live/sales/%s" % (env, sales_id)
899
+ # response = requests.get(url,headers=headers).json()
900
+ # return response
888
901
 
889
902
  def edit_live_info(data):
890
903
  """
@@ -1890,8 +1903,78 @@ def add_all_product_set_to_live(data):
1890
1903
  else:
1891
1904
  break
1892
1905
 
1906
+ def add_all_product_set_to_keyword(data):
1907
+ env = data["env"]
1908
+ headers = data["headers"]
1909
+ sales_id = data["sales_id"]
1910
+ while True:
1911
+ print(data)
1912
+ set_list_res = get_product_set(data)
1913
+ print(set_list_res)
1914
+ data_list = set_list_res["data"]["list"]
1915
+ for product_info in data_list:
1916
+ product_id = product_info["id"]
1917
+ childrenInfo = product_info["childrenInfo"]
1918
+ spu_ids = list(childrenInfo.keys())
1919
+ # necessaryQuantitys = jsonpath(data_list, "$..necessaryQuantity")
1920
+ data["spu_ids"] = spu_ids
1921
+ #查询子商品信息
1922
+ response = get_produnct_set_detail(data)
1923
+ products = []
1924
+ zi_list = response["data"]["list"]
1925
+ # print(vars["childrenInfo"])
1926
+ for i in zi_list:
1927
+ product = {}
1928
+ spu_id = i["id"]
1929
+ product["count"] = childrenInfo[spu_id]["necessaryQuantity"]
1930
+ product["spuId"] = spu_id
1931
+ variations = i["variations"]
1932
+ if variations == []:
1933
+ product["skuId"] = spu_id
1934
+ else:
1935
+ sku_id = variations[0]["id"]
1936
+ product["skuId"] = sku_id
1937
+ products.append(product)
1938
+ url = "%s/admin/api/bff-web/keyword/product_set"%(env)
1939
+ keyword = "python添加商品关键子%d"%int(time.time())
1940
+ add_body = {
1941
+ "productKeywordList": [
1942
+ {
1943
+ "id": "%s"%product_id,
1944
+ "defaultKey": "",
1945
+ "combinationList": [
1946
+ {
1947
+ "products": products,
1948
+ "keywords": [
1949
+ "%s"%keyword
1950
+ ],
1951
+ "skuId": ""
1952
+ }
1953
+ ]
1954
+ }
1955
+ ]
1956
+ }
1957
+ try:
1958
+ data_res = requests.post(url,headers=headers,json=add_body).json()
1959
+ print(data_res)
1960
+ except Exception:
1961
+ print("出现异常")
1962
+ lastPage = set_list_res["data"]["pageInfo"]["lastPage"]
1963
+ pageNum = set_list_res["data"]["pageInfo"]["pageNum"]
1964
+ # print("加前的pagenum",pageNum)
1965
+ # print(lastPage)
1966
+ if lastPage == False:
1967
+ pageNum = pageNum + 1
1968
+ data["pageNum"] = pageNum
1969
+ print("pageNum=",pageNum)
1970
+ else:
1971
+ break
1972
+
1893
1973
 
1894
1974
 
1895
1975
 
1896
1976
  if __name__=="__main__":
1897
- pass
1977
+ data = {'env': 'https://front-admin-preview.shoplineapp.com', 'headers': {'Content-Type': 'application/json', 'authorization': 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiJkZmQxYjNiMDc0M2JmYWU4YTFkODk4NzczNjgyZWVkZCIsImRhdGEiOnsibWVyY2hhbnRfaWQiOiI2MWE4N2M5NzYzYjcwYzAwNTEwNmZiZDAiLCJhcHBsaWNhdGlvbl9pZCI6IjVlYjkwMzVhYjA5ZDEyNjU4NTFmOTU2ZiJ9LCJpc3MiOiJodHRwczovL2RldmVsb3BlcnMtcHJldmlldy5zaG9wbGluZWFwcC5jb20iLCJhdWQiOltdLCJzdWIiOiI2MWE4N2M5NzYzYjcwYzAwNTEwNmZiZDAifQ.Y90xLfYVAp9yByHo7Vc7A3hHrp6hX9X9Lg4mg_WiE_I', 'lang': 'en'}, 'platform': 'FB_GROUP', 'page_id': '106411048594439', 'relationUrl': 'https://www.facebook.com/groups/3592205981019493/posts/3868975560009199/', 'post_id': ['https://www.facebook.com/groups/3592205981019493/posts/3868976186675803/', 'https://www.facebook.com/groups/3592205981019493/posts/3868975560009199/', 'https://www.facebook.com/groups/3592205981019493/posts/3869121803327908/']}
1978
+ data["sales_type"] = "POST"
1979
+ delete_relate_post(data)
1980
+
@@ -57,13 +57,14 @@ def create_general_post(data):
57
57
  if response.status_code==200:
58
58
  break
59
59
  except Exception as e:
60
+ print(e)
60
61
  time.sleep(1)
61
62
  finally:
62
63
  count += 1
63
64
  if count > num:
64
65
  break
65
66
  response = response.json()
66
- print("创建贴文返回",response)
67
+ # print("创建贴文返回",response)
67
68
  sales_id = response["data"]["id"]
68
69
  return response,sales_id
69
70
 
@@ -109,6 +110,7 @@ def create_commerce_post(data):
109
110
  response.raise_for_status()
110
111
  break
111
112
  except requests.exceptions.RequestException as e:
113
+ print(e)
112
114
  time.sleep(1)
113
115
  finally:
114
116
  count +=1
@@ -422,7 +424,7 @@ def relate_post(data):
422
424
  response = get_page_post(data)
423
425
  available_post_list = []
424
426
  related_sales = jsonpath(response,"$..related_sales")
425
- print("查询到的贴文信息",related_sales)
427
+ # print("查询到的贴文信息",related_sales)
426
428
  for index,value in enumerate(related_sales):
427
429
  if value==False:
428
430
  available_post_list.append(response["data"]["data"][index])
@@ -784,7 +786,7 @@ def send_post_comment(data):
784
786
  url = "%s/facebook/webhook"%env
785
787
  sign_text = hmac.new(key.encode("utf-8"), json.dumps(body).encode("utf-8"), sha1)
786
788
  signData = sign_text.hexdigest()
787
- print("body",json.dumps(body))
789
+ # print("body",json.dumps(body))
788
790
  header = {"Content-Type": "application/json", "x-hub-signature": "sha1=%s" % signData}
789
791
  response = requests.post(url, headers=header, data=json.dumps(body))
790
792
  return user_id,name,comment_id
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sc-common-interface
3
- Version: 2.6.4
3
+ Version: 2.6.6
4
4
  Summary: SC贴文销售公用的接口
5
5
  Home-page: UNKNOWN
6
6
  Author: river
@@ -1,3 +1,2 @@
1
1
  requests>=2.0.0
2
2
  jsonpath>=0.82
3
- sc-common-interface>=2.6.2
@@ -2,13 +2,12 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='sc-common-interface',
5
- version='2.6.4',
5
+ version='2.6.6',
6
6
  description='SC贴文销售公用的接口',
7
7
  author='river',
8
8
  packages=find_packages(),
9
9
  install_requires=[
10
10
  "requests>=2.0.0",
11
- "jsonpath>=0.82",
12
- "sc-common-interface>=2.6.2"
11
+ "jsonpath>=0.82"
13
12
  ],
14
13
  )