lazyad 0.0.46__tar.gz → 0.0.48__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.

Potentially problematic release.


This version of lazyad might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lazyad
3
- Version: 0.0.46
3
+ Version: 0.0.48
4
4
  Summary: 基于Python的懒人包-适用于广告投放模块
5
5
  Home-page: https://gitee.com/ZeroSeeker/lazyad
6
6
  Author: ZeroSeeker
@@ -272,6 +272,24 @@ def performance(
272
272
  timeout=timeout
273
273
  )
274
274
 
275
+ def sanitize_entities(
276
+ xml_content
277
+ ):
278
+ """
279
+ 将非XML预定义实体全部替换
280
+ """
281
+ import re
282
+ # 匹配非XML预定义实体
283
+ from html.entities import entitydefs
284
+ combined_map = {f'&{k};': v for k, v in entitydefs.items()}
285
+ pattern = re.compile(r'&(?!lt;|gt;|amp;|apos;|quot;)\w+;')
286
+
287
+ def replace_entity(match):
288
+ entity = match.group(0)
289
+ return combined_map.get(entity, entity) # 未定义则保持原样
290
+
291
+ return pattern.sub(replace_entity, xml_content)
292
+
275
293
 
276
294
  def xml_to_dict(xml_str):
277
295
  """
@@ -0,0 +1,196 @@
1
+ from lazysdk import lazyrequests
2
+ from lazysdk import lazybase64
3
+
4
+
5
+ def make_auth(
6
+ keyid,
7
+ secret_key
8
+ ):
9
+ """
10
+ 生成校验字符串
11
+ :param keyid:
12
+ :param secret_key:
13
+ :return:
14
+ """
15
+ authorization = f"{keyid}:{secret_key}"
16
+ return f"Basic {lazybase64.lazy_b64encode(authorization)}"
17
+
18
+
19
+ def apps(
20
+ organization_id,
21
+ keyid,
22
+ secret_key
23
+ ):
24
+ """
25
+ 获取app列表
26
+ https://services.docs.unity.com/advertise/v1/index.html#section/Get-Started/First-Call:-List-Apps
27
+ :param organization_id:
28
+ :param keyid:
29
+ :param secret_key:
30
+ :return:
31
+ """
32
+ url = f"https://services.api.unity.com/advertise/v1/organizations/{organization_id}/apps"
33
+ headers = {"Authorization": make_auth(keyid=keyid, secret_key=secret_key)}
34
+ return lazyrequests.lazy_requests(
35
+ method="GET",
36
+ url=url,
37
+ headers=headers
38
+ )
39
+
40
+
41
+ def list_campaigns(
42
+ organization_id,
43
+ app_id,
44
+ keyid,
45
+ secret_key
46
+ ):
47
+ """
48
+ 获取Campaigns列表
49
+ https://services.docs.unity.com/advertise/v1/index.html#tag/Campaigns
50
+ :param organization_id:
51
+ :param app_id:
52
+ :param keyid:
53
+ :param secret_key:
54
+ :return:
55
+ """
56
+ url = f"https://services.api.unity.com/advertise/v1/organizations/{organization_id}/apps/{app_id}/campaigns"
57
+ headers = {"Authorization": make_auth(keyid=keyid, secret_key=secret_key)}
58
+ return lazyrequests.lazy_requests(
59
+ method="GET",
60
+ url=url,
61
+ headers=headers
62
+ )
63
+
64
+
65
+ def get_campaign(
66
+ organization_id,
67
+ app_id,
68
+ campaign_id,
69
+ keyid,
70
+ secret_key,
71
+ include_fields: list = None
72
+ ):
73
+ """
74
+ 获取Campaign信息
75
+ https://services.docs.unity.com/advertise/v1/index.html#tag/Campaigns/operation/advertise_getCampaign
76
+ :param organization_id:
77
+ :param app_id:
78
+ :param campaign_id:
79
+ :param keyid:
80
+ :param secret_key:
81
+ :param include_fields: ["cpiBids", "sourceBids", "roasBids", "retentionBids", "eventOptimizationBids", "budget"]
82
+ :return:
83
+ """
84
+ default_include_fields = ["cpiBids", "sourceBids", "roasBids", "retentionBids", "eventOptimizationBids", "budget"]
85
+ url = f"https://services.api.unity.com/advertise/v1/organizations/{organization_id}/apps/{app_id}/campaigns/{campaign_id}"
86
+ headers = {"Authorization": make_auth(keyid=keyid, secret_key=secret_key)}
87
+ if include_fields:
88
+ pass
89
+ else:
90
+ include_fields = default_include_fields
91
+ params_list = list()
92
+ for each in include_fields:
93
+ params_list.append(f"includeFields={each}")
94
+ params_str = "&".join(params_list)
95
+ return lazyrequests.lazy_requests(
96
+ method="GET",
97
+ url=f"{url}?{params_str}",
98
+ headers=headers
99
+ )
100
+
101
+
102
+ def get_budget(
103
+ organization_id,
104
+ app_id,
105
+ campaign_id,
106
+ keyid,
107
+ secret_key
108
+ ):
109
+ """
110
+ 获取 Campaign budget
111
+ https://services.docs.unity.com/advertise/v1/index.html#tag/Campaigns/operation/advertise_getCampaignBudget
112
+ :param organization_id:
113
+ :param app_id:
114
+ :param campaign_id:
115
+ :param keyid:
116
+ :param secret_key:
117
+ :return:
118
+ """
119
+ url = f"https://services.api.unity.com/advertise/v1/organizations/{organization_id}/apps/{app_id}/campaigns/{campaign_id}/budget"
120
+ headers = {"Authorization": make_auth(keyid=keyid, secret_key=secret_key)}
121
+ return lazyrequests.lazy_requests(
122
+ method="GET",
123
+ url=url,
124
+ headers=headers
125
+ )
126
+
127
+
128
+ def get_targeting_options(
129
+ organization_id,
130
+ app_id,
131
+ campaign_id,
132
+ keyid,
133
+ secret_key
134
+ ):
135
+ """
136
+ Get targeting options
137
+ https://services.docs.unity.com/advertise/v1/index.html#tag/Campaigns/operation/advertise_getTargeting
138
+ :param organization_id:
139
+ :param app_id:
140
+ :param campaign_id:
141
+ :param keyid:
142
+ :param secret_key:
143
+ :return:
144
+ """
145
+ url = f"https://services.api.unity.com/advertise/v1/organizations/{organization_id}/apps/{app_id}/campaigns/{campaign_id}/targeting"
146
+ headers = {"Authorization": make_auth(keyid=keyid, secret_key=secret_key)}
147
+ return lazyrequests.lazy_requests(
148
+ method="GET",
149
+ url=url,
150
+ headers=headers
151
+ )
152
+
153
+
154
+ def update_targeting_options(
155
+ organization_id,
156
+ app_id,
157
+ campaign_id,
158
+ keyid,
159
+ secret_key,
160
+ allow_list: list = None,
161
+ block_list: list = None,
162
+ iso_os_min: str = None
163
+ ):
164
+ """
165
+ Update targeting options
166
+ https://services.docs.unity.com/advertise/v1/index.html#tag/Campaigns/operation/advertise_updateTargeting
167
+ :param organization_id:
168
+ :param app_id:
169
+ :param campaign_id:
170
+ :param keyid:
171
+ :param secret_key:
172
+
173
+ :param allow_list:
174
+ :param block_list:
175
+ :param iso_os_min:
176
+ :return:
177
+ """
178
+ url = f"https://services.api.unity.com/advertise/v1/organizations/{organization_id}/apps/{app_id}/campaigns/{campaign_id}/targeting"
179
+ headers = {"Authorization": make_auth(keyid=keyid, secret_key=secret_key)}
180
+ data = {}
181
+ if allow_list or block_list:
182
+ data["appTargeting"] = {}
183
+ if allow_list:
184
+ data["appTargeting"]["allowList"] = allow_list
185
+ if block_list: # 黑名单
186
+ data["appTargeting"]["blockList"] = block_list
187
+ if iso_os_min:
188
+ data["deviceTargeting"] = {}
189
+ if iso_os_min:
190
+ data["deviceTargeting"]["osMin"] = iso_os_min
191
+ return lazyrequests.lazy_requests(
192
+ method="PATCH",
193
+ url=url,
194
+ headers=headers,
195
+ json=data
196
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lazyad
3
- Version: 0.0.46
3
+ Version: 0.0.48
4
4
  Summary: 基于Python的懒人包-适用于广告投放模块
5
5
  Home-page: https://gitee.com/ZeroSeeker/lazyad
6
6
  Author: ZeroSeeker
@@ -13,4 +13,5 @@ lazyad/crawlers/oceanengine.py
13
13
  lazyad/crawlers/qq.py
14
14
  lazyad/open/__init__.py
15
15
  lazyad/open/mintegral.py
16
- lazyad/open/qq.py
16
+ lazyad/open/qq.py
17
+ lazyad/open/unity.py
@@ -13,7 +13,7 @@ with open("README.md", "r", encoding='utf-8') as fh:
13
13
 
14
14
  setuptools.setup(
15
15
  name="lazyad",
16
- version="0.0.46",
16
+ version="0.0.48",
17
17
  description="基于Python的懒人包-适用于广告投放模块",
18
18
  long_description=long_description,
19
19
  long_description_content_type="text/markdown",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes