Skip to content

Commit 197434c

Browse files
authored
Merge pull request #1 from bomber-ban/selective-updates
Added functionality to use different carriers in the calls
2 parents de99eeb + 2f610d4 commit 197434c

File tree

3 files changed

+59
-15
lines changed

3 files changed

+59
-15
lines changed

api/client.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ async def fetch_balance(self):
2828
except Exception as e:
2929
return {'detail': 'error', 'code': str(e)}
3030

31-
async def create_order_now_mode_time(self, phone: str, duration: int):
31+
async def create_order_now_mode_time(self, phone: str, duration: int, carriers_list: list):
3232
start_time = datetime.datetime.now(datetime.UTC).strftime('%Y-%m-%d %H:%M')
3333
payload = {
3434
"mode": "Time",
3535
"phone_number": phone,
3636
"duration": int(duration),
3737
"holder_timezone": "0",
3838
"scheduled_task": False,
39-
"start_time": start_time
39+
"start_time": start_time,
40+
"carriers": carriers_list
4041
}
4142
try:
4243
async with aiohttp.ClientSession(headers=self.headers) as s:
@@ -45,14 +46,16 @@ async def create_order_now_mode_time(self, phone: str, duration: int):
4546
except Exception as e:
4647
return {'detail': 'error', 'code': str(e)}
4748

48-
async def create_order_scheduled_mode_time(self, phone: str, duration: int, start_time: datetime):
49+
async def create_order_scheduled_mode_time(self, phone: str, duration: int, start_time: datetime,
50+
carriers_list: list):
4951
payload = {
5052
"mode": "Time",
5153
"phone_number": phone,
5254
"duration": int(duration),
5355
"holder_timezone": "0",
5456
"scheduled_task": True,
55-
"start_time": start_time
57+
"start_time": start_time,
58+
"carriers": carriers_list
5659
}
5760
try:
5861
async with aiohttp.ClientSession(headers=self.headers) as s:
@@ -61,7 +64,7 @@ async def create_order_scheduled_mode_time(self, phone: str, duration: int, star
6164
except Exception as e:
6265
return {'detail': 'error', 'code': str(e)}
6366

64-
async def create_order_now_mode_smart(self, phone: str, timezone: int):
67+
async def create_order_now_mode_smart(self, phone: str, timezone: int, carriers_list: list):
6568
start_time = datetime.datetime.now(datetime.UTC).strftime('%Y-%m-%d %H:%M')
6669

6770
if int(timezone) > 0:
@@ -75,7 +78,8 @@ async def create_order_now_mode_smart(self, phone: str, timezone: int):
7578
"duration": 160,
7679
"holder_timezone": timezone,
7780
"scheduled_task": False,
78-
"start_time": start_time
81+
"start_time": start_time,
82+
"carriers": carriers_list
7983
}
8084
try:
8185
async with aiohttp.ClientSession(headers=self.headers) as s:
@@ -84,7 +88,8 @@ async def create_order_now_mode_smart(self, phone: str, timezone: int):
8488
except Exception as e:
8589
return {'detail': 'error', 'code': str(e)}
8690

87-
async def create_order_scheduled_mode_smart(self, phone: str, timezone: int, start_time: datetime):
91+
async def create_order_scheduled_mode_smart(self, phone: str, timezone: int, start_time: datetime,
92+
carriers_list: list):
8893
if int(timezone) > 0:
8994
timezone = f"+{timezone}"
9095
else:
@@ -95,7 +100,8 @@ async def create_order_scheduled_mode_smart(self, phone: str, timezone: int, sta
95100
"duration": 160,
96101
"holder_timezone": timezone,
97102
"scheduled_task": True,
98-
"start_time": start_time
103+
"start_time": start_time,
104+
"carriers": carriers_list
99105
}
100106
try:
101107
async with aiohttp.ClientSession(headers=self.headers) as s:

gui/main_window.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,8 @@ def __init__(self, api_key: str, open_login_callback, recreate_callback=None):
133133

