This week only. Pastebin PRO Accounts Christmas Special! Don't miss out!Want more features on Pastebin? Sign Up, it's FREE!
Guest

export script

By: iomari on Oct 24th, 2011  |  syntax: Python  |  size: 2.25 KB  |  views: 37  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #!/usr/bin/env python
  2.  
  3. import subprocess, os, popen2, fcntl, select, fnmatch, string, sys
  4. #argu = sys.argv[1:]
  5. argu = sys.argv[0:]   # use this instead of above to include command as an argument
  6. dest = "/mnt/installs/ebooks/all/iomari/"
  7. lfolder = "/home/iomari/calibre_library/iomari/"
  8. database = "metadata.db"
  9. who = subprocess.Popen("whoami", shell=True, stdout=subprocess.PIPE)
  10. who = who.stdout.read()
  11. who = who[:-1]
  12. idx = 0
  13. choose = []
  14.  
  15. stime = subprocess.Popen('date +"%H:%M:%S"', shell=True, stdout=subprocess.PIPE)
  16. stime = stime.stdout.read()
  17. stime = stime[:-1]
  18. if not who == "iomari":
  19.         print "\nYOU ARE CURRENTLY LOGGED IN AS \""+who+"\". YOU MUST LOG IN AS \"iomari\" for this to work.\n" ;
  20.         sys.exit() ;
  21.  
  22. format = subprocess.Popen("sqlite3 "+ lfolder+database+ " 'select * from data;' | cut -d '|' -f 3 | sort | uniq", shell=True, stdout=subprocess.PIPE)
  23. out = format.stdout.read()
  24. out2 = out.split("\n")
  25. del out2[-1] # remove last empty item
  26.  
  27. def export():
  28.         print "\ndeleting "+buff+" files"
  29.         op = subprocess.call("rm -rf "+dest+buff, shell=True)
  30.         print "exporting " + buff + " files.............."
  31.         print "calibredb export --formats="+buff+" --template='"+buff+"/{#supercat}/{tags}/{authors}/{title} - {authors}' --to-dir="+dest+" --to-lowercase --all\n"
  32.         xrun = subprocess.Popen("calibredb export --formats="+buff+" --template='"+buff+"/{#supercat}/{tags}/{authors}/{title} - {authors}' --to-dir="+dest+" --to-lowercase --all", shell=True, stdout=subprocess.PIPE)
  33.         go = xrun.stdout.read()
  34.         print go
  35.  
  36. print "exporting all books.............\n"
  37. if len(argu) == 2 and argu[1] == "all":     # export all books
  38.         for buff in out2:
  39.                 buff = buff.lower()
  40.                 export()
  41. else:                    # Add code here to choose which formats to export
  42.         for buff in out2:
  43.                 buff = buff.lower()
  44.                 ans = raw_input( "Do you want to export "+ buff+" books [y/n]? " )
  45.                 ans = ans.lower()
  46.                 choose.append(ans)
  47.         for buff in out2:
  48.                 buff = buff.lower()
  49.                 if choose[idx] == "y":
  50.                         export()
  51.                 idx = idx + 1
  52.  
  53. print"\nfinished\n"
  54. sys.exit()
  55.  
clone this paste RAW Paste Data