sc-common-interface 2.7.5__tar.gz → 2.7.7__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.7.5
3
+ Version: 2.7.7
4
4
  Summary: SC贴文销售公用的接口
5
5
  Home-page: UNKNOWN
6
6
  Author: river
@@ -1,6 +1,5 @@
1
1
  import datetime
2
2
  import re
3
-
4
3
  import requests
5
4
  import json
6
5
  from jsonpath import jsonpath
@@ -9,6 +8,7 @@ import random
9
8
  import hmac
10
9
  from hashlib import sha1
11
10
  import random
11
+ from datetime import datetime
12
12
 
13
13
  def delete_post(data):
14
14
  env = data["env"]
@@ -150,7 +150,7 @@ def create_activity(data):
150
150
  headers = data["headers"]
151
151
  body = data["body"]
152
152
  sales_id = data["sales_id"]
153
- url = "%s/api/posts/activity/%s"%(env,sales_id)
153
+ url = "%s/admin/api/bff-web/live/activity/%s"%(env,sales_id)
154
154
  platform = "FACEBOOK"
155
155
  if "platform" in data:
156
156
  platform = data["platform"].upper()
@@ -234,22 +234,23 @@ def send__live_comment(data):
234
234
  num = random.randint(100000, 999999)
235
235
  user_id = "488864%d" % int(time.time())
236
236
  name = "test live%d" % int(time.time())
237
- comment_id = "%s_%d%d" % (page_id, stamp, num)
237
+
238
238
  keyword = "接口测试普通留言"
239
239
  user_id = data.get("user_id", user_id)
240
240
  name = data.get("name", name)
241
- comment_id = data.get("comment_id", comment_id)
242
241
  keyword = data.get("keyword", keyword)
243
242
  # sales_type = data.get("sales_type", "live")
244
- relationUrl = data.get("relationUrl")
243
+ relationUrl = data.get("relationUrl","")
245
244
  if page_id == "" or post_id == "key":
246
245
  page_info = get_page_info(data)
246
+ page_id = page_info["page_id"]
247
247
  platform = page_info["platform"]
248
248
  post_id = page_info["post_id"]
249
249
  group_id = page_info["group_id"]
250
250
  relationUrl = page_info["permalink_url"]
