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.

114 lines
2.9 KiB

7 years ago
7 years ago
  1. """
  2. Python script that prints an ascii roo with a message above it
  3. Jeffery Russell
  4. 10-8-17
  5. """
  6. import sys
  7. def main():
  8. """
  9. checks for command line arguments
  10. :return: None
  11. """
  12. message = ""
  13. for i in range(1, len(sys.argv)):
  14. if len(message) > 0:
  15. message += " "
  16. message += sys.argv[i]
  17. for line in sys.stdin:
  18. message+= line
  19. message = " ".join(message.split())
  20. roo_say(message)
  21. def roo_say(message):
  22. """
  23. Method which prints an ascii roo with a message above it
  24. :param message: the message to print
  25. :return: none
  26. """
  27. print_message(message)
  28. print_roo()
  29. def print_message(message):
  30. """
  31. Prints the message above Roo
  32. :param message: the message to print
  33. :return: None
  34. """
  35. print_list, max_len = convert_to_list(message)
  36. if len(print_list) > 0:
  37. "Print top"
  38. print(" " + "-" * (2 + max_len))
  39. "print middle"
  40. if len(print_list) == 1:
  41. print("< " + print_list[0] + " >")
  42. else:
  43. for i in range(0, len(print_list)):
  44. if i == 0:
  45. print("/ " + print_list[i]
  46. + " " * (max_len - len(print_list[i])) +" \\")
  47. elif i == len(print_list) -1:
  48. print("\ " + print_list[i]
  49. + " " * (max_len - len(print_list[i])) + " /")
  50. else:
  51. print("| " + print_list[i]
  52. + " " * (max_len - len(print_list[i])) + " |")
  53. "print bottom"
  54. print(" " + "-" * (max_len + 2))
  55. else:
  56. print("Please pass in a message parameter")
  57. def convert_to_list(message):
  58. """
  59. Converts the message into string lines which are
  60. less than 35 characters - easier for printing
  61. :param message: the string message
  62. :return: the list of the string lines and the length of the longest line
  63. """
  64. temp_build = ""
  65. temp_return = []
  66. max_len = 0
  67. for word in message.split(" "):
  68. if len(temp_build) + len(word) < 35:
  69. if len(temp_build) > 0:
  70. temp_build += " "
  71. temp_build += word
  72. if max_len < len(temp_build):
  73. max_len = len(temp_build)
  74. else:
  75. temp_return.append(temp_build)
  76. temp_build = word
  77. if len(temp_build) > 0:
  78. temp_return.append(temp_build)
  79. return temp_return, max_len
  80. def print_roo():
  81. """
  82. prints the roo ascii
  83. :return: None
  84. """
  85. print("")
  86. print(" \ /)/)")
  87. print(" \ (ø.ø)")
  88. print(" \ ( />")
  89. print(" __/ _\ //")
  90. print(" '~( '~ )//")
  91. print(" _\ '}/")
  92. print(" \"--~(/")
  93. """
  94. If ran from command line, this will call the main which looks for command line arguments
  95. """
  96. if __name__ == '__main__':
  97. main()