47 lines
1.6 KiB
Python
47 lines
1.6 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Scan the local recipe folder for new Excel files and extract recipes.
|
|
Run periodically (e.g., weekly) to find new content to add to the calculator.
|
|
|
|
Usage:
|
|
python3 scripts/scan-recipes-folder.py
|
|
|
|
It will:
|
|
1. Read all .xlsx files in the recipe folder
|
|
2. Compare with existing recipes in the API
|
|
3. Report any new recipes found
|
|
4. Optionally upload them (with --upload flag)
|
|
"""
|
|
import os
|
|
import sys
|
|
import json
|
|
import argparse
|
|
|
|
RECIPE_FOLDER = os.path.expanduser("~/Hera DOCS/Essential Oil/商业和公司/成本和配方")
|
|
API_BASE = "https://oil.oci.euphon.net"
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description="Scan recipe folder for new content")
|
|
parser.add_argument("--upload", action="store_true", help="Upload new recipes to API")
|
|
parser.add_argument("--token", help="Admin API token")
|
|
args = parser.parse_args()
|
|
|
|
print(f"📁 Scanning: {RECIPE_FOLDER}")
|
|
if not os.path.isdir(RECIPE_FOLDER):
|
|
print(f" Folder not found!")
|
|
return
|
|
|
|
files = [f for f in os.listdir(RECIPE_FOLDER) if f.endswith('.xlsx') and not f.startswith('~$')]
|
|
print(f" Found {len(files)} Excel files:")
|
|
for f in files:
|
|
mtime = os.path.getmtime(os.path.join(RECIPE_FOLDER, f))
|
|
from datetime import datetime
|
|
print(f" - {f} (modified: {datetime.fromtimestamp(mtime).strftime('%Y-%m-%d %H:%M')})")
|
|
|
|
print(f"\n💡 To add recipes from these files, use the web UI's '智能粘贴' feature")
|
|
print(f" or manually add them via the API.")
|
|
print(f"\n🔗 Admin URL: {API_BASE}/?token=<your-token>")
|
|
|
|
if __name__ == "__main__":
|
|
main()
|