Python scripts I use to manage my ssh connections, drive mounts, and other bash related things.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

113 lines
3.0 KiB

7 years ago
7 years ago
7 years ago
7 years ago
  1. """
  2. Simple python script to run on bash start up.
  3. This will print a welcome message and then a random quote from a text file
  4. 9-27-17
  5. Jeffery Russell
  6. """
  7. import random
  8. import sys
  9. import os.path
  10. import glob
  11. from utils import module
  12. from utils import print_message_bubble
  13. import configuration
  14. """Path to a text file containing quotes"""
  15. INPUT_FILE = configuration.get_config()["quotes"]
  16. """Pulls a list of the ascii art file names"""
  17. BASE_FILE = os.path.dirname(os.path.realpath(__file__))
  18. ASCII_ART = glob.glob(BASE_FILE + "/asciiArt/*.txt")
  19. def print_message(message, ascii_file = None):
  20. """
  21. Prints a dialog box with a message in it with an ascii
  22. animal below it
  23. :param message: a quote to print
  24. :param ascii_file: the file location of the ascii art speaking the message
  25. :return: NA
  26. """
  27. print_message_bubble.print_message(message)
  28. if ascii_file != None:
  29. filepath = '/'.join(INPUT_FILE.split('/')[:-1])
  30. filepath += "/asciiArt/" + ascii_file
  31. if (os.path.exists(filepath)):
  32. f = open(filepath, 'r')
  33. print(f.read())
  34. f.close()
  35. else:
  36. print(module.input_file_with_new_line(
  37. ASCII_ART[random.randint(0,(len(ASCII_ART) -1))]))
  38. else:
  39. print(module.input_file_with_new_line(
  40. ASCII_ART[random.randint(0,(len(ASCII_ART) -1))]))
  41. def print_usage():
  42. """
  43. Prints the usage message to the terminal
  44. :return: None
  45. """
  46. print("Usage:")
  47. print("\t-a quote \t: Adds a quote to the quotes list")
  48. print("\t-h \t\t: Prints usage message")
  49. def add_quote():
  50. """
  51. Adds the quote in the command line arguments
  52. to the quotes text file
  53. :return: None
  54. """
  55. quote = ""
  56. for i in range(2, len(sys.argv)):
  57. quote = quote + sys.argv[i]
  58. quote = quote + " "
  59. print("added " + quote + "to " + INPUT_FILE)
  60. module.append_file(INPUT_FILE, quote)
  61. def main():
  62. """
  63. This function calls the welcome function, then it calls the cowsay
  64. function with a random quote.
  65. :return: None
  66. """
  67. if len(sys.argv) > 1:
  68. if sys.argv[1].lower() == "-h" or sys.argv[1].lower() == "-help":
  69. print_usage()
  70. elif sys.argv[1].lower() == "-a":
  71. if len(sys.argv) > 2:
  72. add_quote()
  73. else:
  74. print("You forgot to enter a quote.")
  75. elif sys.argv[1][:2] == "--":
  76. quotes = module.input_file(INPUT_FILE)
  77. print_message(quotes[random.randint(0,(len(quotes) -1))], ascii_file=sys.argv[1][2:]+'.txt')
  78. else:
  79. print_usage()
  80. else:
  81. quotes = module.input_file(INPUT_FILE)
  82. if len(quotes) == 0:
  83. print("Quotes file : " + INPUT_FILE + " is empty.")
  84. else:
  85. print_message(quotes[random.randint(0,(len(quotes) -1))])
  86. """
  87. Makes sure that other programs don't execute the main
  88. """
  89. if __name__ == '__main__':
  90. try:
  91. main()
  92. except KeyboardInterrupt:
  93. exit()