"""Обновить заголовки/текст уже сохранённых tg-записей по свежему парсу. python tools/fixtg.py ab_t_me,tg_leakbase,... """ import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).resolve().parent.parent)) from omni import feeds, sources, store # noqa: E402 def main(): want = set((sys.argv[1] if len(sys.argv) > 1 else "").split(",")) al = [s for s in sources.all_sources() if s.name in want] total = 0 for src in al: items = feeds.fetch(src) c = store.conn() upd = 0 for it in items: cur = c.execute("SELECT id,title FROM items WHERE url=?", (it.url,)).fetchone() if cur and (cur[1] or "") != (it.title or ""): c.execute("UPDATE items SET title=?, text=? WHERE id=?", (it.title, it.text, cur[0])) upd += 1 c.commit() c.close() total += upd print(f" {src.name:16} записей {len(items):>3} обновлено {upd:>3}") print("всего обновлено", total) if __name__ == "__main__": main()