sc-common-interface 2.2.5__tar.gz → 2.2.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.2.5
3
+ Version: 2.2.7
4
4
  Summary: SC贴文销售公用的接口
5
5
  Home-page: UNKNOWN
6
6
  Author: river
@@ -0,0 +1,142 @@
1
+ import datetime
2
+ import requests
3
+ import json
4
+ from jsonpath import jsonpath
5
+ import time
6
+ import random
7
+ import hmac
8
+ from hashlib import sha1
9
+ import random
10
+
11
+
12
+ def create_activity(data):
13
+ env = data["env"]
14
+ headers = data["headers"]
15
+ body = data["body"]
16
+ sales_id = data["sales_id"]
17
+ url = "%s/api/posts/activity/%s"%(env,sales_id)
18
+ platform = "FACEBOOK"
19
+ if "platform" in data:
20
+ platform = data["platform"].upper()
21
+ response = requests.post(url,headers=headers,json=body)
22
+ if response.status_code==200:
23
+ activity_id = response.json()["data"]
24
+ return activity_id
25
+ else:
26
+ return response
27
+
28
+ def delate_activity(data):
29
+ env = data["env"]
30
+ headers = data["headers"]
31
+ activity_id = data["activity_id"]
32
+ url = "%s/api/activity/%s" % (env, activity_id)
33
+ response = requests.delete(url,headers=headers).json()
34
+ return response
35
+
36
+ def start_activity(data):
37
+ env = data["env"]
38
+ headers = data["headers"]
39
+ activity_id = data["activity_id"]
40
+ url = "%s/api/activity/%s/start" % (env, activity_id)
41
+ response = requests.post(url,headers=headers).json()
42
+ return response
43
+
44
+ def end_activity(data):
45
+ env = data["env"]
46
+ headers = data["headers"]
47
+ activity_id = data["activity_id"]
48
+ url = "%s/api/activity/%s/end" % (env, activity_id)
49
+ response = requests.post(url, headers=headers).json()
50
+ return response
51
+
52
+ def send__live_comment(data):
53
+ env = data["env"]
54
+ key = data["key"]
55
+ info = get_live_info(data)
56
+ related_post_list = info["data"]["relatedPostList"][0]
57
+ page_id = related_post_list["page_id"]
58
+ post_id = related_post_list["post_id"]
59
+ platform = related_post_list["platform"]
60
+ stamp = int(time.time())
61
+ num = random.randint(100000, 999999)
62
+ user_id = "488864%d" % int(time.time())
63
+ if "user_id" in data:
64
+ user_id = data['user_id']
65
+ name = "test live%d" % int(time.time())
66
+ if "name" in data:
67
+ name = data['name']
68
+ comment_id = "%s_%d%d" % (page_id, stamp, num)
69
+ if "comment_id" in data:
70
+ comment_id = data['comment_id']
71
+ keyword = "接口测试普通留言"
72
+ if "keyword" in data:
73
+ keyword = data['keyword']
74
+ body = {}
75
+ if platform == "FACEBOOK":
76
+ body = {"object": "page", "entry": [{"id": page_id, "time": stamp, "changes": [{"field": "feed", "value": {
77
+ "from": {"id": user_id, "name": name},
78
+ "post": {"status_type": "added_video", "is_published": True, "updated_time": "2022-11-18T09:57:26+0000",
79
+ "permalink_url": "https://www.facebook.com/permalink.php?story_fbid=pfbid02jLK3e6YdFSXp2DmD7j7vtStLXoBzTi8rxKrp6jFhVMUTTEgz6qvZA8soR9Uwydd8l&id=107977035056574",
80
+ "promotion_status": "inactive", "id": post_id}, "message": keyword, "item": "comment",
81
+ "verb": "add", "post_id": post_id, "comment_id": comment_id,
82
+ "created_time": stamp, "parent_id": post_id}}]}]}
83
+ elif platform == "INSTAGRAM":
84
+ body = {"entry": [{"id": page_id, "time": stamp, "changes": [{"value": {"from": {"id": user_id,
85
+ "username": name},
86
+ "media": {"id": post_id,
87
+ "media_product_type": "FEED"},
88
+ "id": comment_id, "text": keyword},
89
+ "field": "comments"}]}], "object": "instagram"}
90
+
91
+ url = "%s/facebook/webhook" % env
92
+ sign_text = hmac.new(key.encode("utf-8"), json.dumps(body).encode("utf-8"), sha1)
93
+ signData = sign_text.hexdigest()
94
+ # print("body", json.dumps(body))
95
+ header = {"Content-Type": "application/json", "x-hub-signature": "sha1=%s" % signData}
96
+ response = requests.post(url, headers=header, data=json.dumps(body))
97
+ return user_id, name, comment_id
98
+
99
+
100
+ def get_live_info(data):
101
+ env = data["env"]
102
+ headers = data["headers"]
103
+ sales_id = data["sales_id"]
104
+ url = "%s/api/posts/live/sales/%s" % (env, sales_id)
105
+ response = requests.get(url,headers=headers).json()
106
+ return response
107
+
108
+ def get_activity_detail(data):
109
+ """
110
+ type:
111
+ luckyDraw,抽奖活动
112
+ voucher--留言抢优惠
113
+ answerFirst--抢答
114
+ bidding--竞标
115
+ vote:投票
116
+ :param data:
117
+ :return:
118
+ """
119
+ env = data["env"]
120
+ headers = data["headers"]
121
+ activity_id = data["activity_id"]
122
+ type = data["type"]
123
+ url = ""
124
+ if type in "luckyDraw":
125
+ url = "%s/api/activity/luckyDraw/%s"% (env, activity_id)
126
+ elif type in "voucher":
127
+ url = "%s/api/activity/voucher/%s" % (env, activity_id)
128
+ elif type in "answerFirst":
129
+ url = "%s/api/activity/answerFirst/%s" % (env, activity_id)
130
+ elif type in "bidding":
131
+ url = "%s/api/activity/bidding/%s" % (env, activity_id)
132
+ elif type in "vote":
133
+ url = "%s/api/activity/vote/%s" % (env, activity_id)
134
+ response = requests.get(url,headers=headers).json()
135
+ return response
136
+
137
+
138
+
139
+
140
+
141
+ if __name__=="__main__":
142
+ pass
@@ -1,5 +1,4 @@
1
1
  import datetime
