Repository navigation
Expand file tree
/
Copy pathprocess_all.py
More file actions
75 lines (62 loc) · 2.15 KB
/
Copy pathprocess_all.py
File metadata and controls
75 lines (62 loc) · 2.15 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
#!/usr/bin/env python3
"""
Process all items until complete
Automatically runs summarize_with_gemini.py in a loop until all items have AI summaries
"""
import json
import os
import sys
import subprocess
import time
def count_remaining():
"""Count items without AI summaries"""
try:
with open('feed.json', 'r', encoding='utf-8') as f:
items = json.load(f)
return sum(1 for item in items if not item.get('ai_summary'))
except Exception as e:
print(f"Error reading feed.json: {e}")
return 0
def main():
# Check API key
api_key = os.environ.get("GEMINI_API_KEY")
if not api_key:
print("❌ GEMINI_API_KEY environment variable not set")
print(" Run: export GEMINI_API_KEY='your-api-key'")
sys.exit(1)
print("🤖 Automated processing of all feed items")
print("=" * 60)
iteration = 0
while True:
iteration += 1
remaining = count_remaining()
if remaining == 0:
print("\n" + "=" * 60)
print("✅ All items processed successfully!")
break
print(f"\n🔄 Iteration {iteration}: {remaining} items remaining")
print("-" * 60)
# Run summarize_with_gemini.py
try:
result = subprocess.run(
['python3', 'summarize_with_gemini.py'],
check=True,
capture_output=False
)
except subprocess.CalledProcessError as e:
print(f"\n⚠️ Error running summarize script: {e}")
print("Stopping automated processing")
sys.exit(1)
# Check if there are more items to process
new_remaining = count_remaining()
if new_remaining == remaining:
print("\n⚠️ No progress made in this iteration")
print("This might indicate an issue. Check the output above.")
break
if new_remaining > 0:
wait_time = 2 # Minimal wait between batches
print(f"\n⏳ Waiting {wait_time} seconds before next batch...")
time.sleep(wait_time)
print("\n🎉 Processing complete!")
if __name__ == "__main__":
main()