Ecco qualche suggerimento:
Esempio:
- non usare curl di sistema per controllare lo status, usa la stessa libreria requests che già usi
- basta una sola funzione per l'invio degli sms con e senza API key a pagamento
- usa JSON per interpretare il contenuto delle risposte
- conserva il text ID dei messaggi inviati in modo da controllare lo stato in automatico senza dover reinserire i codici manualmente
Esempio:
Python:
# Importo le librerie
import requests, colorama, os, sys, time, json
from colorama import Fore #BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE
from colorama import Style #DIM, NORMAL, BRIGHT, RESET_ALL
# Info
print(Fore.BLUE + Style.BRIGHT + "Version 1.0" + Style.RESET_ALL)
print(Fore.BLUE + Style.DIM + "Codice by - Mr. Camarium" + Style.RESET_ALL)
print(Fore.BLUE + Style.DIM + "Youtube - mrcamarium" + Style.RESET_ALL)
text_ids = []
# Pausa
time.sleep(2)
# Menu
def menu() :
print(Fore.YELLOW + "1. Invia SmS Anonimo (1 Gratis)" + Style.RESET_ALL)
print(Fore.YELLOW + "2. Invia SmS Anonimo (A pagamento)" + Style.RESET_ALL)
print(Fore.YELLOW + "3. Verifica Lo Stato Di Un SmS" + Style.RESET_ALL)
print(Fore.YELLOW + "4. Exit" + Style.RESET_ALL)
# Controlli per il menu
def control() :
ctrl = input("Effettua La Scelta: ")
if ctrl == "1" :
sms('textbelt')
elif ctrl == "2" :
api_key = input("Inserisci chiave API: ")
sms(api_key)
elif ctrl == "3" :
status()
elif ctrl == "4" :
sys.exit()
else :
print("Scelta Errata")
# Inserimento dati per l'invio del sms gratis
def sms(api_key) :
phone_no = input("Inserisci Numero Di Telefono con prefisso internazionale +: ")
msg = input("Messaggio Da Inviare (Max 160 Caratteri): ")
resp = requests.post('https://textbelt.com/text',{
'phone' : phone_no,
'message' : msg ,
'key' : api_key
})
success = False
result = "Impossibile connettersi"
if resp.status_code == 200 :
data = json.loads(resp.text)
if data['success'] :
success = True
text_id = data['textId']
text_ids.append(text_id)
result = "Messaggio inviato, ID: " + str(text_id)
else :
result = data['error']
color = Fore.GREEN if success else Fore.YELLOW
print(color + Style.BRIGHT + result + Style.RESET_ALL)
# Richiesta di verifica del SMS inviato
def status() :
for id in text_ids :
resp = requests.get('https://textbelt.com/status/' + str(id))
status = "UNKNOWN"
if resp.status_code == 200 :
data = json.loads(resp)
status = data['status']
color = ""
if status == "DELIVERED" or status == "SENT" :
color = Fore.GREEN
elif status == "SENDING" or status == "UNKNOWN" :
color = Fore.YELLOW
else :
color = Fore.RED
print("Stato invio SMS ID " + str(id) + ": " + color + Style.BRIGHT + status + Style.RESET_ALL)
#Fine
while True: #Ricomincia il programma
menu()
control()