jtorresj96 commited on
Commit
fc4f72f
·
verified ·
1 Parent(s): 6b15907

Upload sim_cards_final.ipynb

Browse files
Files changed (1) hide show
  1. sim_cards_final.ipynb +196 -0
sim_cards_final.ipynb ADDED
@@ -0,0 +1,196 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 2,
6
+ "metadata": {
7
+ "id": "_AsSApXZfXzl"
8
+ },
9
+ "outputs": [
10
+ {
11
+ "name": "stderr",
12
+ "output_type": "stream",
13
+ "text": [
14
+ "c:\\Users\\JUAN DAVID\\Documents\\GitHub\\gpsprogramer\\.venv\\Lib\\site-packages\\tqdm\\auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
15
+ " from .autonotebook import tqdm as notebook_tqdm\n"
16
+ ]
17
+ }
18
+ ],
19
+ "source": [
20
+ "import requests\n",
21
+ "import gradio as gr"
22
+ ]
23
+ },
24
+ {
25
+ "cell_type": "code",
26
+ "execution_count": 4,
27
+ "metadata": {
28
+ "colab": {
29
+ "base_uri": "https://localhost:8080/",
30
+ "height": 626
31
+ },
32
+ "id": "yD428hr1feLX",
33
+ "outputId": "82907a29-ebb4-49cf-f9ac-864c516cda27"
34
+ },
35
+ "outputs": [
36
+ {
37
+ "name": "stdout",
38
+ "output_type": "stream",
39
+ "text": [
40
+ "Running on local URL: http://127.0.0.1:7861\n",
41
+ "Running on public URL: https://f93cdae94df82588c8.gradio.live\n",
42
+ "\n",
43
+ "This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)\n"
44
+ ]
45
+ },
46
+ {
47
+ "data": {
48
+ "text/html": [
49
+ "<div><iframe src=\"https://f93cdae94df82588c8.gradio.live\" width=\"100%\" height=\"500\" allow=\"autoplay; camera; microphone; clipboard-read; clipboard-write;\" frameborder=\"0\" allowfullscreen></iframe></div>"
50
+ ],
51
+ "text/plain": [
52
+ "<IPython.core.display.HTML object>"
53
+ ]
54
+ },
55
+ "metadata": {},
56
+ "output_type": "display_data"
57
+ },
58
+ {
59
+ "data": {
60
+ "text/plain": []
61
+ },
62
+ "execution_count": 4,
63
+ "metadata": {},
64
+ "output_type": "execute_result"
65
+ }
66
+ ],
67
+ "source": [
68
+ "def get_sim_status(iccid):\n",
69
+ " url = f\"https://iot.truphone.com/api/v2.2/sims/{iccid}/status\"\n",
70
+ " headers = {\n",
71
+ " \"Authorization\": \"Token c1a5eadc6ddaeb233653ff45e90f917900a4a15f\"\n",
72
+ " }\n",
73
+ "\n",
74
+ " response = requests.get(url, headers=headers)\n",
75
+ "\n",
76
+ " if response.status_code == 200:\n",
77
+ " print(\"Solicitud exitosa:\")\n",
78
+ " print(response.json()) # Si la respuesta es JSON\n",
79
+ " else:\n",
80
+ " print(f\"Error al realizar la solicitud: {response.status_code} \")\n",
81
+ " return response\n",
82
+ "\n",
83
+ "\n",
84
+ "\n",
85
+ "def get_sim_details(iccid):\n",
86
+ " url = f\"https://iot.truphone.com/api/v2.2/sims/{iccid}\"\n",
87
+ " headers = {\n",
88
+ " \"Authorization\": \"Token c1a5eadc6ddaeb233653ff45e90f917900a4a15f\"\n",
89
+ " }\n",
90
+ "\n",
91
+ " response = requests.get(url, headers=headers)\n",
92
+ "\n",
93
+ " if response.status_code == 200:\n",
94
+ " print(\"Solicitud exitosa:\")\n",
95
+ " print(response.json()) # Si la respuesta es JSON\n",
96
+ " else:\n",
97
+ " print(f\"Error al realizar la solicitud: {response.status_code} \")\n",
98
+ " return response\n",
99
+ "\n",
100
+ "\n",
101
+ "def send_sms(iccid, text):\n",
102
+ " url = \"https://iot.truphone.com/api/v2.0/sims/send_sms\"\n",
103
+ " headers = {\n",
104
+ " \"Authorization\": \"Token c1a5eadc6ddaeb233653ff45e90f917900a4a15f\",\n",
105
+ " \"Content-Type\": \"application/json\"\n",
106
+ " }\n",
107
+ " body = {\n",
108
+ " \"iccid\": [iccid],\n",
109
+ " \"text\": text\n",
110
+ " }\n",
111
+ "\n",
112
+ " response = requests.post(url, json=body, headers=headers)\n",
113
+ "\n",
114
+ " if response.status_code == 200:\n",
115
+ " print(\"Mensaje enviado exitosamente\")\n",
116
+ " return \"ok\"\n",
117
+ " else:\n",
118
+ " print(f\"Error al enviar el mensaje: {response.status_code}\")\n",
119
+ " return \"error\"\n",
120
+ "\n",
121
+ "\n",
122
+ "def program_gps(iccid_list):\n",
123
+ " messages = ['apn123456 iot.truphone.com','Apn,iot.truphone.com#','TIMER,90,1200#', 'fix090s***n123456',\"SERVER,1,www.safestart.com.co,5023,0#\", 'RESET#', 'reset123456']\n",
124
+ " iccids = iccid_list.split(',') # Asume que la entrada es una cadena de ICCIDs separados por comas\n",
125
+ " text = \"\"\n",
126
+ " for sim in iccids:\n",
127
+ " sim = sim.strip() # Elimina espacios en blanco\n",
128
+ " response_status = get_sim_status(sim)\n",
129
+ " response_status = response_status.json()\n",
130
+ " try:\n",
131
+ " sim_card_service = response_status['status']['sim_card_service']\n",
132
+ " except:\n",
133
+ " sim_card_service = \"error\"\n",
134
+ " aswr_ok = 0\n",
135
+ " for message in messages:\n",
136
+ " aswr = send_sms(sim, message)\n",
137
+ " if aswr == \"ok\":\n",
138
+ " aswr_ok += 1\n",
139
+ " if aswr_ok == 7:\n",
140
+ " text += sim + \" ok. \"\n",
141
+ " if sim_card_service == 'SUSPENDED':\n",
142
+ " text = text + \"Esta bloqueada por consumo, pedir reactivación. \\n\"\n",
143
+ " else:\n",
144
+ " text = text + \"\\n\"\n",
145
+ " else:\n",
146
+ " text += sim + \" fail\\n\"\n",
147
+ "\n",
148
+ " return text\n",
149
+ "\n",
150
+ "# Crea una interfaz de Gradio\n",
151
+ "iface = gr.Interface(\n",
152
+ " fn=program_gps,\n",
153
+ " inputs=gr.Textbox(label=\"Introduce los ICCIDs separados por comas\"),\n",
154
+ " outputs=\"text\",\n",
155
+ " title=\"Programador de GPS\",\n",
156
+ " description=\"Introduce los ICCIDs separados por comas para programar los GPS.\"\n",
157
+ ")\n",
158
+ "\n",
159
+ "# Lanza la interfaz\n",
160
+ "iface.launch(share = True)"
161
+ ]
162
+ },
163
+ {
164
+ "cell_type": "code",
165
+ "execution_count": 3,
166
+ "metadata": {
167
+ "id": "BPRhPnipfiC-"
168
+ },
169
+ "outputs": [],
170
+ "source": []
171
+ }
172
+ ],
173
+ "metadata": {
174
+ "colab": {
175
+ "provenance": []
176
+ },
177
+ "kernelspec": {
178
+ "display_name": "Python 3",
179
+ "name": "python3"
180
+ },
181
+ "language_info": {
182
+ "codemirror_mode": {
183
+ "name": "ipython",
184
+ "version": 3
185
+ },
186
+ "file_extension": ".py",
187
+ "mimetype": "text/x-python",
188
+ "name": "python",
189
+ "nbconvert_exporter": "python",
190
+ "pygments_lexer": "ipython3",
191
+ "version": "3.11.9"
192
+ }
193
+ },
194
+ "nbformat": 4,
195
+ "nbformat_minor": 0
196
+ }