-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathverify_shares.py
More file actions
270 lines (222 loc) Β· 8.69 KB
/
Copy pathverify_shares.py
File metadata and controls
270 lines (222 loc) Β· 8.69 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
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#!/usr/bin/env python3
"""
ChatGPT Share Verification Tool
Verifies accessibility of discovered ChatGPT share URLs.
Checks HTTP status and content to categorize shares as:
- accessible: Valid share with content
- deleted: Returns 200 but shows "Can't load" message
- not_found: Returns 404
- error: Other errors (timeouts, network issues, etc.)
"""
import sys
import io
import argparse
import json
import requests
from typing import Dict, List
from datetime import datetime
from pathlib import Path
from concurrent.futures import ThreadPoolExecutor, as_completed
import time
# Windows UTF-8 fix
if sys.platform == 'win32':
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
class ShareVerifier:
"""Verifies accessibility of ChatGPT shares"""
def __init__(self, concurrent: int = 5, delay: float = 0.5):
self.concurrent = concurrent
self.delay = delay
self.results = {
"accessible": [],
"deleted": [],
"not_found": [],
"error": []
}
self.stats = {
"total_checked": 0,
"accessible": 0,
"deleted": 0,
"not_found": 0,
"error": 0,
"start_time": datetime.now().isoformat(),
"end_time": None
}
def verify_single_url(self, url: str) -> Dict:
"""Verify a single URL"""
result = {
"url": url,
"guid": self._extract_guid(url),
"status": None,
"category": None,
"checked_at": datetime.now().isoformat()
}
try:
# Use GET to check content, not just status
response = requests.get(
url,
allow_redirects=False,
timeout=10,
headers={'User-Agent': 'Mozilla/5.0 (Research Bot)'}
)
result["status"] = response.status_code
if response.status_code == 200:
# Check if content shows deletion message
is_deleted = (
"Can't load shared conversation" in response.text or
"Can't load shared conversation" in response.text
)
if is_deleted:
result["category"] = "deleted"
self.results["deleted"].append(result)
self.stats["deleted"] += 1
else:
result["category"] = "accessible"
self.results["accessible"].append(result)
self.stats["accessible"] += 1
elif response.status_code == 404:
result["category"] = "not_found"
self.results["not_found"].append(result)
self.stats["not_found"] += 1
else:
result["category"] = "error"
result["error"] = f"Unexpected status code: {response.status_code}"
self.results["error"].append(result)
self.stats["error"] += 1
except requests.Timeout:
result["category"] = "error"
result["error"] = "Timeout"
self.results["error"].append(result)
self.stats["error"] += 1
except requests.RequestException as e:
result["category"] = "error"
result["error"] = str(e)
self.results["error"].append(result)
self.stats["error"] += 1
self.stats["total_checked"] += 1
# Rate limiting delay
time.sleep(self.delay)
return result
def _extract_guid(self, url: str) -> str:
"""Extract GUID from ChatGPT share URL"""
if '/share/' in url:
guid = url.split('/share/')[-1].split('?')[0].split('/')[0]
if len(guid) == 36 and guid.count('-') == 4:
return guid
return None
def verify_urls(self, urls: List[str]) -> None:
"""Verify multiple URLs concurrently"""
total = len(urls)
print(f"π Verifying {total} URLs with {self.concurrent} concurrent connections...")
with ThreadPoolExecutor(max_workers=self.concurrent) as executor:
future_to_url = {executor.submit(self.verify_single_url, url): url for url in urls}
for i, future in enumerate(as_completed(future_to_url), 1):
result = future.result()
# Progress output
if i % 10 == 0 or i == total:
accessible = self.stats["accessible"]
deleted = self.stats["deleted"]
not_found = self.stats["not_found"]
errors = self.stats["error"]
print(f"Progress: {i}/{total} | "
f"β
{accessible} accessible | "
f"ποΈ {deleted} deleted | "
f"β {not_found} not found | "
f"β οΈ {errors} errors", end='\r')
print() # New line after progress
print(f"\nπ Verification Complete:")
print(f" β
Accessible: {self.stats['accessible']}")
print(f" ποΈ Deleted: {self.stats['deleted']}")
print(f" β Not Found: {self.stats['not_found']}")
print(f" β οΈ Errors: {self.stats['error']}")
def save_results(self, output_file: str) -> None:
"""Save verification results to JSON"""
self.stats["end_time"] = datetime.now().isoformat()
output_data = {
"stats": self.stats,
"results": self.results
}
output_path = Path(output_file)
with output_path.open('w', encoding='utf-8') as f:
json.dump(output_data, f, indent=2)
print(f"πΎ Results saved to {output_file}")
def export_accessible_guids(self, output_file: str) -> None:
"""Export only accessible GUIDs to text file"""
accessible_guids = [r["guid"] for r in self.results["accessible"] if r["guid"]]
if accessible_guids:
output_path = Path(output_file)
with output_path.open('w', encoding='utf-8') as f:
for guid in sorted(accessible_guids):
f.write(f"{guid}\n")
print(f"πΎ Exported {len(accessible_guids)} accessible GUIDs to {output_file}")
else:
print("β οΈ No accessible shares found to export")
def load_urls_from_file(file_path: str) -> List[str]:
"""Load URLs from text file"""
urls = []
with open(file_path, 'r', encoding='utf-8') as f:
for line in f:
line = line.strip()
if line and line.startswith('http'):
urls.append(line)
elif line and '-' in line and len(line) == 36:
# GUID format - convert to URL
urls.append(f"https://chatgpt.com/share/{line}")
return urls
def main():
parser = argparse.ArgumentParser(
description="Verify accessibility of ChatGPT share URLs",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
# Verify URLs from file
python verify_shares.py --input cdx_shares.txt --output results.json
# Verify with custom concurrency and delay
python verify_shares.py --input shares.txt --output results.json --concurrent 10 --delay 0.3
# Export only accessible GUIDs
python verify_shares.py --input shares.txt --output results.json --export-accessible accessible.txt
"""
)
parser.add_argument(
'--input',
required=True,
help='Input file containing URLs or GUIDs (one per line)'
)
parser.add_argument(
'--output',
default='verification_results.json',
help='Output JSON file for results (default: verification_results.json)'
)
parser.add_argument(
'--export-accessible',
help='Export accessible GUIDs to separate text file'
)
parser.add_argument(
'--concurrent',
type=int,
default=5,
help='Number of concurrent connections (default: 5)'
)
parser.add_argument(
'--delay',
type=float,
default=0.5,
help='Delay between requests in seconds (default: 0.5)'
)
args = parser.parse_args()
# Load URLs
print(f"π Loading URLs from {args.input}...")
urls = load_urls_from_file(args.input)
print(f"π Loaded {len(urls)} URLs")
if not urls:
print("β No URLs found in input file")
sys.exit(1)
# Verify
verifier = ShareVerifier(concurrent=args.concurrent, delay=args.delay)
verifier.verify_urls(urls)
# Save results
verifier.save_results(args.output)
# Export accessible GUIDs if requested
if args.export_accessible:
verifier.export_accessible_guids(args.export_accessible)
if __name__ == '__main__':
main()