Package: text-excuse-generator
Text Excuse GeneratorTable of ContentsIntroductionUsesRunning from Command LineRunning with Command Line ArgumentsSending a Text MessageSetting Up .env FileSaving a New RecipientImporting as a ModuleInstalling with pipgenerate_excuse()setup_env()add_recipient()send_twilio_text()RunningDependenciesSetting Up .env FileRunningQuality AssuranceSuggestionsContributingLicenseIntroductionRecently, I came across a reddit post onr/ProgrammerHumorthat had a comment that referencedthis repository. While not only being a pretty funny story and set of scripts, it also got me thinking about creating a script of my own to create excuses and text them to whoever I want/need to. Unlike the scripts that I took inspiration from:hangover.py&smack_my_bitch_up.py, that just picked excuses from a predetermined list, I decided to generate the excuses usingOpenAI's GPT-3.5-turboAPI, and I usedTwilio's APIto send text messages. The program prompts the user (or can be passed in as arguments) for: the sender of the text, the recipient of the text, the 'problem', an excuse for the problem, and the option to send the generated message as a text. It also has a system to save phone numbers to names, so you can just type in a name instead of a phone number. Since the program uses OpenAI'sGPT-3.5-turbomodel, it can generate a pretty good excuse to anyone for virtually anything! The program can be run normally, with command line arguments, or imported as a module into another python file. Since it can have command line arguments passed in to operate it, it can be used in other programs, such as a Bash script, or used in a cron job.UsesThere are three main ways to interact with the program: by running it normally, by running it with command line arguments, or by importing it into another python file.Note:[recipient]can be a name or a case sensitive phone number: e.g.Huckor+15555555555. You must also set up your .env file (more details inDependencies).Running from Command LineI'd recommend just downloadingexcuse_generator.pyand running it from the command line. You can run it by typing:python3text_excuse_generator.pyIf you just want theexcuse_generator.pyfile for a project, please also include theLICENSEfile in the same directory asexcuse_generator.py.When you run the program normally, it will ask you for the sender, recipient, problem, and excuse, and if you want to send the text message. It will then generate a text message, and send it to the recipient if chosen. If you input a name into recipient that isn't saved to the system yet when sending a text, it will ask you if you want to save it to the system. If you choose to save it, it will ask you for the phone number, and then save it to the system. You can also just use a phone number for the recipient field, and it will send the text to that number.Running with Command Line ArgumentsYou can also run the program with command line arguments. If you want to send the text message, you can add--sendor-sas the last argument. All command line arguments longer than a single word need to be in parentheses. I'd recommend just downloadingexcuse_generator.pyand running it from the command line. If you just want theexcuse_generator.pyfile for a project, please also include theLICENSEfile in the same directory asexcuse_generator.py.Sending a Text MessageIf you want to send a text with command line arguments, run:python3text_excuse_generator.pySENDERRECIPIENTPROBLEMEXCUSE[--send_text_flag]e.g.python3text_excuse_generator.pyMe"Your mom""I'm late to 😈""Too many wizards around"-sOmit the[--send_text_flag]if you don't want to send the text message.Setting Up .env FileIf you want to set up the .env file, run:python3text_excuse_generator.py-e/--setup_envTWILIO_ACCOUNT_SIDTWILIO_AUTH_TOKENTWILIO_PHONE_NUMBER[OPENAI_API_KEY]e.g.python3text_excuse_generator.py-e"AC1234567890""1234567890""+15555555555""sk-1234567890"Saving a New RecipientIf you want to save a new recipient to the system, run:python3text_excuse_generator.py-a/--addNAMEPHONE_NUMBERe.g.python3text_excuse_generator.py-a"Your mom"+15555555555Importing as a ModuleYou can also import the program as a module into another python file. Thetext_excuse_generatormodule has  four functions:generate_excuse(),setup_env(),add_recipient(), &send_twilio_text().Installing with pipSimply run:pipinstalltext-excuse-generatorTo import the module into your python file, put this at the top of your file:fromtext_excuse_generator.excuse_generatorimport*# orimporttext_excuse_generator.excuse_generatorasteg# or whatever you want to call itOr you can import the individual functions.generate_excuse()takes in:generate_excuse(USER:str,RECIPIENT:str,PROBLEM:str,EXCUSE:str,SEND_TEXT:bool)->(str|None)generate_excuse()returns a string of the text message that was generated, or None if unable to generate the text message.If you want to generate a text message, call the function like this:generate_excuse("user","recipient","problem","excuse",True)e.g.generate_excuse(user="me",recipient="your mom",problem="I'm late to 😈",excuse="Too many wizards around",send_text=True)Make sure to put the fields before the variables when calling the function. Omit the[--send_text_flag]if you don't want to send the text message.setup_env()takes in:setup_env(TWILIO_ACCOUNT_SID:str,TWILIO_AUTH_TOKEN:str,TWILIO_PHONE_NUMBER:str,OPENAI_API_KEY:str)->boolIf you want to set up your .env file, callsetup_env()like this:setup_env("TWILIO_ACCOUNT_SID","TWILIO_AUTH_TOKEN","TWILIO_PHONE_NUMBER","OPENAI_API_KEY")e.g.setup_env("AC1234567890abcdef1234567890abcdef","1234567890abcdef1234567890abcdef","+15555555555","sk-1234567890")setup_env()returns True if the .env file was successfully set up, and False if it wasn't (Invalid phone number).add_recipient()takes in:add_recipient(NAME:str,PHONE_NUMBER:str)->boolIf you want to save a new recipient to the system, calladd_recipient()like this:add_recipient("new_recipient_name","new_recipient_phone_number")e.g.add_recipient("Your Mom","+15555555555")add_recipient()returns True if the recipient was successfully added to the system, and False if it wasn't (Invalid phone number or phone number is already in the system).send_twilio_text()takes in:send_twilio_text(RECIPIENT_PHONE_NUMBER:str,MESSAGE:str)->NoneIf you want to send a text message, callsend_twilio_text()like this:send_twilio_text("recipient_phone_number","message")e.g.send_twilio_text("+15555555555","Beep boop beep bop")RunningDependenciesAccountsYou'll need to create aTwilioaccount to get a phone number. You can either use the free trial phone number, or pay $1/month for a real phone number, but you'll need to verify any phone numbers you want to text with the trial account.You'll also need to create anOpenAI accountto get anAPI key. You'll also need to give payment information to OpenAI to use the API, but with the GPT-3.5-Turbo model it'sextremely cheap: $0.002/1000 tokens: at one word, punctuation, special character, or space per token. As of right now, I've sent ~30 requests to the OpenAI API, and I've only spent $0.02 so far!Once you get these two accounts set up, you'll need to find out this information from Twilio:Account SIDAuth TokenTwilio Phone NumberAnd this information from OpenAI:OpenAI API KeyAnd thenset up the.envfilewith this information.InstallFor Command Line UseDouble clickdependencies, or runbashdependenciesor./dependenciesin the root directory to install the python dependencies. You must havepipinstalled to download the new dependencies. Also, you'll need to installpythonyourself if you haven't already.For Importing as a ModuleIf you just run:pipinstalltext-excuse-generatorThe dependencies will be installed automatically, along with the rest of the module!List of DependenciesSetting Up .env FileEither run the program without any arguments to manually input the information for the .env file, run withcommand line argumentsto automatically input the information for the .env file, or pass in the correct parameters to thesetup_env()function in thetext_excuse_generatormodule.RunningYOU HAVE TO INSTALL THE DEPENDENCIES & SETUP THE.envFILE BEFORE TRYING TO RUN THE PROGRAM!!!Runpython3 text_excuse_generator.pyorpython3 text_excuse_generator.py SENDER RECIPIENT PROBLEM EXCUSE [--send_text_flag]in the command line in the source directory.More detailed instructions are in theUsessection.Quality AssuranceAll variable, function, class, module, & file names are written insnake_caseto make sure everything is consistent, and allconstvariables are written in ALL-CAPS. The code is also quite commented and the variable names are quite verbose, so it should be easy enough to understand what's going on.If there are any other/better ways to check for quality assurance, please let me know in thesuggestions!SuggestionsIf you have any suggestions about anything, please create anew discussion in suggestions.ContributingContributions are always welcomed! Look atCONTRIBUTING.mdfor more information.LicenseThe project is available under theMITlicense.