laterbase.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Laterbase, part of GNU FM -- a free network service for sharing your
  2. # music listening habits
  3. #
  4. # Copyright (C) 2009, 2012 Free Software Foundation, Inc
  5. #
  6. # This program is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU Affero General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU Affero General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU Affero General Public License
  17. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. import sys
  19. import os
  20. import getpass
  21. import fileinput
  22. LATERBASE = os.path.abspath("/home/" + getpass.getuser() + "/.laterbase")
  23. def showhelp():
  24. print " "
  25. print "88 db 888888 888888 8888Yb 8888Yb db .dP8Y8 888888 "
  26. print "88 dPYb 88 88__ 88__dP 88__dP dPYb `Ybo.8 88__ "
  27. print "88 .o dP__Yb 88 8888 888Yb 8888Yb dP__Yb o.`Y8b 8888 "
  28. print "88ood8 dP8888Yb 88 888888 88 Yb 88oodP dP8888Yb 8bodP' 888888 "
  29. print " "
  30. print "Got a job you really don't want to do? Stick it on the laterbase!"
  31. print " "
  32. print "Usage:"
  33. print " "
  34. print "(Put this nice python script in somewhere useful like /usr/bin/lb)"
  35. print " "
  36. print "Then, just type lb wash car"
  37. print "And hey Presto, 'wash car' is added to your laterbase."
  38. if (len(sys.argv) > 1):
  39. if( sys.argv[1] == 'list' ):
  40. try:
  41. ins = open( LATERBASE, "r" )
  42. for line in ins:
  43. print "* " + line
  44. ins.close()
  45. except IOError as e:
  46. print "You don't have anything on your laterbase. Try lb <item> to add something to the laterbase."
  47. elif( sys.argv[1] == 'help' ):
  48. showhelp()
  49. else:
  50. n = ""
  51. for x in range (1,len(sys.argv)):
  52. n = n + sys.argv[x] + " "
  53. n = n.strip()
  54. try:
  55. f = open(LATERBASE, "a")
  56. try:
  57. f.write (n + "\n")
  58. print "Added '" + n + "' to the laterbase."
  59. finally:
  60. f.close()
  61. except IOError:
  62. print "Cannot write to ~/.laterbase."