GmailTrust commited on
Commit
7738737
·
verified ·
1 Parent(s): 28b3d23

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -40
app.py CHANGED
@@ -42,10 +42,10 @@ class ZGMApiClient:
42
  response.raise_for_status()
43
  return response.json()
44
  except requests.exceptions.ConnectTimeout:
45
- return {"error": f"Cannot connect to {self.base_url}. Check URL or network.", "status_code": 0}
46
  except requests.exceptions.HTTPError as e:
47
  if response.status_code == 401:
48
- return {"error": "Unauthorized. Check API Token.", "status_code": 401}
49
  elif response.status_code == 500:
50
  return {"error": "Server error from ZGM API.", "status_code": 500}
51
  return {"error": f"HTTP Error: {str(e)}", "status_code": response.status_code}
@@ -71,11 +71,11 @@ def validate_key_from_api(access_key: str) -> tuple[bool, str]:
71
  response.raise_for_status()
72
  data = response.json()
73
  if data["valid"]:
74
- return True, f"{data['remaining']} key(s) remaining."
75
  else:
76
- return False, "Invalid key. Please enter a valid key."
77
  except requests.exceptions.RequestException as e:
78
- return False, f"Error while checking key from API: {str(e)}"
79
 
80
  def remove_key_from_api(access_key: str) -> tuple[bool, str]:
81
  try:
@@ -83,28 +83,27 @@ def remove_key_from_api(access_key: str) -> tuple[bool, str]:
83
  response.raise_for_status()
84
  data = response.json()
85
  if data["success"]:
86
- return True, f"{data['remaining']} key(s) remaining."
87
  else:
88
- return False, "Could not remove key."
89
  except requests.exceptions.RequestException as e:
90
- return False, f"Error while removing key from API: {str(e)}"
91
 
92
  def validate_and_remove_key(access_key: str, result: Dict) -> tuple[bool, str]:
93
  is_valid, message = validate_key_from_api(access_key)
94
  if not is_valid:
95
  return False, message
96
-
97
  if result.get("code") == 200 and result.get("data") and "orderId" in result["data"] and "email" in result["data"]:
98
  success, remove_message = remove_key_from_api(access_key)
99
  if not success:
100
- return True, f"OTP rental succeeded but {remove_message}"
101
- remaining_keys = int(remove_message.split(" key")[0].split()[-1])
102
- remaining_message = f"{remaining_keys} key(s) remaining."
103
  if remaining_keys < 100:
104
- remaining_message += " Low key count! Please generate more."
105
  return True, remaining_message
106
  else:
107
- return True, f"Error: {result.get('message', 'Could not rent Gmail.')}\nKey not removed."
108
 
109
  def execute_with_loading(func, *args, **kwargs):
110
  result = [None]
@@ -117,14 +116,8 @@ def execute_with_loading(func, *args, **kwargs):
117
  api_thread = threading.Thread(target=target)
118
  api_thread.start()
119
 
120
- chars = "|/-\\"
121
- i = 0
122
  while is_loading[0]:
123
- print(f"\rLoading {chars[i % len(chars)]}", end="")
124
- i += 1
125
  time.sleep(0.1)
126
- print("\r", end="")
127
-
128
  api_thread.join()
129
  return result[0]
130
 
@@ -132,10 +125,13 @@ def format_rent_otp_result(data: Dict) -> pd.DataFrame:
132
  if not data or "data" not in data:
133
  return pd.DataFrame([["No data to display."]], columns=["Message"])
134
  order_info = data["data"]
135
- df = pd.DataFrame([{ "Order ID": order_info.get("orderId", "N/A"), "Email": order_info.get("email", "N/A") }])
 
 
 
136
  return df
137
 
138
- def format_get_otp_result(data: Dict, selected_service: str) -> pd.DataFrame:
139
  if not data or "data" not in data:
140
  return pd.DataFrame([["No data to display."]], columns=["Message"])
141
  otp_data = data["data"]
@@ -143,10 +139,8 @@ def format_get_otp_result(data: Dict, selected_service: str) -> pd.DataFrame:
143
  otp_data = [otp_data]
144
  if not isinstance(otp_data, list):
