Neon-tech commited on
Commit
f39e4dd
·
verified ·
1 Parent(s): 34f0326

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -4
app.py CHANGED
@@ -134,10 +134,20 @@ async def process(state):
134
 
135
  print(f"Downloading msg {msg.id} — {msg.document.file_name} ({msg.document.file_size:,} bytes)")
136
 
137
- zip_bytes = io.BytesIO()
138
- async for chunk in app.stream_media(msg):
139
- zip_bytes.write(chunk)
140
- zip_bytes.seek(0)
 
 
 
 
 
 
 
 
 
 
141
 
142
  try:
143
  with zipfile.ZipFile(zip_bytes) as zf:
 
134
 
135
  print(f"Downloading msg {msg.id} — {msg.document.file_name} ({msg.document.file_size:,} bytes)")
136
 
137
+ for attempt in range(5):
138
+ try:
139
+ zip_bytes = io.BytesIO()
140
+ async for chunk in app.stream_media(msg):
141
+ zip_bytes.write(chunk)
142
+ zip_bytes.seek(0)
143
+ break
144
+ except Exception as e:
145
+ wait = 300 * (attempt + 1) # 5min, 10min, 15min, 20min, 25min
146
+ print(f" ⚠ Attempt {attempt + 1} failed: {e} — waiting {wait//60}min")
147
+ await asyncio.sleep(wait)
148
+ else:
149
+ print(f" ✗ Telegram unavailable after 25min — stopping")
150
+ return
151
 
152
  try:
153
  with zipfile.ZipFile(zip_bytes) as zf: