From 1ddb4f65fb9e277a5e6f9a7c82620ff1d98c087e Mon Sep 17 00:00:00 2001 From: 6455 Date: Fri, 4 Aug 2017 03:00:19 +0000 Subject: [PATCH] i think i did it right this time, even though I don't know how to ignore still haha --- LICENSE | 21 ++++++++++++++++++ README.md | 13 ++++++++++++ nicethings | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 96 insertions(+) create mode 100644 LICENSE create mode 100644 README.md create mode 100755 nicethings diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..2e399ed --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 m455/Jesse + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8cd9697 --- /dev/null +++ b/README.md @@ -0,0 +1,13 @@ +# nicethings +A poorly written python script that will hopefully cheer some people up + +Note: I've modified the file paths in this script so it will work on [tilde.town](https://tilde.town). You can adjust the accordingly + +### How it works +It stores user{'s/s'} input into a text file if an argument is given. If no arguments are given, a random nice message from the text file will be displayed. + +### Usage +##### Adding a message to the file: +`nicethings "insert your message here"` +##### Randomly generate a message: +`nicethings` diff --git a/nicethings b/nicethings new file mode 100755 index 0000000..b0e5fda --- /dev/null +++ b/nicethings @@ -0,0 +1,62 @@ +#!/usr/bin/env python3 + +import os +import sys +import random + +#create list.txt +def createlist(): + thefile = open('/home/m455/code/projects/nicethings/list.txt', 'w+') + thefile.close() + print("list.txt created, try your command again and it should work :)") + +#display random nice message if no arguments are given +def showrandomline(): + thefile = open('/home/m455/code/projects/nicethings/list.txt', 'r') + filecontents = thefile.read(1) + if not filecontents: + print("sorry, there's nothing in list.txt.\nTry adding something to the list by typing:\nnicethings \"your message here\"") + else: + print("\n" + random.choice(list(open('/home/m455/code/projects/nicethings/list.txt', 'r')))) + +#too many arguments error +def toomanyargs(): + print("Sorry, I only accept one argument.\nTry using:\nnicethings \"your message here\"") + +#no input error +def noinputerror(): + print("Sorry, I couldn't find any input.\n\nTry using:\nnicethings \"your message here\"") + +#add user input to file and display to user what was added +def addtofile(): + thefile = open('/home/m455/code/projects/nicethings/list.txt', 'a') + thefile.write(sys.argv[1] + "\n") + thefile.close() + print("-----------------------------------------\nYou have added the following to the list:\n\n{}\n-----------------------------------------".format(sys.argv[1])) + +#how to handle different user inputs +def handleargs(): + if len(sys.argv) <= 1: + showrandomline() + elif len(sys.argv) > 2: + toomanyargs() + elif sys.argv[1].isspace() == True or sys.argv[1] == "": + noinputerror() + else: + addtofile() + +def handlechoice(): + userchoice = input() + if userchoice == "y": + createlist() + elif userchoice == "n": + print("bye bye") + else: + print("sorry, I didn't get that, type either y or n:") + handlechoice() + +if os.path.exists('/home/m455/code/projects/nicethings/list.txt') == True: + handleargs() +else: + print("list.txt doesn't exist\ndo you want me to make a list.txt file right now? (y/n)") + handlechoice()