2
-
3
2
  import requests
4
3
  import json
5
4
  from jsonpath import jsonpath
@@ -400,28 +399,40 @@ def relate_post(data):
400
399
  sales_id = data["sales_id"]
401
400
  if "platform" in data:
402
401
  platform = data["platform"].upper()
403
- response = get_page_post(data)
404
- available_post_list = []
405
- related_sales = jsonpath(response,"$..related_sales")
406
- print("查询到的贴文信息",related_sales)
407
- for index,value in enumerate(related_sales):
408
- if value==False:
409
- available_post_list.append(response["data"]["data"][index])
410
402
  url = "%s/api/posts/post/sales/%s/addPost"%(env,sales_id)
403
+ body = {}
404
+ if platform=="FB_GROUP":
405
+ page_id = data["page_id"]
406
+ relationUrl = data["relationUrl"]
407
+ body = {
408
+ "pageId": page_id,
409
+ "platform": "FB_GROUP",
410
+ "relationUrl": relationUrl
411
+ }
412
+ else:
413
+ response = get_page_post(data)
414
+ available_post_list = []
415
+ related_sales = jsonpath(response,"$..related_sales")
416
+ print("查询到的贴文信息",related_sales)
417
+ for index,value in enumerate(related_sales):
418
+ if value==False:
419
+ available_post_list.append(response["data"]["data"][index])
420
+
411
421
  # platform = "FACEBOOK"
412
422
  # print(available_post_list[0])
