File size: 2,833 Bytes
a1d11a9
 
 
 
 
 
 
 
 
 
7d90b6b
 
 
ee75ec9
7d90b6b
 
 
 
 
 
 
fa36d82
7d90b6b
ee75ec9
7d90b6b
 
a1d11a9
fa36d82
a1d11a9
ee75ec9
7d90b6b
fa36d82
7d90b6b
 
 
a1d11a9
ee75ec9
 
 
 
 
 
 
 
 
 
 
a1d11a9
ee75ec9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
a1d11a9
 
 
 
ee75ec9
 
 
a1d11a9
ee75ec9
 
 
 
 
 
 
 
a1d11a9
 
 
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
76
77
78
79
80
81
82
83
"""
Run get/list operations and print results (no writes).
Run from backend:  python -m db.test_functions.query_data ***
Requires DATABASE_URL in backend/.env.
"""

import db


def run():
    print("=== list_mangas (default: newest first) ===\n")
    mangas = db.list_mangas()
    for m in mangas:
        print(f"  {m.manga_title}")
    print(f"\n  Total: {len(mangas)} manga(s)\n")

    if not mangas:
        print("No data. Run:  python -m db.test_functions.create_data")
        return

    first_manga = mangas[0]
    manga_title = first_manga.manga_title

    chapters = db.list_chapters(manga_title)
    if not chapters:
        print(f"No chapters for {manga_title}. Run create_data to add pages.")
        return
    chapter_number = chapters[0].chapter_number

    print(f"=== list_chapters({manga_title!r}) ===\n")
    for c in chapters[:5]:
        print(f"  ch.{c.chapter_number} (id={c.id})")
    if len(chapters) > 5:
        print(f"  ... and {len(chapters) - 5} more chapter(s)")
    print(f"\n  Total: {len(chapters)} chapter(s)\n")

    print(f"=== get_chapter_panels({manga_title!r}, {chapter_number}) ===\n")
    panels = db.get_chapter_panels(manga_title, chapter_number)
    for i, s in enumerate(panels[:5]):  # show first 5
        print(
            f"  [{i+1}] page {s.page_number} bubble {s.bubble_index}: "
            f"{s.original_text[:30]!r} → {s.translated_text[:30]!r} "
            f"(url={s.panel_url!r})"
        )
    if len(panels) > 5:
        print(f"  ... and {len(panels) - 5} more panel(s)")
    print(f"\n  Total: {len(panels)} panel(s) in chapter\n")

    if panels and panels[0].panel_url:
        url = panels[0].panel_url
        print(f"=== get_panel_by_panel_url({url!r}) ===\n")
        p = db.get_panel_by_panel_url(url)
        if p:
            print(
                f"  found: {p.manga_title} ch.{p.chapter_number} "
                f"page={p.page_number} bubble={p.bubble_index} url={p.panel_url!r}"
            )
        else:
            print("  not found")
        print()

    print(f"=== get_panels (manga_title={manga_title!r}, chapter_number={chapter_number}, page_number=1) ===\n")
    page_panels = db.get_panels(
        manga_title=manga_title,
        chapter_number=chapter_number,
        page_number=1,
    )
    for s in page_panels:
        print(f"  bubble {s.bubble_index}: {s.translated_text!r}")
    print(f"\n  Total: {len(page_panels)} panel(s) on page 1\n")

    print("=== get_panels (no filters: all panels) ===\n")
    all_panels = db.get_panels()
    for s in all_panels:
        print(
            f"  {s.manga_title} ch.{s.chapter_number} | {s.page_number} | "
            f"{s.bubble_index}: {s.translated_text!r} (url={s.panel_url!r})"
        )
    print(f"\n  Total: {len(all_panels)} panel(s)\n")

if __name__ == "__main__":
    run()