-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
73 lines (59 loc) · 2.05 KB
/
main.py
File metadata and controls
73 lines (59 loc) · 2.05 KB
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import asyncio
import os
from sdk import CafeSDK
async def run():
try:
# 1. Get params
input_json_dict = CafeSDK.Parameter.get_input_json_dict()
CafeSDK.Log.debug(f"params: {input_json_dict}")
# 2. proxy configuration
proxyDomain = "proxy-inner.cafescraper.com:6000"
try:
proxyAuth = os.environ.get("PROXY_AUTH")
CafeSDK.Log.info(f"Proxy authentication information: {proxyAuth}")
except Exception as e:
CafeSDK.Log.error(f"Failed to retrieve proxy authentication information: {e}")
proxyAuth = None
# 3. Construct the proxy URL
proxy_url = f"socks5://{proxyAuth}@{proxyDomain}" if proxyAuth else None
CafeSDK.Log.info(f"Proxy address: {proxy_url}")
# 4. TODO: Handle business logic
url = input_json_dict.get('url')
CafeSDK.Log.info(f"start deal URL: {url}")
# Simulate business processing results
result = {
"url": url,
"status": "success",
"data": {
"title": "Sample title",
"content": "Sample content",
# ... Other fields
}
}
# 5. Push result data
CafeSDK.Log.info(f"Processing result: {result}")
CafeSDK.Result.push_data(result)
# 6. Set the table headers (if table output is needed)
headers = [
{
"label": "URL",
"key": "url",
"format": "text",
},
# ... Other table header configurations
]
res = CafeSDK.Result.set_table_header(headers)
CafeSDK.Log.info("Script execution completed")
except Exception as e:
CafeSDK.Log.error(f"Script execution error: {e}")
error_result = {
"error": str(e),
"error_code": "500",
"status": "failed"
}
CafeSDK.Result.push_data(error_result)
raise
if __name__ == "__main__":
asyncio.run(run())