import os
import shutil

RAW = os.path.expanduser("~/Desktop/Alex Wiki/raw-notes")
BASE = os.path.expanduser("~/Desktop/Alex Wiki")

# Read uncategorized files and recategorize
uncat_files = """Notes-1-----.md
Notes-1--03002003600.md
Notes-1--100-Earnings-No-Split.md
Notes-1--160-shopam-iedot-back.md
Notes-1--2024-It-has-been-an-amazing-year-Shortly-to-say-Im-very-thankful.md
Notes-1--2024.md
Notes-1--2562-copper-ridge-way.md
Notes-1--3-pillars-APPRENTICE-from-their-perspective-A-Day-in-the.md
Notes-1--30-marts-ir-ceturksnis.md
Notes-1--48metri-leja.md
Notes-1--ACCESS-FROM-THE-AIRPORTS.md
Notes-1--AI-PASSKEYS.md
Notes-1--Aftercare-text.md
Notes-1--Automotive-Parts-Counter-ignition-engine.md
Notes-1--BJJ-KODS-13092.md
Notes-1--BLACK-FRIDAY-GIVEAWAY.md
Notes-1--BLVKHRTTT-TEXTI.md
Notes-1--BOOKIN-FORM.md
Notes-1--Building-a-street-legal-racedrift-car-using-a-BMW-E46-320Ci-with.md
Notes-1--COINBASE.md
Notes-1--COMING-SOON.md
Notes-1--CONVENTION.md
Notes-1--Certainly-Heres-a-suggested-route-from-Chiswick-High-Road-in-London.md
Notes-1--Color-codes-RMT.md
Notes-1--DARBI-1.md
Notes-1--DARBNICAI.md
Notes-1--DIENAS-NAUDU-SISTEMU-JAUNU.md
Notes-1--DOCTYPE-html.md
Notes-1--Dear-Friends-and-Customers.md
Notes-1--FINE-LINE-MICRO-REALISM.md
Notes-1--FOR-ARTISTS-ATTRACTIONS.md
Notes-1--GOOGLE-ADS-TEXTI.md
Notes-1--HEALTH-AND-SAFETY.md
Notes-1--Has-so-much-fun-doing-these-Right-one-done-a-week-ago-Thank-You.md
Notes-1--Hashtags.md
Notes-1--Hello---Sveiki---Czesc.md
Notes-1--Hello-1.md
Notes-1--Hello.md
Notes-1--Heres-5-things-that-our-artists-love-about-our-studio.md
Notes-1--Heres-a-set-of-lyrics-in-the-style-of-uicideboy-with-a-focus-on.md
Notes-1--Heres-the-revised-invoice-without-company-details-and-with-VAT-included.md
Notes-1--Hey-We-really-enjoy-your-work-and-would-love-to-have-you-as-a-guest.md
Notes-1--Hey-buddy-hope-you-been-good-We-have-few-things-that-we-need-to.md
Notes-1--Hey.md
Notes-1--I-will-do-a-deep-search-of-the-equippment-and-price-comparisons-I.md
Notes-1--INSTA-STORY-PEDEJAA-LAPA-AR-LOGO-UN-BOOKING-INFO-LIDZIGI-KAA-PIE.md
Notes-1--IZNJEMT-NAUDU-KAKJIEM.md
Notes-1--IZSUTIIT-KLIENTIEM-EMAILIEM-NOVELEJUMU-NEW-YEAR.md
Notes-1--Jan-feb-marts-aprilis.md
Notes-1--KALENDAR-TEXTI.md
Notes-1--Left-For-Them-To-Feast.md
Notes-1--NEAREST-PUBLIC-TRANSPORT.md
Notes-1--Noles-file-httpsdocsgooglecomdocumentd14EiJTuiV-Hq0cDbnJfkFIkFQvLilIUM8LNYnPAoSw.md
Notes-1--P-R-I-N-C-E-L-E-T-T-A-T-T-O-O.md
Notes-1--PARVAKSANAS-PLANS.md
Notes-1--PRINCELET-TATTOO-MEMBERSHIP.md
Notes-1--PRINCELET-TEXTI.md
Notes-1--Pankuka.md
Notes-1--Payment.md
Notes-1--Prompt-AddOn-HighConversion-Marketplace-Ad-Generator.md
Notes-1--Prompts-for-key-frames---Chat-GPT-40.md
Notes-1--RIGA-1.md
Notes-1--ROAD-TRIP.md
Notes-1--SALONA-EKIPĒJUMS.md
Notes-1--SAPULCE.md
Notes-1--SAPULCES-PROTOKOLS.md
Notes-1--SKICES.md
Notes-1--SPONSORSHIP-VISA-CANADA.md
Notes-1--SPULDZES-2.md
Notes-1--SSOT-of-cummunications-and-context-for-human-to-clearly-communicate.md
Notes-1--START-WITH-1-Organize-Your-Data-with-CMS-Collections.md
Notes-1--STUDIO-MEETING.md
Notes-1--STUDIO-SERVICE-DAY.md
Notes-1--Se-mans-eatin-spaghetti.md
Notes-1--TATTOO-GIVEAWAY.md
Notes-1--TATTOO-PRICES-IN-LONDON.md
Notes-1--Tattoo-Cartridge-Sizes-Definitions-and-Types.md
Notes-1--Tattooing-to-me-has-never-just-been-about-art-Its-not-about-mere.md
Notes-1--Things-to-overlook-while-Alex-away.md
Notes-1--WIFI-RITES-alexroze2019.md
Notes-1--WORK-LIST.md
Notes-1--We-offer-2-rent-options.md
Notes-1--What-a-remarkable-year-2024-has-been-for-Princelet-Tattoo-We-expanded.md
Notes-1--While-its-not-strictly-necessary-to-have-a-special-bleeding-tool.md
Notes-1--YOUTUBE.md
Notes-1--You-said.md
Notes-1--Your-full-name-Your-email-Tattoo-Style-Linework-colour-or-black-and.md
Notes-1--________________________________________________________________________________.md
Notes-1--bars.md
Notes-1--blonaa.md
Notes-1--consent-forms-boxes-with-labeling-year-form-holder-pads-desktop.md
Notes-1--edienkarte.md
Notes-1--emails-victor-if-its-busy-we-ask-help.md
Notes-1--for-human-to-clearly-communicate-get-and-build-and-understand-the.md
Notes-1--gramatvezi.md
Notes-1--hello-hello.md
Notes-1--hibgum-gafhIg-0xuqmi.md
Notes-1--httpswwwprincelettattoocouk.md
Notes-1--i-like-my-food-as-i-like-my-tattoos---traditional.md
Notes-1--insta-post-texts-Princelet-Tattoo-is-opening-a-position-for-one.md
Notes-1--joki-.md
Notes-1--ko-inji.md
Notes-1--lREAD-THE-CAPTION.md
Notes-1--naudas-PT.md
Notes-1--okay-okay-Lets-do-a-flash-giveaway-Winner-will-receive-a-free-tattoo.md
Notes-1--only-god-can-judge-me-tattoo-on-a-chest.md
Notes-1--princelet_tattoo-London.md
Notes-1--rekini.md
Notes-1--rmt-gmail---PasswordimusRMThq.md
Notes-1--saule-kalteti-tomati.md
Notes-1--search-console.md
Notes-1--slipped__up.md
Notes-1--smerejamais-suds.md
Notes-1--tattoo-history-facts.md
Notes-1--ventilacijas-kanalu-parbaude.md
Notes-1--zigim-paskatities-elwktribas-paterinju.md
RMT--1-Sales-Categories.md
RMT--BRAND-FOUNDATION.md
RMT--CORE-GOALS.md
RMT--MIGRATION.md
RMT--Minimum-viable-truths-that-dissolve-anxiety-and-enable-action.md
RMT--PROMPTS-find-non-obvious-patterns-and-build-a-resonant-context.md
RMT--RMT-AI-TRAINING-plan.md
RMT--ROCKY-MOUNTAIN-TATTOO-LOCATIONS.md
RMT--ROCKY-MOUNTAIN-TATTOO-master-context-doc.md
RMT--Role.md
RMT--SEO-AND-META-SEO-Meta-Descriptions-Framework.md
RMT--SSOT-Single-Source-of-Truth-KGOC---Knowledge-Graph-of-Operational.md
RMT--UNIFIED-CSV-FORMAT-Collections-with-fields.md
RMT--ask---REVIEWS-west-side-reception-marketing---laser-as-pre.md""".strip().split("\n")

