93 lines
2.7 KiB
Python
93 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
run.py — entrypoint for HF Daily Paper RSS generation.
|
|
|
|
Generates:
|
|
- Daily feed (always)
|
|
- Weekly feed (every Monday)
|
|
- Monthly feed (1st of month)
|
|
|
|
Usage:
|
|
python run.py # output to ./feeds/
|
|
python run.py --output-dir /data/feeds
|
|
python run.py --date 2026-06-27 # simulate date
|
|
"""
|
|
import argparse
|
|
import datetime
|
|
import os
|
|
import subprocess
|
|
import sys
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="HF Daily Paper RSS Generator")
|
|
parser.add_argument("--output-dir", default=os.path.join(os.getcwd(), "feeds"),
|
|
help="Directory to save RSS feeds")
|
|
parser.add_argument("--date", default=None,
|
|
help="Simulate a specific date (YYYY-MM-DD)")
|
|
args = parser.parse_args()
|
|
|
|
output_dir = os.path.abspath(args.output_dir)
|
|
os.makedirs(output_dir, exist_ok=True)
|
|
|
|
# Resolve date
|
|
if args.date:
|
|
today = datetime.date.fromisoformat(args.date)
|
|
else:
|
|
today = datetime.date.today()
|
|
|
|
year = today.year
|
|
month = f"{today.month:02d}"
|
|
week_num = today.isocalendar()[1]
|
|
is_monday = today.isoweekday() == 1
|
|
is_first = today.day == 1
|
|
|
|
script_dir = os.path.dirname(os.path.abspath(__file__))
|
|
parser_py = os.path.join(script_dir, "parser.py")
|
|
|
|
print(f"[run.py] Date: {today.isoformat()} "
|
|
f"(Year={year} Month={month} Week={week_num} "
|
|
f"Mon={is_monday} First={is_first})")
|
|
print(f"[run.py] Output: {output_dir}")
|
|
|
|
def run_parser(source, outfile):
|
|
full_path = os.path.join(output_dir, outfile)
|
|
print(f"\n── Generating {outfile} ──")
|
|
result = subprocess.run(
|
|
[sys.executable, parser_py, "--source", source, "--output", full_path],
|
|
capture_output=False, text=True, cwd=script_dir,
|
|
)
|
|
return result.returncode
|
|
|
|
# 1. Daily (always)
|
|
run_parser("https://huggingface.co/papers", "feed.xml")
|
|
|
|
# 2. Weekly (Mondays)
|
|
if is_monday:
|
|
run_parser(
|
|
f"https://huggingface.co/papers/week/{year}-W{week_num}",
|
|
"feed_weekly.xml",
|
|
)
|
|
else:
|
|
print("[run.py] Skipping weekly (not Monday)")
|
|
|
|
# 3. Monthly (1st)
|
|
if is_first:
|
|
run_parser(
|
|
f"https://huggingface.co/papers/month/{year}-{month}",
|
|
"feed_monthly.xml",
|
|
)
|
|
else:
|
|
print("[run.py] Skipping monthly (not 1st)")
|
|
|
|
print(f"\n[run.py] ✅ Done — feeds in {output_dir}")
|
|
for f in sorted(os.listdir(output_dir)):
|
|
if f.endswith(".xml"):
|
|
fpath = os.path.join(output_dir, f)
|
|
size = os.path.getsize(fpath)
|
|
print(f" {f} ({size:,} bytes)")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|