catime 0.2.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
catime/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """catime - AI-generated hourly cat images."""
2
+
3
+ __version__ = "0.2.0"
catime/cli.py ADDED
@@ -0,0 +1,127 @@
1
+ """CLI entry point for catime - view AI-generated hourly cats."""
2
+
3
+ import argparse
4
+ import json
5
+ import re
6
+ import sys
7
+ from datetime import datetime, timezone, timedelta
8
+ from pathlib import Path
9
+
10
+ import httpx
11
+
12
+ CATLIST_URL = "https://raw.githubusercontent.com/{repo}/main/catlist.json"
13
+ DEFAULT_REPO = "yazelin/catime"
14
+
15
+
16
+ def fetch_catlist(repo: str) -> list[dict]:
17
+ url = CATLIST_URL.format(repo=repo)
18
+ resp = httpx.get(url, follow_redirects=True)
19
+ resp.raise_for_status()
20
+ return resp.json()
21
+
22
+
23
+ def load_local_catlist() -> list[dict]:
24
+ p = Path(__file__).resolve().parent.parent.parent / "catlist.json"
25
+ if p.exists():
26
+ return json.loads(p.read_text())
27
+ return []
28
+
29
+
30
+ def print_cat(cat: dict, index: int | None = None):
31
+ """Print a single cat entry."""
32
+ num = cat.get("number") or index
33
+ status = cat.get("status", "success")
34
+ if status == "failed":
35
+ print(f"Cat #{num or '?':>4} [FAILED] {cat['timestamp']} error: {cat.get('error', '?')}")
36
+ else:
37
+ print(f"Cat #{num:>4} {cat['timestamp']} model: {cat.get('model', '?')}")
38
+ print(f" URL: {cat['url']}")
39
+
40
+
41
+ def filter_by_query(cats: list[dict], query: str) -> list[dict]:
42
+ """Filter cats by time query: date, date+hour, today, yesterday."""
43
+ now = datetime.now(timezone.utc)
44
+
45
+ if query == "today":
46
+ target_date = now.strftime("%Y-%m-%d")
47
+ return [c for c in cats if c["timestamp"].startswith(target_date)]
48
+
49
+ if query == "yesterday":
50
+ target_date = (now - timedelta(days=1)).strftime("%Y-%m-%d")
51
+ return [c for c in cats if c["timestamp"].startswith(target_date)]
52
+
53
+ # date+hour: 2026-01-30T05 or 2026-01-30 05
54
+ m = re.match(r"^(\d{4}-\d{2}-\d{2})[T ](\d{1,2})$", query)
55
+ if m:
56
+ date_str, hour_str = m.group(1), m.group(2).zfill(2)
57
+ prefix = f"{date_str} {hour_str}:"
58
+ return [c for c in cats if c["timestamp"].startswith(prefix)]
59
+
60
+ # date only: 2026-01-30
61
+ if re.match(r"^\d{4}-\d{2}-\d{2}$", query):
62
+ return [c for c in cats if c["timestamp"].startswith(query)]
63
+
64
+ return []
65
+
66
+
67
+ def main():
68
+ parser = argparse.ArgumentParser(
69
+ prog="catime",
70
+ description="View AI-generated hourly cat images",
71
+ )
72
+ parser.add_argument(
73
+ "query", nargs="?",
74
+ help="Cat number (e.g. 42), date (2026-01-30), date+hour (2026-01-30T05), 'today', or 'yesterday'.",
75
+ )
76
+ parser.add_argument("--repo", default=DEFAULT_REPO, help="GitHub repo owner/name")
77
+ parser.add_argument("--local", action="store_true", help="Use local catlist.json")
78
+ parser.add_argument("--list", action="store_true", help="List all cats")
79
+ args = parser.parse_args()
80
+
81
+ try:
82
+ cats = load_local_catlist() if args.local else fetch_catlist(args.repo)
83
+ except Exception as e:
84
+ print(f"Error loading cat list: {e}", file=sys.stderr)
85
+ sys.exit(1)
86
+
87
+ if not cats:
88
+ print("No cats yet! Check back in an hour.")
89
+ return
90
+
91
+ if args.list:
92
+ for i, cat in enumerate(cats, 1):
93
+ print_cat(cat, i)
94
+ return
95
+
96
+ if args.query is None:
97
+ print(f"Total cats: {len(cats)}")
98
+ print(f"Latest: #{len(cats):04d} {cats[-1]['timestamp']}")
99
+ print()
100
+ print("Usage:")
101
+ print(" catime 42 View cat #42")
102
+ print(" catime today List today's cats")
103
+ print(" catime yesterday List yesterday's cats")
104
+ print(" catime 2026-01-30 List all cats from a date")
105
+ print(" catime 2026-01-30T05 View the cat from a specific hour")
106
+ print(" catime --list List all cats")
107
+ return
108
+
109
+ # Try as number first
110
+ if args.query.isdigit():
111
+ idx = int(args.query) - 1
112
+ if idx < 0 or idx >= len(cats):
113
+ print(f"Cat #{args.query} not found. Available: 1-{len(cats)}", file=sys.stderr)
114
+ sys.exit(1)
115
+ print_cat(cats[idx], int(args.query))
116
+ return
117
+
118
+ # Try as time query
119
+ matched = filter_by_query(cats, args.query)
120
+ if not matched:
121
+ print(f"No cats found for '{args.query}'.", file=sys.stderr)
122
+ sys.exit(1)
123
+
124
+ print(f"Found {len(matched)} cat(s) for '{args.query}':\n")
125
+ for cat in matched:
126
+ print_cat(cat)
127
+ print()
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.4
2
+ Name: catime
3
+ Version: 0.2.0
4
+ Summary: AI-generated hourly cat images - a new cat every hour!
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.10
8
+ Requires-Dist: httpx
9
+ Description-Content-Type: text/markdown
10
+
11
+ # catime
12
+
13
+ AI-generated hourly cat images. A new cat every hour!
14
+
15
+ ## Usage
16
+
17
+ ```bash
18
+ uvx catime # Show total cat count
19
+ uvx catime 42 # View cat #42
20
+ uvx catime today # List today's cats
21
+ uvx catime yesterday # List yesterday's cats
22
+ uvx catime 2026-01-30 # List all cats from a date
23
+ uvx catime 2026-01-30T05 # View the cat from a specific hour
24
+ uvx catime --list # List all cats
25
+ ```
@@ -0,0 +1,7 @@
1
+ catime/__init__.py,sha256=f37KsktucfUui7NyCuEJRZT_WMFOIcUFCWao5y9wsyM,70
2
+ catime/cli.py,sha256=dDMYM6UvXQlDldni2rfQ70CsjUwIaQGPZj6Egcd4t8M,4243
3
+ catime-0.2.0.dist-info/METADATA,sha256=bfR_tARqCSml9MpfEOnZZnBUz1bMgGF3OTPSsX88GV8,665
4
+ catime-0.2.0.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
5
+ catime-0.2.0.dist-info/entry_points.txt,sha256=oPgi6h026vMo9YyEOH3wuNtD3A28e-s1ChJs-KWWGXw,43
6
+ catime-0.2.0.dist-info/licenses/LICENSE,sha256=p_h5YRMaNCwMqGXX5KDrk49_NWGpzAJ2d6IhKa67B0E,1064
7
+ catime-0.2.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.28.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ catime = catime.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 yazelin
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.