Spaces:
Sleeping
Sleeping
jtorresj96 commited on
Commit ·
479fa28
1
Parent(s): e69e701
Update app.py
Browse files
app.py
CHANGED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
import gradio as gr
|
| 3 |
+
|
| 4 |
+
def get_sim_status(iccid):
|
| 5 |
+
url = f"https://iot.truphone.com/api/v2.2/sims/{iccid}/status"
|
| 6 |
+
headers = {
|
| 7 |
+
"Authorization": "Token c1a5eadc6ddaeb233653ff45e90f917900a4a15f"
|
| 8 |
+
}
|
| 9 |
+
|
| 10 |
+
response = requests.get(url, headers=headers)
|
| 11 |
+
|
| 12 |
+
if response.status_code == 200:
|
| 13 |
+
print("Solicitud exitosa:")
|
| 14 |
+
print(response.json()) # Si la respuesta es JSON
|
| 15 |
+
else:
|
| 16 |
+
print(f"Error al realizar la solicitud: {response.status_code} ")
|
| 17 |
+
return response
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def get_sim_details(iccid):
|
| 22 |
+
url = f"https://iot.truphone.com/api/v2.2/sims/{iccid}"
|
| 23 |
+
headers = {
|
| 24 |
+
"Authorization": "Token c1a5eadc6ddaeb233653ff45e90f917900a4a15f"
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
response = requests.get(url, headers=headers)
|
| 28 |
+
|
| 29 |
+
if response.status_code == 200:
|
| 30 |
+
print("Solicitud exitosa:")
|
| 31 |
+
print(response.json()) # Si la respuesta es JSON
|
| 32 |
+
else:
|
| 33 |
+
print(f"Error al realizar la solicitud: {response.status_code} ")
|
| 34 |
+
return response
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def send_sms(iccid, text):
|
| 38 |
+
url = "https://iot.truphone.com/api/v2.0/sims/send_sms"
|
| 39 |
+
headers = {
|
| 40 |
+
"Authorization": "Token c1a5eadc6ddaeb233653ff45e90f917900a4a15f",
|
| 41 |
+
"Content-Type": "application/json"
|
| 42 |
+
}
|
| 43 |
+
body = {
|
| 44 |
+
"iccid": [iccid],
|
| 45 |
+
"text": text
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
response = requests.post(url, json=body, headers=headers)
|
| 49 |
+
|
| 50 |
+
if response.status_code == 200:
|
| 51 |
+
print("Mensaje enviado exitosamente")
|
| 52 |
+
return "ok"
|
| 53 |
+
else:
|
| 54 |
+
print(f"Error al enviar el mensaje: {response.status_code}")
|
| 55 |
+
return "error"
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def program_gps(iccid_list):
|
| 59 |
+
messages = ['apn123456 iot.truphone.com','Apn,iot.truphone.com#','TIMER,90,1200#', 'fix090s***n123456',"SERVER,1,www.safestart.com.co,5023,0#", 'RESET#', 'reset123456']
|
| 60 |
+
iccids = iccid_list.split(',') # Asume que la entrada es una cadena de ICCIDs separados por comas
|
| 61 |
+
text = ""
|
| 62 |
+
for sim in iccids:
|
| 63 |
+
sim = sim.strip() # Elimina espacios en blanco
|
| 64 |
+
response_status = get_sim_status(sim)
|
| 65 |
+
response_status = response_status.json()
|
| 66 |
+
try:
|
| 67 |
+
sim_card_service = response_status['status']['sim_card_service']
|
| 68 |
+
except:
|
| 69 |
+
sim_card_service = "error"
|
| 70 |
+
aswr_ok = 0
|
| 71 |
+
for message in messages:
|
| 72 |
+
aswr = send_sms(sim, message)
|
| 73 |
+
if aswr == "ok":
|
| 74 |
+
aswr_ok += 1
|
| 75 |
+
if aswr_ok == 7:
|
| 76 |
+
text += sim + " ok. "
|
| 77 |
+
if sim_card_service == 'SUSPENDED':
|
| 78 |
+
text = text + "Esta bloqueada por consumo, pedir reactivación. \n"
|
| 79 |
+
else:
|
| 80 |
+
text = text + "\n"
|
| 81 |
+
else:
|
| 82 |
+
text += sim + " fail\n"
|
| 83 |
+
|
| 84 |
+
return text
|
| 85 |
+
|
| 86 |
+
# Crea una interfaz de Gradio
|
| 87 |
+
iface = gr.Interface(
|
| 88 |
+
fn=program_gps,
|
| 89 |
+
inputs=gr.Textbox(label="Introduce los ICCIDs separados por comas"),
|
| 90 |
+
outputs="text",
|
| 91 |
+
title="Programador de GPS",
|
| 92 |
+
description="Introduce los ICCIDs separados por comas para programar los GPS."
|
| 93 |
+
)
|
| 94 |
+
|
| 95 |
+
# Lanza la interfaz
|
| 96 |
+
iface.launch()
|