Skip to content

Instantly share code, notes, and snippets.

@Silverbullet069
Last active January 27, 2024 08:30
Show Gist options
  • Save Silverbullet069/e036cc12f673f837cea6502dca86336c to your computer and use it in GitHub Desktop.
Save Silverbullet069/e036cc12f673f837cea6502dca86336c to your computer and use it in GitHub Desktop.
[PyCon 2018] This is a very interesting topics to be one step closer to a Python-guru #python

solve your problem with sloppy python

who's it for?

  • you, you, and only you
  • not professional
  • not checked in

the rules

  • fail early and noisily
  • stop wrting shell scripts
  • have fun

guidelines

  • 3.6, f-string
  • try automating even more
  • try new lib/tech (controversy)

deep dive

mass rename

  • use hard links to backup (only while renaming)

provision

audio download, decant

  • make random-named dir
  • os.system("unzip " + zipfile)
  • flatten_directory(), remove the tree and put all of the files at the root level
  • read_all_metadata(), if we have all the metadata we need:
  • titlecase and clean up artist / album / title
  • rename media files to your fav pattern
  • create audio playlist file M3U : "{artist} - {album}.m3u"
  • rename directory to "artist - album"

survey

Custom data format: matter= year= month= day= five part story

tips

Don't use: os.system(), this is deprecated, you have to fail early and often, os.system() don't fail early and often, if it fails the remaining Python script still runs :v the command that return anything non-zero should be failed, should stop right immediately.

def run(s):
	subprocess.run(s, check=True, shell=True)

shell=True for piping and sudo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment