Skip to content

Instantly share code, notes, and snippets.

@ggorlen
Created September 13, 2020 23:29
Show Gist options
  • Select an option

  • Save ggorlen/0e6e80b6187c3ded09a423fc348950aa to your computer and use it in GitHub Desktop.

Select an option

Save ggorlen/0e6e80b6187c3ded09a423fc348950aa to your computer and use it in GitHub Desktop.
keeps my ebooks nicely organized
"""
keeps my ebooks nicely organized
"""
import os
import re
categories = {
"computer architecture": ["architecture", "computer architecture"],
"ai": ["machine learning", "big data", "convolutional", "neural", "artificial", "intelligence"],
"algorithms": ["algorithms", "data structures", "interview", "algorithmic", "algorithm"],
"apache": ["apache", "hadoop"],
"assembly": ["assembly", "assembler"],
"c": ["c ", " c"],
"chess": ["chess"],
"cobol": ["cobol"],
"cpp": ["c++", "cpp"],
"c#": ["c#", "csharp", "sharp"],
"compilers": ["interpreters", "parsers", "lexers", "lexical", "parser", "compiler", "compilers", "llvm"],
"cryptography": ["coding theory", "cryptography", "encryption", "cryptanalysis"],
"cs": ["computational", "computation", "computer science", "software design", "cs", "software engineering"],
"dsp": ["dsp", "synthesis", "audio"],
"emacs": ["emacs"],
"game_programming": ["game"],
"git": ["git", "github", "version control"],
"graphics": ["ray", "raytracing", "graphics", "processing"],
"security": ["hacking", "hackers", "hacker's", "penetration", "pentesting", "exploit", "exploits", "exploitation", "reverse engineering", "security"],
"java": ["java"],
"js": ["js", "json", "javascript", "html5", "node", "nodejs", "jquery", "d3", "html", "css", "full stack", "coffeescript"],
"llvm": ["llvm"],
"math": ["algebra", "algebraic", "statistics", "statistical", "geometry", "trigonometry", "trigonometric", "number", "math", "mathematics", "discrete"],
"perl": ["perl"],
"php": ["php"],
"processing": ["processing"],
"regex": ["regular expression", "regular expressions", "regex"],
"ruby": ["rails", "ruby", "sinatra"],
"functional": ["scala", "functional", "erlang", "f#", "haskell", "elixir", "lisp", "clojure", "ocaml"],
"scratch": ["scratch"],
"sql": ["mysql", "sql", "oracle", "database", "postgresql", "mongodb"],
"supercollider": ["supercollider"],
"unix": [
"linux", "shell", "unix", "bash", "system administration", "network",
"networking", "firewall", "ubuntu", "tcp/ip", "tcp", "tcpip", "administration",
"administrator", "red hat", "grep", "sed", "awk", "systems", "protocols",
"bsd", "freebsd"
],
"vb": ["visual basic"],
"vi": ["vi", "vim"],
"windows": ["powershell"],
"xml": ["xml"]
}
path = "unsorted"
keywords = {}
for k, v in categories.items():
for x in v:
keywords[x] = k
for filename in [x for x in os.listdir(path) if os.path.isfile(os.path.join(path, x))]:
for term in [x for x in re.findall(r"[+'A-Za-z]+", filename.lower()) if x in keywords]:
src = os.path.join(path, filename)
dest = os.path.join(keywords[term], filename)
try:
if not os.path.exists(keywords[term]):
os.makedirs(keywords[term])
os.rename(src, dest)
break
except (FileNotFoundError, FileExistsError) as e:
print(e)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment