-
-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed loop termination when timeout limit is reached
- Loading branch information
Showing
1 changed file
with
10 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,7 +9,6 @@ | |
python3 send_ussd.py http://admin:[email protected]/ *4# 7 1 | ||
""" | ||
import sys | ||
import time | ||
import itertools | ||
import threading | ||
|
@@ -30,8 +29,9 @@ | |
'codes', metavar='code', | ||
type=str, nargs='+', help='USSD code to send' | ||
) | ||
parser.add_argument('--timeout', type=int, default=15) | ||
args = parser.parse_args() | ||
MAX_WAIT_TIME = 15 | ||
MAX_WAIT_TIME = args.timeout | ||
DONE = False | ||
|
||
|
||
|
@@ -63,21 +63,24 @@ def animate(): | |
t.start() | ||
else: | ||
print('Error: Cannot send USSD code') | ||
break | ||
except Exception as e: | ||
print(f'Error: {e}') | ||
break | ||
|
||
# Wait for the response from the service provider. | ||
while int(client.ussd.status().get('result', '1')) >= 1: | ||
if wait_time >= MAX_WAIT_TIME: | ||
print('Error: Timeout Limit Exceeded') | ||
DONE = True | ||
t.join() | ||
print('Error: Timeout Limit Exceeded') | ||
break | ||
wait_time += 1 | ||
time.sleep(1) | ||
if DONE: | ||
continue | ||
else: | ||
DONE = True | ||
t.join() | ||
break | ||
DONE = True | ||
t.join() | ||
|
||
# Print the response. | ||
response = client.ussd.get() | ||
|