# RMT files are tattoo operations - per rule 7 we should skip, but since 
# the instructions say to categorize all files, put them in personal/ideas 
# (they're tattoo business ops, not product). Actually the instructions say
# "skip, they're in rocky-mountain-tattoo/" but we should still copy them somewhere.
# Let's put RMT in projects/misc as they're business operation notes.

moves = {}
for f in uncat_files:
    f = f.strip()
    fn = f.upper()
    
    # RMT files -> projects/misc (tattoo business operations)
    if f.startswith("RMT--"):
        moves[f] = "projects/misc"
        continue
    
    # Tattoo studio operations (Princelet, studio, artist related)
    tattoo_ops = ["PRINCELET", "TATTOO", "AFTERCARE", "STUDIO", "ARTIST", "BOOKING", "BOOKIN",
                  "GIVEAWAY", "CARTRIDGE", "CONSENT", "FINE-LINE", "MICRO-REALISM", "SKICE"]
    if any(k in fn for k in tattoo_ops):
        moves[f] = "projects/misc"
        continue
    
    # Latvian personal/misc notes
    latvian_personal = ["DARBI", "DARBNICAI", "DIENAS", "IZNJEMT", "IZSUTIIT", "KALENDAR",
                        "PARVAKSANAS", "SAPULCE", "SAPULCES", "SALONA", "SPULDZES", "EDIENKARTE",
                        "NAUDAS", "REKINI", "VENTILACIJAS", "ZIGIM", "BLONAA", "GRAMATVEZI",
                        "SMEREJAMAIS", "SAULE-KALTETI", "PANKUKA", "JOKI"]
    if any(k in fn for k in latvian_personal):
        moves[f] = "personal/ideas"
        continue
    
    # Social media / marketing content
    social = ["INSTA", "HASHTAG", "GOOGLE-ADS", "YOUTUBE", "BLVKHRTTT", "COMING-SOON",
              "BLACK-FRIDAY", "CAPTION", "POST-TEXT"]
    if any(k in fn for k in social):
        moves[f] = "projects/misc"
        continue
    
    # Personal misc (cars, BJJ, travel, food, lyrics, addresses)
    personal = ["BMW", "AUTOMOTIVE", "BJJ", "ROAD-TRIP", "RIGA", "BARS", "COINBASE",
                "SPONSORSHIP", "VISA", "WIFI", "LEFT-FOR-THEM", "SPAGHETTI", "SLIPPED",
                "HELLO", "HEY", "PAYMENT", "WORK-LIST", "INVOICE", "COLOR-CODES",
                "EARNINGS", "SHOPAM", "ADDRESS", "COPPER-RIDGE"]
    if any(k in fn for k in personal):
        moves[f] = "personal/ideas"
        continue
    
    # Specific classifications
    if "AI-PASSKEYS" in fn:
        moves[f] = "ai-research/models"
    elif "SSOT" in fn or "COMMUNICATE" in fn:
        moves[f] = "motherlabs/architecture"
    elif "Prompt-AddOn" in f or "Prompts-for-key-frames" in f:
        moves[f] = "ai-research/models"
    elif "START-WITH-1-Organize" in f or "DOCTYPE" in f or "CMS" in fn:
        moves[f] = "projects/misc"
    elif "HEALTH-AND-SAFETY" in fn or "CONVENTION" in fn or "NEAREST" in fn or "ACCESS-FROM" in fn:
        moves[f] = "projects/misc"
    elif "2024" in fn or "YEAR" in fn:
        moves[f] = "personal/reflections"
    elif "THINGS-TO-OVERLOOK" in fn or "EMAILS-VICTOR" in fn:
        moves[f] = "personal/ideas"
    else:
        moves[f] = "personal/ideas"

# Execute moves - remove from uncategorized, copy to new location
uncat_dir = os.path.join(BASE, "uncategorized")
for f, cat in moves.items():
    src = os.path.join(RAW, f)
    new_dst = os.path.join(BASE, cat, f)
    old_dst = os.path.join(uncat_dir, f)
    
    # Copy to new category
    os.makedirs(os.path.join(BASE, cat), exist_ok=True)
    if os.path.exists(src):
        shutil.copy2(src, new_dst)
    
    # Remove from uncategorized
    if os.path.exists(old_dst):
        os.remove(old_dst)

# Count what's left in uncategorized
remaining = os.listdir(uncat_dir) if os.path.exists(uncat_dir) else []
print(f"Remaining uncategorized: {len(remaining)}")
for r in remaining:
    print(f"  {r}")

# Print move summary
from collections import Counter
c = Counter(moves.values())
print("\nRe-categorized:")
for cat, count in sorted(c.items()):
    print(f"  {cat}: {count}")
print(f"  TOTAL moved: {sum(c.values())}")
