Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add text sender python command line program #571

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions projects/Text Sender/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Py Text Sender

[![License](https://img.shields.io/static/v1?label=License&message=GPL-3-0&color=blue&?style=plastic&logo=appveyor)](https://opensource.org/license/GPL-3-0)



## Table Of Content

- [Description](#description)
- [Installation](#installation)
- [Usage](#usage)
- [GitHub](#github)
- [License](#license)




![GitHub repo size](https://img.shields.io/github/repo-size/robertlent/py_auto_textmessage?style=plastic)

![GitHub top language](https://img.shields.io/github/languages/top/robertlent/py_auto_textmessage?style=plastic)



## Description

Python script to send a text message through textbelt. A message can also be scheduled to go out every day at a certain time.

Using the program with the included key 'textbelt', the user can send one free text message per day.



## Installation

1. Download main.py and requirements.txt to your machine.
2. Change to the directory that the files were downloaded to, create a virtual environment, and activate it using `cd [/path/to/files] && python3 -m venv venv && source venv/bin/activate`
3. Install dependencies using `pip3 install -r requirements.txt`



Py Text Sender is built with the following tools and libraries: <ul><li>Python</li><li><a href='https://textbelt.com/'>textbelt</a></li></ul>



## Usage

1. Run the program with `python3 main.py`
2. Follow the prompts:
- Choose to either send a one-time text message or schedule a text message every day at a specific time.
- Provide the phone number you would like to send the text to.
- Your default command-line editor will open, prompting you for the text's message.
- If you chose option 1, the number and message will be sent to the textbelt api and a 'success' or 'failure' response will be received.
- If you chose option 2, you will be prompted to enter the time of day that you want to schedule the text to be sent.
- The program will continue running, sending your message every day at the provided time, until you kill it.


## GitHub

<a href="https://github.com/robertlent"><strong>robertlent</a></strong>



## License

[![License](https://img.shields.io/static/v1?label=License&message=GPL-3-0&color=blue&?style=plastic&logo=appveyor)](https://opensource.org/license/GPL-3-0)
69 changes: 69 additions & 0 deletions projects/Text Sender/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import schedule
import time
import requests
import click


def main():
while True:
option = int(input("""\
1: Send a one-time text message\n\
2: Schedule a text message every day at a chosen time?\n\

Option 1 or 2: """))

if option in [1, 2]:
break

global number, message
number, message = set_text_details()

if option == 1:
send_text()

if option == 2:
schedule_text()


def set_text_details():
number = input("What phone number would you like to text? ")
number = ''.join(c for c in number if c.isdigit())
prompt = f"# Please enter your text message for phone number {number} above."
message = click.edit('\n\n' + prompt)

if message:
message = message.split(prompt)[0].strip()

return number, message


def send_text():
resp = requests.post('https://textbelt.com/text', {
'phone': number,
'message': message,
'key': 'textbelt', # textbelt allows one free text per day using this key
})

print(resp.json())


def schedule_text():
while True:
scheduled_time = input(
"Please enter the time you would like to send the text each day, in 24-hour time: ")

scheduled_time = scheduled_time.replace(':', '')

if scheduled_time.isdigit() and len(scheduled_time) == 4:
if int(scheduled_time[:2]) <= 23 and int(scheduled_time[2:]) <= 59:
scheduled_time = f'{scheduled_time[:2]}:{scheduled_time[2:]}'
break

schedule.every().day.at(scheduled_time).do(send_text)

while True:
schedule.run_pending()
time.sleep(1)


main()
20 changes: 20 additions & 0 deletions projects/Text Sender/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# This file is autogenerated by pip-compile with Python 3.11
# by the following command:
#
# pip-compile
#
certifi==2023.7.22
# via requests
charset-normalizer==3.3.0
# via requests
click==8.1.7
# via -r requirements.in
idna==3.4
# via requests
requests==2.31.0
# via -r requirements.in
schedule==1.2.1
# via -r requirements.in
urllib3==2.0.6
# via requests