145
  return pd.DataFrame([["Invalid data."]], columns=["Message"])
146
-
147
  df = pd.DataFrame([
148
  {
149
- "Service": selected_service,
150
  "Email": item.get("email", "N/A"),
151
  "OTP Code": item.get("otpCode", "N/A"),
152
  "Content": item.get("otpContent", "N/A")
@@ -161,15 +155,13 @@ def clear_all_logs():
161
  def gradio_interface(access_key, action, service, order_id, rent_otp_log, get_otp_log):
162
  message = ""
163
  new_order_id = order_id
164
-
165
  if rent_otp_log is None:
166
  rent_otp_log = pd.DataFrame([["No data yet"]], columns=["Message"])
167
  if get_otp_log is None:
168
  get_otp_log = pd.DataFrame([["No data yet"]], columns=["Message"])
169
-
170
  if action == "Rent OTP":
171
  if not access_key:
172
- rent_otp_log = pd.DataFrame([["Please enter key to proceed!"]], columns=["Message"])
173
  return rent_otp_log, get_otp_log, message, order_id
174
  if not service:
175
  rent_otp_log = pd.DataFrame([["Please select a service!"]], columns=["Message"])
@@ -191,40 +183,82 @@ def gradio_interface(access_key, action, service, order_id, rent_otp_log, get_ot
191
  return rent_otp_log, get_otp_log, "", order_id
192
  result = execute_with_loading(client.get_otp, order_id)
193
  if result.get("code") == 200 and "data" in result:
194
- get_otp_log = format_get_otp_result(result, service)
195
  else:
196
  get_otp_log = pd.DataFrame([[json.dumps(result, indent=2, ensure_ascii=False)]], columns=["Message"])
197
  return rent_otp_log, get_otp_log, "", order_id
198
  else:
199
  return rent_otp_log, get_otp_log, "Invalid action!", order_id
200
 
201
- SERVICES = ["ICLOUD", "ZSK", "FACEBOOK", "TELEGRAM", "OTHERS", "GGPLAY", "INSTAGRAM", "FMCPAY", "AMAZON"]
 
 
 
 
 
 
 
 
 
 
 
202
 
203
  with gr.Blocks() as demo:
204
- gr.Markdown("## ZGM API Client - Enter Access Key to Rent OTP (Key is required only for Rent OTP, one-time use only)")
205
 
206
  with gr.Row():
207
- access_key = gr.Textbox(label="Enter Access Key (Only for Rent OTP)", placeholder="Enter 32-character key...")
208
  action = gr.Dropdown(label="Select Action", choices=["Rent OTP", "Get OTP"], value="Rent OTP")
209
 
210
  with gr.Row():
211
- service = gr.Dropdown(label="Service (for Rent OTP)", choices=SERVICES)
212
- order_id = gr.Textbox(label="Order ID (for Get OTP)", placeholder="Enter Order ID")
213
 
214
  rent_otp_log = gr.State(value=pd.DataFrame([["No data yet"]], columns=["Message"]))
215
  get_otp_log = gr.State(value=pd.DataFrame([["No data yet"]], columns=["Message"]))
216
 
217
- with gr.Row():
218
- rent_otp_output = gr.Dataframe(label="Rent OTP Log", headers=["Order ID", "Email"], datatype=["str", "str"], interactive=False)
219
- get_otp_output = gr.Dataframe(label="Get OTP Log", headers=["Service", "Email", "OTP Code", "Content"], datatype=["str", "str", "str", "str"], interactive=False)
 
 
 
 
 
 
 
 
 
 
220
 
221
  message_output = gr.Textbox(label="Message", interactive=False)
222
 
223
  with gr.Row():
224
- submit_btn = gr.Button("Execute", variant="primary")
225
- clear_btn = gr.Button("Clear Logs", variant="secondary")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
226
 
227
- submit_btn.click(fn=gradio_interface, inputs=[access_key, action, service, order_id, rent_otp_log, get_otp_log], outputs=[rent_otp_output, get_otp_output, message_output, order_id])
228
- clear_btn.click(fn=clear_all_logs, inputs=None, outputs=[rent_otp_output, get_otp_output, message_output])
229
 
230
  demo.launch()
 
42
  response.raise_for_status()
43
  return response.json()
44
  except requests.exceptions.ConnectTimeout:
45
+ return {"error": f"Cannot connect to {self.base_url}. Please check URL or network.", "status_code": 0}
46
  except requests.exceptions.HTTPError as e:
47
  if response.status_code == 401:
48
+ return {"error": "Unauthorized. Please check API Token.", "status_code": 401}
49
  elif response.status_code == 500:
50
  return {"error": "Server error from ZGM API.", "status_code": 500}
51
  return {"error": f"HTTP Error: {str(e)}", "status_code": response.status_code}
 
71
  response.raise_for_status()
72
  data = response.json()
73
  if data["valid"]:
74
+ return True, f"Remaining {data['remaining']} keys."
75
  else:
76
+ return False, "Invalid key!"
77
  except requests.exceptions.RequestException as e:
78
+ return False, f"Error checking key from API: {str(e)}"
79
 
80
  def remove_key_from_api(access_key: str) -> tuple[bool, str]:
81
  try:
 
83
  response.raise_for_status()
84
  data = response.json()
85
  if data["success"]:
86
+ return True, f"Remaining {data['remaining']} keys."
87
  else:
88
+ return False, "Cannot remove key."
89
  except requests.exceptions.RequestException as e:
90
+ return False, f"Error removing key from API: {str(e)}"
91
 
92
  def validate_and_remove_key(access_key: str, result: Dict) -> tuple[bool, str]:
93
  is_valid, message = validate_key_from_api(access_key)
94
  if not is_valid:
95
  return False, message
 
96
  if result.get("code") == 200 and result.get("data") and "orderId" in result["data"] and "email" in result["data"]:
97
  success, remove_message = remove_key_from_api(access_key)
98
  if not success:
99
+ return True, f"OTP rented successfully but {remove_message}"
100
+ remaining_keys = int(remove_message.split("Remaining ")[1].split(" key")[0])
101
+ remaining_message = f"Remaining {remaining_keys} keys."
102
  if remaining_keys < 100:
103
+ remaining_message += " Low key count! Please create more keys."
104
  return True, remaining_message
105
  else:
106
+ return True, f"Error: {result.get('message', 'Unable to rent Gmail.')}\nKey not deleted."
107
 
108
  def execute_with_loading(func, *args, **kwargs):
109
  result = [None]
 
116
  api_thread = threading.Thread(target=target)
117
  api_thread.start()
118
 
 
 
119
  while is_loading[0]:
 
 
120
  time.sleep(0.1)
 
 
121
  api_thread.join()
122
  return result[0]
123
 
 
125
  if not data or "data" not in data:
126
  return pd.DataFrame([["No data to display."]], columns=["Message"])
127
  order_info = data["data"]
128
+ df = pd.DataFrame([{
129
+ "Order ID": order_info.get("orderId", "N/A"),
130
+ "Email": order_info.get("email", "N/A")
131
+ }])
132
  return df
133
 
134
+ def format_get_otp_result(data: Dict) -> pd.DataFrame:
135
  if not data or "data" not in data:
136
  return pd.DataFrame([["No data to display."]], columns=["Message"])
137
  otp_data = data["data"]
 
139
  otp_data = [otp_data]
140
  if not isinstance(otp_data, list):
141
  return pd.DataFrame([["Invalid data."]], columns=["Message"])
 
142
  df = pd.DataFrame([
143
  {
 
144
  "Email": item.get("email", "N/A"),
145
  "OTP Code": item.get("otpCode", "N/A"),
146
  "Content": item.get("otpContent", "N/A")
 
155
  def gradio_interface(access_key, action, service, order_id, rent_otp_log, get_otp_log):
156
  message = ""
157
  new_order_id = order_id
 
158
  if rent_otp_log is None:
159
  rent_otp_log = pd.DataFrame([["No data yet"]], columns=["Message"])
160
  if get_otp_log is None:
161
  get_otp_log = pd.DataFrame([["No data yet"]], columns=["Message"])
 
162
  if action == "Rent OTP":
163
  if not access_key:
164
+ rent_otp_log = pd.DataFrame([["Please enter a key to rent OTP!"]], columns=["Message"])
165
  return rent_otp_log, get_otp_log, message, order_id
166
  if not service:
167
  rent_otp_log = pd.DataFrame([["Please select a service!"]], columns=["Message"])
 
183
  return rent_otp_log, get_otp_log, "", order_id
184
  result = execute_with_loading(client.get_otp, order_id)
185
  if result.get("code") == 200 and "data" in result:
186
+ get_otp_log = format_get_otp_result(result)
187
  else:
188
  get_otp_log = pd.DataFrame([[json.dumps(result, indent=2, ensure_ascii=False)]], columns=["Message"])
189
  return rent_otp_log, get_otp_log, "", order_id
190
  else:
191
  return rent_otp_log, get_otp_log, "Invalid action!", order_id
192
 
193
+ SERVICES = [
194
+ "ICLOUD", "ZSK", "FACEBOOK", "TELEGRAM", "OTHERS",
195
+ "GGPLAY", "INSTAGRAM", "FMCPAY", "AMAZON"
196
+ ]
197
+
198
+ notification_message = ""
199
+
200
+ def update_notification(msg_input, password):
201
+ global notification_message
202
+ if password == "2312":
203
+ notification_message = msg_input
204
+ return notification_message
205
 
206
  with gr.Blocks() as demo:
207
+ gr.Markdown("## ZGM API Client - Enter Key to Rent OTP")
208
 
209
  with gr.Row():
210
+ access_key = gr.Textbox(label="Access Key (Required for Rent OTP)", placeholder="Enter 32-char key...")
211
  action = gr.Dropdown(label="Select Action", choices=["Rent OTP", "Get OTP"], value="Rent OTP")
212
 
213
  with gr.Row():
214
+ service = gr.Dropdown(label="Service (For Rent OTP)", choices=SERVICES)
215
+ order_id = gr.Textbox(label="Order ID (For Get OTP)", placeholder="Enter Order ID")
216
 
217
  rent_otp_log = gr.State(value=pd.DataFrame([["No data yet"]], columns=["Message"]))
218
  get_otp_log = gr.State(value=pd.DataFrame([["No data yet"]], columns=["Message"]))
219
 
220
+ rent_otp_output = gr.Dataframe(
221
+ label="Rent OTP Log",
222
+ headers=["Order ID", "Email"],
223
+ datatype=["str", "str"],
224
+ interactive=False
225
+ )
226
+
227
+ get_otp_output = gr.Dataframe(
228
+ label="Get OTP Log",
229
+ headers=["Email", "OTP Code", "Content"],
230
+ datatype=["str", "str", "str"],
231
+ interactive=False
232
+ )
233
 
234
  message_output = gr.Textbox(label="Message", interactive=False)
235
 
236
  with gr.Row():
237
+ submit_btn = gr.Button("Submit", variant="primary")
238
+ clear_btn = gr.Button("Clear Log", variant="secondary")
239
+
240
+ submit_btn.click(
241
+ fn=gradio_interface,
242
+ inputs=[access_key, action, service, order_id, rent_otp_log, get_otp_log],
243
+ outputs=[rent_otp_output, get_otp_output, message_output, order_id]
244
+ )
245
+
246
+ clear_btn.click(
247
+ fn=clear_all_logs,
248
+ inputs=None,
249
+ outputs=[rent_otp_output, get_otp_output, message_output]
250
+ )
251
+
252
+ gr.Markdown("## System Notification")
253
+ with gr.Row():
254
+ notification_input = gr.Textbox(label="Update Notification", lines=3)
255
+ password_input = gr.Textbox(label="Password", type="password")
256
+ with gr.Row():
257
+ update_btn = gr.Button("Update Notification")
258
+ current_notification = gr.Textbox(label="Current Notification", interactive=False)
259
+ update_btn.click(update_notification, inputs=[notification_input, password_input], outputs=current_notification)
260
 
261
+ gr.Markdown("## Get OTP Log")
262
+ demo.append(get_otp_output)
263
 
264
  demo.launch()