mirror of
https://github.com/harivansh-afk/nix.git
synced 2026-04-15 01:00:31 +00:00
wallpaper
This commit is contained in:
parent
29cffdc0fb
commit
010831e0c9
2 changed files with 19 additions and 8 deletions
|
|
@ -19,14 +19,16 @@ let
|
|||
close = 12;
|
||||
balanced = 11;
|
||||
wide = 10;
|
||||
ultrawide = 9;
|
||||
};
|
||||
densityPresets = {
|
||||
sparse = 14;
|
||||
balanced = 20;
|
||||
dense = 28;
|
||||
packed = 40;
|
||||
};
|
||||
view = "balanced";
|
||||
density = "balanced";
|
||||
view = "wide";
|
||||
density = "dense";
|
||||
candidatePool = {
|
||||
maxCached = 24;
|
||||
randomAttempts = 20;
|
||||
|
|
@ -55,7 +57,7 @@ let
|
|||
};
|
||||
label = label;
|
||||
view = {
|
||||
tileConcurrency = 6;
|
||||
tileConcurrency = 3;
|
||||
zoom = viewPresets.${view};
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ import os
|
|||
import random
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import urllib.request
|
||||
from datetime import datetime
|
||||
from io import BytesIO
|
||||
|
|
@ -254,11 +255,19 @@ def lat_lon_to_tile(lat: float, lon: float, zoom: int) -> tuple[int, int]:
|
|||
|
||||
def fetch_tile(z: int, x: int, y: int) -> Image.Image:
|
||||
url = TILE_URL.format(z=z, x=x, y=y)
|
||||
req = urllib.request.Request(url, headers={"User-Agent": "wallpaper-gen/1.0"})
|
||||
with urllib.request.urlopen(req, timeout=15) as resp:
|
||||
tile = Image.open(BytesIO(resp.read()))
|
||||
tile.load()
|
||||
return tile
|
||||
for attempt in range(4):
|
||||
try:
|
||||
req = urllib.request.Request(url, headers={"User-Agent": "wallpaper-gen/1.0"})
|
||||
with urllib.request.urlopen(req, timeout=15) as resp:
|
||||
tile = Image.open(BytesIO(resp.read()))
|
||||
tile.load()
|
||||
return tile
|
||||
except (ConnectionResetError, urllib.error.URLError) as err:
|
||||
if attempt == 3:
|
||||
raise
|
||||
delay = 0.5 * (2 ** attempt)
|
||||
log(f"tile retry z={z} x={x} y={y} attempt={attempt + 1} delay={delay:.1f}s err={err!r}")
|
||||
time.sleep(delay)
|
||||
|
||||
|
||||
def fetch_tile_task(task: TileTask) -> tuple[int, int, Image.Image]:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue