Update app.py
Browse files
app.py
CHANGED
@@ -40,15 +40,6 @@ def load_proxies(proxy_file="proxys.txt"):
|
|
40 |
print(f"Error loading proxies: {e}")
|
41 |
return []
|
42 |
|
43 |
-
def cleanup_temp_files():
|
44 |
-
for filename in os.listdir(temp_dir):
|
45 |
-
file_path = os.path.join(temp_dir, filename)
|
46 |
-
try:
|
47 |
-
if os.path.isfile(file_path):
|
48 |
-
os.remove(file_path)
|
49 |
-
except Exception as e:
|
50 |
-
print(f"Error deleting {file_path}: {e}")
|
51 |
-
|
52 |
def search_google_images(query, num_images=1):
|
53 |
try:
|
54 |
api_key = os.getenv('GOOGLE_API_KEY')
|
@@ -68,8 +59,24 @@ def search_google_images(query, num_images=1):
|
|
68 |
"searchType": "image",
|
69 |
"num": num_images * 3,
|
70 |
"safe": 'off',
|
71 |
-
"imgSize": '
|
72 |
-
"imgType": '
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
"rights": 'cc_publicdomain|cc_attribute|cc_sharealike',
|
74 |
"key": api_key
|
75 |
}
|
|
|
40 |
print(f"Error loading proxies: {e}")
|
41 |
return []
|
42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
def search_google_images(query, num_images=1):
|
44 |
try:
|
45 |
api_key = os.getenv('GOOGLE_API_KEY')
|
|
|
59 |
"searchType": "image",
|
60 |
"num": num_images * 3,
|
61 |
"safe": 'off',
|
62 |
+
"imgSize": 'LARGE',
|
63 |
+
"imgType": 'imgTypeUndefined',
|
64 |
+
"rights": 'cc_publicdomain|cc_attribute|cc_sharealike',
|
65 |
+
"key": api_key
|
66 |
+
}
|
67 |
+
).json()
|
68 |
+
else:
|
69 |
+
with requests_proxy.ProxyManager(proxies) as proxy_manager:
|
70 |
+
result = proxy_manager.get(
|
71 |
+
f"https://www.googleapis.com/customsearch/v1",
|
72 |
+
params={
|
73 |
+
"q": query,
|
74 |
+
"cx": cse_id,
|
75 |
+
"searchType": "image",
|
76 |
+
"num": num_images * 3,
|
77 |
+
"safe": 'off',
|
78 |
+
"imgSize": 'LARGE',
|
79 |
+
"imgType": 'imgTypeUndefined',
|
80 |
"rights": 'cc_publicdomain|cc_attribute|cc_sharealike',
|
81 |
"key": api_key
|
82 |
}
|