251
-
252
-
251
+ #放到后面,需要等设置完page_id 后再设置
252
+ comment_id = "%s_%d%d" % (page_id, stamp, num)
253
+ comment_id = data.get("comment_id", comment_id)
253
254
  body = {"object": "page", "entry": [{"id": page_id, "time": stamp, "changes": [{"field": "feed", "value": {
254
255
  "from": {"id": user_id, "name": name},
255
256
  "post": {"status_type": "added_video", "is_published": True, "updated_time": "2022-11-18T09:57:26+0000",
@@ -269,9 +270,7 @@ def send__live_comment(data):
269
270
  t_time = stamp*1000
270
271
  if "_" in post_id:
271
272
  post_id = post_id.split("_")[-1]
272
- else:
273
- # print("----")
274
- # relationUrl = data["relationUrl"]
273
+ elif relationUrl!="":
275
274
  match = re.search(r'groups/(\d+)/permalink/(\d+)/', relationUrl)
276
275
  group_id = match.group(1)
277
276
  post_id = match.group(2)
@@ -651,7 +650,6 @@ def create_live(data):
651
650
  need_send_message = data.get("need_send_message", need_send_message)
652
651
  has_link = data.get("has_link", has_link)
653
652
 
654
-
655
653
  body = {}
656
654
  if platform.lower() in ("fb_group","facebook","instagram"):
657
655
  body = {
@@ -843,6 +841,83 @@ def create_live(data):
843
841
  },
844
842
  "postConfigMap":{}
845
843
  }
844
+ elif platform.lower in ("line&pl","line&obc","pl&line","obc&line"):
845
+ shopId, platformChannelId, platformChannelName, response = get_line_info(data)
846
+ if platform.lower in ("line&pl","pl&line"):
847
+ type = "PL"
848
+ else:
849
+ type = "OBC"
850
+ needArchive = data.get("needArchive",True)
851
+ visibleTime = data.get("visibleTime",get_stamp_time(**{"days":60}))
852
+ startTime = data.get("startTime",get_stamp_time(**{"minutes":1}))
853
+ endTime = data.get("startTime", get_stamp_time(**{"minutes": 2}))
854
+ body = {
855
+ "sales": {
856
+ "title": title,
857
+ "salesOwner": salesOwner,
858
+ "salesDescription": salesDescription,
859
+ "platforms": [
860
+ "LINE"
861
+ ],
862
+ "platformSubType": type,
863
+ "platformChannels": [
864
+ {
865
+ "platform": "LINE",
866
+ "platformChannelName": shopId,
867
+ "platformChannelId": shopId
868
+ }
869
+ ],
870
+ "coverImage": "https://img.shoplineapp.com/media/image_clips/67a5678419ad34003b97243c/original.jpeg?1738893188",
871
+ "startTime": startTime,
872
+ "endTime": endTime,
873
+ "archivedStreamVisibleTime": visibleTime,
874
+ "needArchive": needArchive
875
+ },
876
+ "salesConfig": {
877
+ "patternModel": {
878
+ "patternModel": patternModel,
879
+ "keywordValidInLive": keywordValidInLive,
880
+ "keywordValidAfterLive": keywordValidAfterLive
881
+ },
882
+ "autoNotifyPay": {
883
+ "enable": False
884
+ },
885
+ "stock": {
886
+ "lockStock": stockEnable,
887
+ "salesStockLockExpireTime": stockExpireTime
888
+ },
889
+ "lowOfQuantity": {
890
+ "enable": False,
891
+ "sound": False
892
+ }
893
+ },
894
+ "postConfigMap": {
895
+ "LINE": {
896
+ "message": {
897
+ "needSendMessage": False,
898
+ "hasInteractionMessage": {
899
+ "firstMessageTemplate": {
900
+ "topMessage": ""
901
+ },
902
+ "messageButton": ""
903
+ },
904
+ "hasLink": True,
905
+ "noInteractionMessage": {
906
+ "firstMessageTemplate": {
907
+ "topMessage": ""
908
+ },
909
+ "firstMessageButton": "",
910
+ "secondMessageTemplate": {
911
+ "topMessage": ""
912
+ },
913
+ "secondMessageButton": ""
914
+ },
915
+ "messageType": "MESSAGE"
916
+ }
917
+ }
918
+ }
919
+ }
920
+
846
921
  count = 0
847
922
  while True:
848
923
  response = requests.post(url,headers=headers,json=body)
@@ -865,6 +940,29 @@ def create_live(data):
865
940
  return sales_id
866
941
 
867
942
  # print(json.dumps(body))
943
+ def get_stamp_time(data):
944
+ #拿到指定时间的时间戳
945
+ num = data.get("num",2)
946
+ time_type = data.get("time_type","add")
947
+ unit = data.get("unit","minutes")
948
+ # 获取当前 UTC 时间
949
+ now = datetime.now()
950
+ if time_type not in {"add", "sub"}:
951
+ raise ValueError("Invalid time_type. Use 'add' or 'sub'.")
952
+ stamp_time = now + datetime.timedelta(**{unit:num if time_type == "add" else -num})
953
+ return int(stamp_time.timestamp()*1000)
954
+
955
+ def get_line_info(data):
956
+ env = data["env"]
957
+ headers = data["headers"]
958
+ url = "%s/api/posts/post/sales/lineConnectInfo"%env
959
+ response = requests.get(url,headers=headers).json()
960
+ shopId = response["data"]["shopInfo"]["shopId"]
961
+ platformChannelId = response["data"]["channel"]["platformChannelId"]
962
+ platformChannelName = response["data"]["channel"]["platformChannelName"]
963
+ return shopId,platformChannelId,platformChannelName,response
964
+
965
+
868
966
 
869
967
 
870
968
  def add_live(data):
@@ -2021,7 +2119,10 @@ def handler_auto_reply(data):
2021
2119
 
2022
2120
 
2023
2121
  if __name__=="__main__":
2024
- pass
2122
+ 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', 'sales_id': '514694', 'activity_id': '10296402', 'keyword': 'lyqyh1738918140786', 'post_id': '3592205981019493_3943831999190221', 'page_id': '106411048594439', 'group_id': '3592205981019493', 'key': '5e3bba98882fc0fb22a0607238bc5b8f'}
2123
+ data["keyword"] = "lyqyh1738918047653"
2124
+ send__live_comment(data)
2125
+
2025
2126
 
2026
2127
 
2027
2128
 
@@ -190,6 +190,34 @@ def search_oa_product(data):
190
190
  response = requests.get(url, headers=headers).json()
191
191
  return response
192
192
 
193
+ def get_has_stock_product(data):
194
+ """返回有库存商品的spu_id和sku_id"""
195
+ env = data["env"]
196
+ headers = data["headers"]
197
+ url = "%s/openApi/proxy/v1/products?page=1&per_page=20" % env
198
+ if "query" in data:
199
+ query = data["query"]
200
+ url = "%s/openApi/proxy/v1/products/search?page=1&per_page=20&%s" % (env,query)
201
+ response = requests.get(url, headers=headers).json()
202
+ product_item = response["data"]["items"]
203
+ sku_id = ""
204
+ for product in product_item:
205
+ variations = product["variations"]
206
+ status = product["status"]
207
+ if variations == [] and status != "draft":
208
+ total_orderable_quantity = product["total_orderable_quantity"]
209
+ if total_orderable_quantity > 0 or total_orderable_quantity == -1:
210
+ spu_id = product["id"]
211
+ return spu_id,sku_id
212
+ elif status != "draft":
213
+ for variation in variations:
214
+ total_orderable_quantity = variation["total_orderable_quantity"]
215
+ if total_orderable_quantity > 0 or total_orderable_quantity == -1:
216
+ spu_id = product["id"]
217
+ sku_id = variation["id"]
218
+ return spu_id,sku_id
219
+
220
+
193
221
  def create_post_lucky_draw(data):
194
222
  """
195
223
  创建抽奖活动
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sc-common-interface
3
- Version: 2.7.5
3
+ Version: 2.7.7
4
4
  Summary: SC贴文销售公用的接口
5
5
  Home-page: UNKNOWN
6
6
  Author: river
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='sc_common_interface',
5
- version='2.7.5',
5
+ version='2.7.7',
6
6
  description='SC贴文销售公用的接口',
7
7
  author='river',
8
8
  packages=find_packages(),
@@ -11,3 +11,4 @@ setup(
11
11
  "jsonpath>=0.82"
12
12
  ],
13
13
  )
14
+