134134
# Breadcrumbs
135135
self.modes = {
136-
"Smart": ["Phone", "Timezone", "Scheduled", "Confirm"],
137-
"Time": ["Minutes", "Phone", "Scheduled", "Confirm"]
136+
"Smart": ["Phone", "Carriers", "Timezone", "Scheduled", "Confirm"],
137+
"Time": ["Minutes", "Carriers", "Phone", "Scheduled", "Confirm"]
138138
}
139139
self.order_data = {
140140
"Smart": {},

gui/widgets.py

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -273,14 +273,19 @@ async def api_call(self, order_mode, order_details):
273273
if order_details.get('Scheduled'):
274274

275275
api_answer = await self.step_widget.main.client.create_order_scheduled_mode_smart(
276-
order_details.get('Phone'), order_details.get('Timezone'), order_details.get('Scheduled')
276+
order_details.get('Phone'),
277+
order_details.get('Timezone'),
278+
order_details.get('Scheduled'),
279+
order_details.get('Carriers', [])
277280
)
278281
return api_answer
279282

280283
else:
281284

282285
api_answer = await self.step_widget.main.client.create_order_now_mode_smart(
283-
order_details.get('Phone'), order_details.get('Timezone')
286+
order_details.get('Phone'),
287+
order_details.get('Timezone'),
288+
order_details.get('Carriers', [])
284289
)
285290
return api_answer
286291

@@ -290,14 +295,19 @@ async def api_call(self, order_mode, order_details):
290295
if order_details.get('Scheduled'):
291296

292297
api_answer = await self.step_widget.main.client.create_order_scheduled_mode_time(
293-
order_details.get('Phone'), order_details.get('Minutes'), order_details.get('Scheduled')
298+
order_details.get('Phone'),
299+
order_details.get('Minutes'),
300+
order_details.get('Scheduled'),
301+
order_details.get('Carriers', [])
294302
)
295303
return api_answer
296304

297305
else:
298306

299307
api_answer = await self.step_widget.main.client.create_order_now_mode_time(
300-
order_details.get('Phone'), order_details.get('Minutes')
308+
order_details.get('Phone'),
309+
order_details.get('Minutes'),
310+
order_details.get('Carriers', [])
301311
)
302312
return api_answer
303313

@@ -360,6 +370,8 @@ def __init__(self, step_name: str, value: str, submit_callback, cancel_callback,
360370
"📞 Number of calls: 160\n"
361371
"📦 Price of the service: 8 Euros\n"
362372
"📌 Each call is unique and comes from a new number",
373+
"Carriers": "📡️ Enter carriers separated by commas,\n"
374+
"or leave the field empty to use default carrier mode",
363375
"Timezone": "🌎 To continue, please enter the number owner's time zone (from -12 to +12)",
364376
"Scheduled": "⏰ To continue, send in the chat the date when work on the phone should begin,\n"
365377
" or leave the field empty.\n\n"
@@ -370,6 +382,7 @@ def __init__(self, step_name: str, value: str, submit_callback, cancel_callback,
370382
"Confirm": f"📞 Phone: {data.get('Phone')}\n"
371383
f"🕘 Task duration: 2 days\n"
372384
f"#️⃣ Number of calls/minutes: 160\n"
385+
f"📡 Carriers: {', '.join(data.get('Carriers', [])) if data.get('Carriers') else '—'}\n"
373386
f"💶 Order price: 8.00 Euros\n"
374387
f"🌎 Subscriber's time zone: {data.get('Timezone')}\n\n"
375388

@@ -383,6 +396,8 @@ def __init__(self, step_name: str, value: str, submit_callback, cancel_callback,
383396
📌 Each call is unique and comes from a new number
384397
⌨️ Enter how many minutes we should work on this phone""",
385398
"Phone": "⌨️ To continue, enter your phone number in the field",
399+
"Carriers": "📡️ Enter carriers separated by commas,\n"
400+
"or leave the field empty to use default carrier mode",
386401
"Scheduled": "⏰ To continue, send in the chat the date when work on the phone should begin,\n"
387402
" or leave the field empty.\n\n"
388403
"❗️ For the start, the time will be taken in the UTC format.\n"
@@ -392,6 +407,7 @@ def __init__(self, step_name: str, value: str, submit_callback, cancel_callback,
392407
"Confirm": f"📞 Phone: {data.get('Phone')}\n"
393408
f"🕘 Task duration: {data.get('Minutes')} minutes\n"
394409
f"#️⃣ Number of calls/minutes: {data.get('Minutes')}\n"
410+
f"📡 Carriers: {', '.join(data.get('Carriers', [])) if data.get('Carriers') else 'Default'}\n"
395411
f"💶 Order price: {round(float(data.get('Minutes')) * 0.05, 2) if data.get('Minutes') else 0}"
396412
f" Euros\n\n"
397413

@@ -428,6 +444,9 @@ def __init__(self, step_name: str, value: str, submit_callback, cancel_callback,
428444
self.layout.addLayout(layout_desc)
429445
self.input_field = QLineEdit()
430446

447+
if step_name == "Carriers" and isinstance(value, list):
448+
value = ", ".join(value)
449+
431450
if value:
432451
self.input_field.setText(value)
433452

@@ -460,13 +479,16 @@ def go_next(self, submit_callback):
460479
if not self.validate():
461480
return
462481
else:
463-
submit_callback(self.input_field.text())
482+
submitted_value = getattr(self, "parsed_value", self.input_field.text())
483+
submit_callback(submitted_value)
484+
# submit_callback(self.input_field.text())
464485

465486
def validate(self):
466487
try:
467488
step = self.main.modes[self.main.current_mode][self.main.current_step]
468489
value = self.input_field.text().strip()
469490
error = None
491+
self.parsed_value = value
470492

471493
# === PHONE VALIDATION ===
472494
if step == "Phone":
@@ -478,7 +500,23 @@ def validate(self):
478500
error = "Phone number is too long."
479501
if not value:
480502
error = "Enter the Phone number."
503+
# === CARRIERS VALIDATION ===
481504

505+
elif step == "Carriers":
506+
if not value:
507+
self.parsed_value = []
508+
else:
509+
carriers = [item.strip() for item in value.split(",")]
510+
if any(not item for item in carriers):
511+
error = "Carriers must be separated by commas without empty values."
512+
elif len(carriers) > 100:
513+
error = "You can enter up to 100 carriers."
514+
else:
515+
invalid = [item for item in carriers if len(item) < 4 or len(item) > 8]
516+
if invalid:
517+
error = "Each carrier must be 4 to 8 characters long."
518+
else:
519+
self.parsed_value = carriers
482520
# === TIMEZONE VALIDATION ===
483521
elif step == "Timezone":
484522
try:

0 commit comments

Comments
 (0)