我是靠谱客的博主 自信胡萝卜,这篇文章主要介绍python 阿里云审核,现在分享给大家,希望可以做个参考。

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
#!/usr/bin/python3 # coding=utf-8 import pymssql import threading import time from profile import * from service import * import configparser import decimal decimal.__version__ cf = configparser.ConfigParser() cf.read("config.ini") access_key_id = "" access_key_secret = "" profile = Profile(access_key_id, access_key_secret) api_path_results = r'/green/image/results' api_path = r'/green/image/asyncscan' sqlhost=cf.get("Database", "sqlhost") sqluser=cf.get("Database", "sqluser") sqlpassword=cf.get("Database", "sqlpassword") sqldatabase=cf.get("Database", "sqldatabase") client_info = { "ip": "127.0.0.1" } class myThread (threading.Thread): def __init__(self,id): threading.Thread.__init__(self) self.id=id def run(self): while 1: print(str(self.id)+"开始执行"+time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))) threadLock.acquire() results=get_date(self.id) threadLock.release() if self.id < 5: ali(results,self.id) else: aliresults(results,self.id) print(str(self.id)+"执行成功"+time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))) def get_date(id): try: Alipolitician=0 sqlstr=" update az_ali_photo_20210315 set status="+str(id)+" WHERE status =0 and ID IN (select top 100 id from az_ali_photo_20210315 with(NOLOCK) where id>5571335 AND id<11690052 AND Alipolitician=0 and status =0 )" if id > 5: Alipolitician=8 sqlstr=" update az_ali_photo_20210315 set status="+str(id)+" WHERE status =0 and ID IN (select top 100 id from az_ali_photo_20210315 with(NOLOCK) where id>5571335 AND id<11690052 AND Alipolitician=8 and status =0 and dateadd(MINUTE,-1,getdate())>addtime )" conn=pymssql.connect(host=sqlhost,user=sqluser,password=sqlpassword,database=sqldatabase,timeout=30,login_timeout=5) cur=conn.cursor() cur.execute(sqlstr) conn.commit() cur.close() conn.close() conn1=pymssql.connect(host=sqlhost,user=sqluser,password=sqlpassword,database=sqldatabase,timeout=30,login_timeout=5) cur1=conn1.cursor() cur1.execute(" select id,taskId,yunpicurl from az_ali_photo_20210315 with(NOLOCK) WHERE Alipolitician="+str(Alipolitician)+" and status ="+str(id)) results = cur1.fetchall() cur1.close() conn1.close() return results except Exception as ex: log("获取数据失败!"+str(ex)) #myThread(id).start() def ali(results,id): for row in results: alicensor(str(row[0]), str(row[2]),id) def log(logtxt): with open("log.txt","a") as f: f.write(logtxt+"n") def aliresults(results,id): for row in results: alicensorresults(str(row[0]), str(row[1]),id) def alicensor(pid, url,id): post_data = { "bizType": "Green", "scenes": ["ad","terrorism"], "offline":"true", "tasks": [ { "dataId": str(uuid.uuid1()), "url":url } ] } service = GreenService(profile) result="" try: response = service.send_request(api_path, client_info, post_data,15) if response=="": return #print(response+url) result = json.loads(response) if "Request was denied due to user flow control" in str(result): return #print(str(result)) if 200 == result["code"]: taskResults = result["data"] for taskResult in taskResults: if(200 == taskResult["code"]): taskId = taskResult["taskId"] updateconn=pymssql.connect(host=sqlhost,user=sqluser,password=sqlpassword,database=sqldatabase,timeout=30,login_timeout=5) updatecur=updateconn.cursor() #print("update az_ali_photo_20210330 set Alipolitician=8,addtime=getdate(),taskId="+str(taskId)+" WHERE id="+pid) updatecur.execute("update az_ali_photo_20210315 set Alipolitician=8,status =0,addtime=getdate(),taskId='"+str(taskId)+"' WHERE id="+pid); updateconn.commit() updatecur.close() updateconn.close() #print('线程'+str(id)+' 检测成功+'+time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))) else: updateconn=pymssql.connect(host=sqlhost,user=sqluser,password=sqlpassword,database=sqldatabase,timeout=30,login_timeout=5) updatecur=updateconn.cursor() updatecur.execute("update az_ali_photo_20210315 set Alipolitician=4,addtime=getdate() WHERE id="+pid); updateconn.commit() updatecur.close() updateconn.close() else: updateconn=pymssql.connect(host=sqlhost,user=sqluser,password=sqlpassword,database=sqldatabase,timeout=30,login_timeout=5) updatecur=updateconn.cursor() log("检测失败3"+str(pid)) #myThread(id).start() updatecur.execute("update az_ali_photo_20210315 set Alipolitician=3,addtime=getdate() WHERE id="+pid); updateconn.commit() updatecur.close() updateconn.close() except Exception as ex: log("检测失败1!"+str(ex)) time.sleep(3) #myThread(id).start() def alicensorresults(pid, taskId,id): post_data = { "bizType": "Green", "scenes": ["ad","terrorism"], "taskIds": taskId } service = GreenService(profile) result="" Alipolitician=2 Risktype=0 try: response = service.send_request(api_path_results, client_info, post_data,10) if response=="": return result = json.loads(response) #print(str(result)) if "Request was denied due to user flow control" in str(result): return if 200 == result["code"]: taskResults = result["data"] for taskResult in taskResults: if(200 == taskResult["code"]): sceneResults = taskResult["results"] for sceneResult in sceneResults: scene = sceneResult["scene"] label = sceneResult["label"] suggestion = sceneResult["suggestion"] if scene=='ad' and label=='customized': Alipolitician=1 Risktype=1 if scene=='terrorism' and suggestion!='pass': Alipolitician=1 Risktype=2 except Exception as ex: log(str(ex)+str(response)) time.sleep(2) Alipolitician=0 try: updateconn=pymssql.connect(host=sqlhost,user=sqluser,password=sqlpassword,database=sqldatabase,timeout=30,login_timeout=5) updatecur=updateconn.cursor() #print('线程'+str(id)+' 结果+'+time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))) updatecur.execute("update az_ali_photo_20210315 set status =0,Risktype="+str(Risktype)+", Alipolitician="+str(Alipolitician)+",result='"+str(result).replace("'","''")+"' WHERE id="+pid); updateconn.commit() updatecur.close() updateconn.close() except Exception as ex : log('检测失败4'+str(ex)) time.sleep(2) #myThread(id).start() threadLock = threading.Lock() if __name__ == '__main__': try : myThread(1).start() time.sleep(10) myThread(2).start() time.sleep(10) myThread(3).start() #myThread(4).start() #time.sleep(10) #myThread(5).start() #time.sleep(10) #myThread(6).start() #time.sleep(10) #myThread(7).start() #time.sleep(10) #myThread(8).start() #time.sleep(10) #myThread(9).start() #time.sleep(10) #myThread(10).start() #time.sleep(10) except Exception as ex : log(ex) #!/usr/bin/python3 # coding=utf-8 import uuid from urllib import parse from utils import * import http.client class GreenService: def __init__(self, profile): self.profile = profile def send_request(self, api_path, client_info, post_data,out_time): try: data = json.dumps(post_data) content_md5 = signature_md5(data.encode("utf-8")) gmt = gmt_time() header = { "Accept": "application/json", "Content-Type": "application/json", "Content-MD5": content_md5, "Date": gmt, "x-acs-version": "2017-01-12", "x-acs-signature-nonce": str(uuid.uuid1()), "x-acs-signature-version": "1.0", "x-acs-signature-method": "HMAC-SHA1", } header["Authorization"] = "acs " + self.profile.access_key_id + ":" + signature_header(header, api_path, client_info, self.profile.access_key_secret) query = { "clientInfo": json.dumps(client_info) } query_data = parse.urlencode(query).encode('utf-8') conn = http.client.HTTPConnection("green.cn-shanghai.aliyuncs.com", 80,out_time) conn.request('POST', api_path + "?%s" % str(query_data, encoding="utf-8"), json.dumps(post_data), header) response = conn.getresponse() data = response.read().decode('utf-8') return data except Exception as ex: return "" #!/usr/bin/python3 # coding=utf-8 class Profile: def __init__(self, access_key_id, access_key_secret): self.access_key_id = access_key_id self.access_key_secret = access_key_secret

最后

以上就是自信胡萝卜最近收集整理的关于python 阿里云审核的全部内容,更多相关python内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(68)

评论列表共有 0 条评论

立即
投稿
返回
顶部