lint: fix bare except and unused variables

This commit is contained in:
2026-06-19 11:52:30 +02:00
parent df644219de
commit ac5beb831b
15 changed files with 1359 additions and 728 deletions
+24
View File
@@ -0,0 +1,24 @@
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.{yml,yaml}]
indent_size = 2
[*.{json,jsonc}]
indent_size = 2
[*.md]
trim_trailing_whitespace = false
[*.py]
indent_size = 4
[{Makefile,makefile}]
indent_style = tab
+10
View File
@@ -0,0 +1,10 @@
ignored:
- DL3008
- DL3042
- DL3018
- DL3059
trustedRegistries:
- docker.io
- ghcr.io
- quay.io
- gcr.forust.xyz
+8
View File
@@ -0,0 +1,8 @@
{
"default": true,
"MD013": false,
"MD024": false,
"MD033": false,
"MD041": false,
"MD046": false
}
+8
View File
@@ -0,0 +1,8 @@
bracketSameLine: true
htmlWhitespaceSensitivity: css
printWidth: 120
tabWidth: 2
singleQuote: true
trailingComma: all
proseWrap: preserve
endOfLine: lf
+34
View File
@@ -0,0 +1,34 @@
{
"[yaml]": {
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.formatOnSave": true,
"editor.defaultFormatter": "redhat.vscode-yaml"
},
"[python]": {
"editor.tabSize": 4,
"editor.formatOnSave": true,
"editor.defaultFormatter": "charliermarsh.ruff"
},
"[dockerfile]": {
"editor.formatOnSave": true,
"editor.defaultFormatter": "exiasr.hadolint"
},
"[markdown]": {
"editor.wordWrap": "wordWrapColumn",
"editor.wordWrapColumn": 120
},
"yaml.schemas": {
"kubernetes": ["**/k8s/*.yaml", "**/k8s/*.yml"]
},
"yaml.format.enable": true,
"yaml.validate": true,
"yaml.completion": true,
"prettier.bracketSameLine": true,
"prettier.htmlWhitespaceSensitivity": "css",
"prettier.printWidth": 120,
"editor.formatOnSave": true,
"files.autoSave": "onFocusChange",
"editor.wordWrapColumn": 120,
"editor.wordWrap": "wordWrapColumn"
}
+17
View File
@@ -0,0 +1,17 @@
extends: default
rules:
comments:
min-spaces-from-content: 1
comments-indentation: false
document-start: disable
line-length: disable
braces:
min-spaces-inside: 0
max-spaces-inside: 1
brackets:
min-spaces-inside: 0
max-spaces-inside: 1
indentation:
spaces: 2
indent-sequences: consistent
+39
View File
@@ -0,0 +1,39 @@
{
"tab_size": 2,
"soft_wrap": "prefer_line",
"preferred_line_length": 120,
"format_on_save": "on",
"languages": {
"YAML": {
"tab_size": 2,
"hard_tabs": false,
"format_on_save": "on",
"formatter": {
"language_server": { "name": "yaml-language-server" }
}
},
"Python": {
"tab_size": 4,
"format_on_save": "on",
"formatter": {
"language_server": { "name": "ruff" }
}
}
},
"lsp": {
"yaml-language-server": {
"settings": {
"yaml": {
"schemas": {
"kubernetes": ["**/k8s/*.yaml", "**/k8s/*.yml"]
},
"validate": true,
"completion": true,
"format": {
"enable": true
}
}
}
}
}
}
+6 -2
View File
@@ -57,7 +57,9 @@ class StateStore:
self.path.parent.mkdir(parents=True, exist_ok=True) self.path.parent.mkdir(parents=True, exist_ok=True)
tmp_path = self.path.with_suffix(self.path.suffix + ".tmp") tmp_path = self.path.with_suffix(self.path.suffix + ".tmp")
with tmp_path.open("w", encoding="utf-8") as handle: with tmp_path.open("w", encoding="utf-8") as handle:
json.dump(self._merge_defaults(state), handle, ensure_ascii=False, indent=2) json.dump(
self._merge_defaults(state), handle, ensure_ascii=False, indent=2
)
handle.write("\n") handle.write("\n")
tmp_path.replace(self.path) tmp_path.replace(self.path)
self._cache = None self._cache = None
@@ -71,7 +73,9 @@ class StateStore:
def continuous_config(self) -> Dict[str, Any]: def continuous_config(self) -> Dict[str, Any]:
state = self.load() state = self.load()
return dict(state.get("continuous_scraping") or DEFAULT_STATE["continuous_scraping"]) return dict(
state.get("continuous_scraping") or DEFAULT_STATE["continuous_scraping"]
)
def save_continuous_config(self, config: Dict[str, Any]) -> Dict[str, Any]: def save_continuous_config(self, config: Dict[str, Any]) -> Dict[str, Any]:
def mutate(state: Dict[str, Any]) -> None: def mutate(state: Dict[str, Any]) -> None:
+6
View File
@@ -10,6 +10,12 @@ services:
tty: true tty: true
ports: ports:
- "7887:8080" - "7887:8080"
healthcheck:
test: ["CMD", "python", "-c", "import http.client,json;c=http.client.HTTPConnection('localhost',8080);c.request('GET','/health');r=c.getresponse();exit(0)if json.loads(r.read()).get('ok')else exit(1)"]
interval: 30s
timeout: 10s
retries: 3
start_period: 15s
volumes: volumes:
- ./data:/app/data - ./data:/app/data
- ./session:/app/session - ./session:/app/session
+12
View File
@@ -38,6 +38,18 @@ spec:
stdin: true stdin: true
ports: ports:
- containerPort: 8080 - containerPort: 8080
livenessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 15
periodSeconds: 30
readinessProbe:
httpGet:
path: /health
port: 8080
initialDelaySeconds: 5
periodSeconds: 10
volumeMounts: volumeMounts:
- name: telegram-scraper-data - name: telegram-scraper-data
mountPath: /app/data mountPath: /app/data
+2 -1
View File
@@ -41,7 +41,8 @@ class ScraperJobService:
) )
elif job_type == "scrape_selected": elif job_type == "scrape_selected":
await self._scrape_channels( await self._scrape_channels(
scraper, [str(channel_id) for channel_id in payload.get("channels", [])] scraper,
[str(channel_id) for channel_id in payload.get("channels", [])],
) )
elif job_type == "export_all": elif job_type == "export_all":
await scraper.export_data() await scraper.export_data()
+5 -1
View File
@@ -60,7 +60,11 @@ def main() -> int:
status, body = fetch(endpoint) status, body = fetch(endpoint)
if status != 200: if status != 200:
raise RuntimeError(f"{endpoint} returned HTTP {status}") raise RuntimeError(f"{endpoint} returned HTTP {status}")
if endpoint.endswith(".json") or endpoint.startswith("/api") or endpoint.startswith("/health"): if (
endpoint.endswith(".json")
or endpoint.startswith("/api")
or endpoint.startswith("/health")
):
json.loads(body.decode("utf-8")) json.loads(body.decode("utf-8"))
print(f"ok {endpoint}") print(f"ok {endpoint}")
return 0 return 0
+426 -250
View File
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+35 -13
View File
@@ -306,7 +306,9 @@ class JobRunner:
if job.status == "running": if job.status == "running":
running_jobs.append(job) running_jobs.append(job)
if running_jobs: if running_jobs:
logger.warning("Waiting for %d running job(s) to finish...", len(running_jobs)) logger.warning(
"Waiting for %d running job(s) to finish...", len(running_jobs)
)
deadline = time.time() + timeout deadline = time.time() + timeout
while time.time() < deadline: while time.time() < deadline:
with self.lock: with self.lock:
@@ -561,6 +563,7 @@ class TelegramAuthManager:
async def _disconnect(): async def _disconnect():
if self.client: if self.client:
await self.client.disconnect() await self.client.disconnect()
if self.client: if self.client:
try: try:
future = asyncio.run_coroutine_threadsafe(_disconnect(), self.loop) future = asyncio.run_coroutine_threadsafe(_disconnect(), self.loop)
@@ -831,7 +834,10 @@ def openapi_payload() -> Dict[str, Any]:
"requestBody": json_body( "requestBody": json_body(
{ {
"api_id": {"type": "integer", "example": 123456}, "api_id": {"type": "integer", "example": 123456},
"api_hash": {"type": "string", "example": "0123456789abcdef"}, "api_hash": {
"type": "string",
"example": "0123456789abcdef",
},
}, },
["api_id", "api_hash"], ["api_id", "api_hash"],
), ),
@@ -929,7 +935,11 @@ def openapi_payload() -> Dict[str, Any]:
{ {
"name": "limit", "name": "limit",
"in": "query", "in": "query",
"schema": {"type": "integer", "default": 120, "maximum": 300}, "schema": {
"type": "integer",
"default": 120,
"maximum": 300,
},
}, },
{ {
"name": "before", "name": "before",
@@ -945,7 +955,10 @@ def openapi_payload() -> Dict[str, Any]:
"summary": "Track a channel", "summary": "Track a channel",
"requestBody": json_body( "requestBody": json_body(
{ {
"channel_id": {"type": "string", "example": "-1001234567890"}, "channel_id": {
"type": "string",
"example": "-1001234567890",
},
"name": {"type": "string", "example": "Research feed"}, "name": {"type": "string", "example": "Research feed"},
}, },
["channel_id"], ["channel_id"],
@@ -990,7 +1003,10 @@ def openapi_payload() -> Dict[str, Any]:
"schema": {"type": "string"}, "schema": {"type": "string"},
} }
], ],
"responses": {**json_response, "404": {"description": "Job not found"}}, "responses": {
**json_response,
"404": {"description": "Job not found"},
},
} }
}, },
"/api/jobs/scrape": { "/api/jobs/scrape": {
@@ -1416,15 +1432,18 @@ class TelegramScraperRequestHandler(BaseHTTPRequestHandler):
try: try:
start, end = self._parse_range(range_header, file_size) start, end = self._parse_range(range_header, file_size)
except ValueError: except ValueError:
self.send_error_json(HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE, "Invalid range") self.send_error_json(
HTTPStatus.REQUESTED_RANGE_NOT_SATISFIABLE, "Invalid range"
)
return return
content_length = end - start + 1 content_length = end - start + 1
self.send_response(HTTPStatus.PARTIAL_CONTENT) self.send_response(HTTPStatus.PARTIAL_CONTENT)
self.send_header("Content-Type", content_type) self.send_header("Content-Type", content_type)
self.send_header("Accept-Ranges", "bytes") self.send_header("Accept-Ranges", "bytes")
self.send_header("Last-Modified", time.strftime( self.send_header(
"%a, %d %b %Y %H:%M:%S GMT", time.gmtime(last_modified) "Last-Modified",
)) time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(last_modified)),
)
self.send_header("Content-Range", f"bytes {start}-{end}/{file_size}") self.send_header("Content-Range", f"bytes {start}-{end}/{file_size}")
self.send_header("Content-Length", str(content_length)) self.send_header("Content-Length", str(content_length))
self.end_headers() self.end_headers()
@@ -1434,9 +1453,10 @@ class TelegramScraperRequestHandler(BaseHTTPRequestHandler):
self.send_response(HTTPStatus.OK) self.send_response(HTTPStatus.OK)
self.send_header("Content-Type", content_type) self.send_header("Content-Type", content_type)
self.send_header("Accept-Ranges", "bytes") self.send_header("Accept-Ranges", "bytes")
self.send_header("Last-Modified", time.strftime( self.send_header(
"%a, %d %b %Y %H:%M:%S GMT", time.gmtime(last_modified) "Last-Modified",
)) time.strftime("%a, %d %b %Y %H:%M:%S GMT", time.gmtime(last_modified)),
)
self.send_header("Content-Length", str(file_size)) self.send_header("Content-Length", str(file_size))
self.end_headers() self.end_headers()
if not head_only: if not head_only:
@@ -1495,7 +1515,9 @@ class TelegramScraperWebServer(ThreadingHTTPServer):
self.job_runner = JobRunner() self.job_runner = JobRunner()
self.auth_manager = TelegramAuthManager() self.auth_manager = TelegramAuthManager()
self.continuous_manager = ContinuousScrapeManager() self.continuous_manager = ContinuousScrapeManager()
if START_CONTINUOUS and self.continuous_manager.snapshot()["config"].get("enabled", True): if START_CONTINUOUS and self.continuous_manager.snapshot()["config"].get(
"enabled", True
):
self.continuous_manager.start() self.continuous_manager.start()