413
- page_id = jsonpath(available_post_list[0],"$..from.id")[0]
414
- page_name = jsonpath(available_post_list[0],"$..from.name")[0]
415
- post_id = jsonpath(available_post_list[0],"$.id")[0]
416
- message = jsonpath(available_post_list[0],"$.message")[0]
417
- permalink_url = jsonpath(available_post_list[0],"$.permalink_url")[0]
418
- status_type = jsonpath(available_post_list[0],"$.status_type")[0]
419
- picture = jsonpath(available_post_list[0],"$.picture")[0]
420
- body = {"pageId": page_id, "pageName": page_name, "platform": platform,
421
- "postList": [{"postId": post_id, "postTitle": page_name,
422
- "postDescription": message, "postImageUrl": picture,
423
- "permalinkUrl": permalink_url,
424
- "statusType": status_type}]}
423
+ page_id = jsonpath(available_post_list[0],"$..from.id")[0]
424
+ page_name = jsonpath(available_post_list[0],"$..from.name")[0]
425
+ post_id = jsonpath(available_post_list[0],"$.id")[0]
426
+ message = jsonpath(available_post_list[0],"$.message")[0]
427
+ permalink_url = jsonpath(available_post_list[0],"$.permalink_url")[0]
428
+ status_type = jsonpath(available_post_list[0],"$.status_type")[0]
429
+ picture = jsonpath(available_post_list[0],"$.picture")[0]
430
+ body = {"pageId": page_id, "pageName": page_name, "platform": platform,
431
+ "postList": [{"postId": post_id, "postTitle": page_name,
432
+ "postDescription": message, "postImageUrl": picture,
433
+ "permalinkUrl": permalink_url,
434
+ "statusType": status_type}]}
435
+
425
436
  response = requests.post(url,headers=headers,json=body).json()
426
437
  return response
427
438
 
@@ -1450,4 +1461,11 @@ def get_mc_order_link(url):
1450
1461
 
1451
1462
 
1452
1463
  if __name__=="__main__":
1453
- pass
1464
+ pass
1465
+ # headers = {"content-type": "application/json",
1466
+ # "authorization": "Bearer 11eyJhbGciOiJIUzI1NiJ9.eyJqdGkiOiIzN2Y2MjY2M2IyMTI1MjIzMWZlMTc4MTE2ODhkNDliYSIsImRhdGEiOnsibWVyY2hhbnRfaWQiOiI2MjI5YTdiYWVhNzA2NDJhOGI2NWViZGEiLCJhcHBsaWNhdGlvbl9pZCI6IjYwZWVjNWViZjhkYzkyMDAwNjUyZTAwNiJ9LCJpc3MiOiJodHRwczovL2RldmVsb3BlcnMteXkuc2hvcGxpbmVzdGcuY29tIiwiYXVkIjpbXSwic3ViIjoiNjIyOWE3YmFlYTcwNjQyYThiNjVlYmRhIn0.FwtntG1dAYWNUcEZf6WSehXQveEw_rvTSGPEM3xV9FA"}
1467
+ # data = {"env": "https://front-service.shoplinestg.com", "headers": headers, "platform": "FB_GROUP",
1468
+ # "sales_id": "84031", "page_id": "110842575060695",
1469
+ # "relationUrl": "https://www.facebook.com/groups/416632743936652/posts/823646243235298/"}
1470
+ # res = relate_post(data)
1471
+ # print(res)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: sc-common-interface
3
- Version: 2.2.5
3
+ Version: 2.2.7
4
4
  Summary: SC贴文销售公用的接口
5
5
  Home-page: UNKNOWN
6
6
  Author: river
@@ -1,4 +1,5 @@
1
1
  setup.py
2
+ sc_common_interface/LiveCommonInterface.py
2
3
  sc_common_interface/Platform.py
3
4
  sc_common_interface/PostCommonInterface.py
4
5
  sc_common_interface/__init__.py
@@ -2,7 +2,7 @@ from setuptools import setup, find_packages
2
2
 
3
3
  setup(
4
4
  name='sc-common-interface',
5
- version='2.2.5',
5
+ version='2.2.7',
6
6
  description='SC贴文销售公用的接口',
7
7
  author='river',
8
8
  packages=find_packages(),