-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathdex.py
More file actions
59 lines (47 loc) · 1.9 KB
/
dex.py
File metadata and controls
59 lines (47 loc) · 1.9 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
#!/usr/bin/env python3
"""
Backward compatibility script that maintains the original dex.py interface.
This allows existing users to run `python dex.py` as before while using the new DexScraper.
"""
import asyncio
import sys
from dexscraper import DexScraper
async def main() -> None:
"""Run with the original interface for backward compatibility."""
print("🚀 DexScraper - Backward Compatibility Mode")
print("📡 Starting real-time token extraction...")
scraper = DexScraper(debug=True) # Enable debug by default like original
# Stream tokens using the new extraction method
async def stream_tokens() -> None:
while True:
try:
batch = await scraper.extract_token_data()
if batch.tokens:
# Output in original JSON format
import json
import time
output = {
"type": "tokens",
"extracted": batch.total_extracted,
"high_confidence": batch.high_confidence_count,
"tokens": [
token.to_dict() for token in batch.get_top_tokens(10)
],
"timestamp": int(time.time()),
}
print(json.dumps(output, separators=(",", ":"), default=str))
# Wait between extractions (similar to original streaming)
await asyncio.sleep(5)
except Exception as e:
print(f"Extraction error: {e}", file=sys.stderr)
await asyncio.sleep(10)
await stream_tokens()
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\nStopped by user", file=sys.stderr)
sys.exit(0)
except Exception as e:
print(f"Error: {e}", file=sys.stderr)
sys.exit(1)