Spaces:
Sleeping
Sleeping
import requests | |
import urllib.parse | |
import gradio as gr | |
# List of 20 phone numbers (SIMs) installed in GPS trackers | |
SIM_NUMBERS = [ | |
"94757271180", "94758339857", "94758529725", "94753670267", "94758620601", | |
"94750413297", "94759371051", "94754240229", "94752570494", "94758713293", | |
"94753740267", "94751240524", "94754740373", "94750731994", "94758770643", | |
"94757634250", "94752313312", "94755872071", "94750472110", "94755872055" | |
] | |
# File that contains 1000 IMEI numbers | |
IMEI_FILE = "imei.txt" | |
# Function to read IMEIs from file | |
def read_imei_file(): | |
with open(IMEI_FILE, "r") as file: | |
imei_list = [line.strip() for line in file if line.strip()] | |
return imei_list | |
# Function to update the IMEI file after successful updates | |
def remove_processed_imeis(processed_imeis): | |
imei_list = read_imei_file() | |
remaining_imeis = [imei for imei in imei_list if imei not in processed_imeis] | |
with open(IMEI_FILE, "w") as file: | |
for imei in remaining_imeis: | |
file.write(f"{imei}\n") | |
return f"Successfully processed and removed {len(processed_imeis)} IMEIs from file." | |
# Function to send SMS and check delivery | |
def send_sms_and_check_delivery(user_id, password, recipient, message): | |
base_url = "https://www.textit.biz/sendmsg/index.php" | |
encoded_message = urllib.parse.quote(message) # URL encode the message | |
params = { | |
"id": user_id, | |
"pw": password, | |
"to": recipient, | |
"text": encoded_message | |
} | |
try: | |
response = requests.get(base_url, params=params) | |
response_text = response.text.strip() | |
if response_text.startswith("OK"): | |
return f"Message to {recipient} sent successfully." | |
else: | |
return f"Failed to deliver message to {recipient}. Error: {response_text}" | |
except Exception as e: | |
return f"Error sending SMS to {recipient}: {e}" | |
# Function to process IMEI update in batches of 20 | |
def process_imei_batches(user_id, password): | |
imeis = read_imei_file() | |
if len(imeis) == 0: | |
return "No IMEIs left to process. Exiting." | |
batch_size = len(SIM_NUMBERS) | |
logs = [] | |
for i in range(0, len(imeis), batch_size): | |
batch_imeis = imeis[i:i + batch_size] | |
logs.append("\nProcessing next batch of 20 IMEIs...") | |
processed_imeis = [] | |
for sim, imei in zip(SIM_NUMBERS, batch_imeis): | |
logs.append(f"\nSending CHECK# command to SIM: {sim}") | |
if "successfully" in send_sms_and_check_delivery(user_id, password, sim, "CHECK#"): | |
imei_write_command = f"IMEI,{imei}#" | |
logs.append(f"Sending IMEI write command: {imei_write_command} to SIM: {sim}") | |
if "successfully" in send_sms_and_check_delivery(user_id, password, sim, imei_write_command): | |
processed_imeis.append(imei) | |
logs.append(f"IMEI {imei} written successfully to {sim}") | |
else: | |
logs.append(f"Failed to write IMEI {imei} to {sim}") | |
else: | |
logs.append(f"CHECK# command failed for {sim}, skipping IMEI update.") | |
# Remove successfully processed IMEIs from the file | |
if processed_imeis: | |
logs.append(remove_processed_imeis(processed_imeis)) | |
logs.append("\nPress the button to proceed with the next 20 IMEIs after changing SIM cards.") | |
break | |
return "\n".join(logs) | |
# Gradio UI function | |
def start_imei_processing(user_id, password): | |
if not user_id or not password: | |
return "Error: Please enter both User ID and Password." | |
return process_imei_batches(user_id, password) | |
# Gradio interface with submit button | |
iface = gr.Interface( | |
fn=start_imei_processing, | |
inputs=[ | |
gr.Textbox(label="User ID (Phone Number in International Format)", type="text"), | |
gr.Textbox(label="Password (4-digit)", type="password") | |
], | |
outputs="text", | |
title="GPS Tracker IMEI Writer", | |
description="Enter your User ID and Password to start processing IMEI numbers. Click the button below to proceed.", | |
allow_flagging="never" | |
) | |
iface.launch(share=True) | |