forked from purplemashu/me-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
228 lines (209 loc) · 8.84 KB
/
main.py
File metadata and controls
228 lines (209 loc) · 8.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
from dotenv import load_dotenv
from app.service.git import check_for_updates
load_dotenv()
import sys, json
from datetime import datetime
from app.menus.util import clear_screen, pause
from app.client.engsel import (
get_balance,
get_tiering_info,
)
from app.client.famplan import validate_msisdn
from app.menus.payment import show_transaction_history
from app.service.auth import AuthInstance
from app.menus.bookmark import show_bookmark_menu
from app.menus.account import show_account_menu
from app.menus.package import fetch_my_packages, get_packages_by_family, show_package_details
from app.menus.hot import show_hot_menu, show_hot_menu2
from app.service.sentry import enter_sentry_mode
from app.menus.purchase import purchase_by_family
from app.menus.famplan import show_family_info
from app.menus.circle import show_circle_info
from app.menus.notification import show_notification_menu
from app.menus.store.segments import show_store_segments_menu
from app.menus.store.search import show_family_list_menu, show_store_packages_menu
from app.menus.store.redemables import show_redeemables_menu
from app.client.registration import dukcapil
WIDTH = 55
def show_main_menu(profile):
clear_screen()
print("=" * WIDTH)
expired_at_dt = datetime.fromtimestamp(profile["balance_expired_at"]).strftime("%Y-%m-%d")
print(f"Nomor: {profile['number']} | Type: {profile['subscription_type']}".center(WIDTH))
print(f"Pulsa: Rp {profile['balance']} | Aktif sampai: {expired_at_dt}".center(WIDTH))
print(f"{profile['point_info']}".center(WIDTH))
print("=" * WIDTH)
print("Menu:")
print("1. Login/Ganti akun")
print("2. Lihat Paket Saya")
print("3. Beli Paket 🔥 HOT 🔥")
print("4. Beli Paket 🔥 HOT-2 🔥")
print("5. Beli Paket Berdasarkan Option Code")
print("6. Beli Paket Berdasarkan Family Code")
print("7. Beli Semua Paket di Family Code (loop)")
print("8. Riwayat Transaksi")
print("9. Family Plan/Akrab Organizer")
print("10. Circle")
print("11. Store Segments")
print("12. Store Family List")
print("13. Store Packages")
print("14. Redemables")
print("R. Register")
print("N. Notifikasi")
print("V. Validate msisdn")
print("00. Bookmark Paket")
print("99. Tutup aplikasi")
print("-------------------------------------------------------")
show_menu = True
def main():
while True:
active_user = AuthInstance.get_active_user()
# Logged in
if active_user is not None:
balance = get_balance(AuthInstance.api_key, active_user["tokens"]["id_token"])
balance_remaining = balance.get("remaining")
balance_expired_at = balance.get("expired_at")
point_info = "Points: N/A | Tier: N/A"
if active_user["subscription_type"] == "PREPAID":
tiering_data = get_tiering_info(AuthInstance.api_key, active_user["tokens"])
tier = tiering_data.get("tier", 0)
current_point = tiering_data.get("current_point", 0)
point_info = f"Points: {current_point} | Tier: {tier}"
profile = {
"number": active_user["number"],
"subscriber_id": active_user["subscriber_id"],
"subscription_type": active_user["subscription_type"],
"balance": balance_remaining,
"balance_expired_at": balance_expired_at,
"point_info": point_info
}
show_main_menu(profile)
choice = input("Pilih menu: ")
# Testing shortcuts
if choice.lower() == "t":
pause()
elif choice == "1":
selected_user_number = show_account_menu()
if selected_user_number:
AuthInstance.set_active_user(selected_user_number)
else:
print("No user selected or failed to load user.")
continue
elif choice == "2":
fetch_my_packages()
continue
elif choice == "3":
show_hot_menu()
elif choice == "4":
show_hot_menu2()
elif choice == "5":
option_code = input("Enter option code (or '99' to cancel): ")
if option_code == "99":
continue
show_package_details(
AuthInstance.api_key,
active_user["tokens"],
option_code,
False
)
elif choice == "6":
family_code = input("Enter family code (or '99' to cancel): ")
if family_code == "99":
continue
get_packages_by_family(family_code)
elif choice == "7":
family_code = input("Enter family code (or '99' to cancel): ")
if family_code == "99":
continue
start_from_option = input("Start purchasing from option number (default 1): ")
try:
start_from_option = int(start_from_option)
except ValueError:
start_from_option = 1
use_decoy = input("Use decoy package? (y/n): ").lower() == 'y'
pause_on_success = input("Pause on each successful purchase? (y/n): ").lower() == 'y'
delay_seconds = input("Delay seconds between purchases (0 for no delay): ")
try:
delay_seconds = int(delay_seconds)
except ValueError:
delay_seconds = 0
purchase_by_family(
family_code,
use_decoy,
pause_on_success,
delay_seconds,
start_from_option
)
elif choice == "8":
show_transaction_history(AuthInstance.api_key, active_user["tokens"])
elif choice == "9":
show_family_info(AuthInstance.api_key, active_user["tokens"])
elif choice == "10":
show_circle_info(AuthInstance.api_key, active_user["tokens"])
elif choice == "11":
input_11 = input("Is enterprise store? (y/n): ").lower()
is_enterprise = input_11 == 'y'
show_store_segments_menu(is_enterprise)
elif choice == "12":
input_12_1 = input("Is enterprise? (y/n): ").lower()
is_enterprise = input_12_1 == 'y'
show_family_list_menu(profile['subscription_type'], is_enterprise)
elif choice == "13":
input_13_1 = input("Is enterprise? (y/n): ").lower()
is_enterprise = input_13_1 == 'y'
show_store_packages_menu(profile['subscription_type'], is_enterprise)
elif choice == "14":
input_14_1 = input("Is enterprise? (y/n): ").lower()
is_enterprise = input_14_1 == 'y'
show_redeemables_menu(is_enterprise)
elif choice == "00":
show_bookmark_menu()
elif choice == "99":
print("Exiting the application.")
sys.exit(0)
elif choice.lower() == "r":
msisdn = input("Enter msisdn (628xxxx): ")
nik = input("Enter NIK: ")
kk = input("Enter KK: ")
res = dukcapil(
AuthInstance.api_key,
msisdn,
kk,
nik,
)
print(json.dumps(res, indent=2))
pause()
elif choice.lower() == "v":
msisdn = input("Enter the msisdn to validate (628xxxx): ")
res = validate_msisdn(
AuthInstance.api_key,
active_user["tokens"],
msisdn,
)
print(json.dumps(res, indent=2))
pause()
elif choice.lower() == "n":
show_notification_menu()
elif choice == "s":
enter_sentry_mode()
else:
print("Invalid choice. Please try again.")
pause()
else:
# Not logged in
selected_user_number = show_account_menu()
if selected_user_number:
AuthInstance.set_active_user(selected_user_number)
else:
print("No user selected or failed to load user.")
if __name__ == "__main__":
try:
print("Checking for updates...")
need_update = check_for_updates()
if need_update:
pause()
main()
except KeyboardInterrupt:
print("\nExiting the application.")
# except Exception as e:
# print(f"An error occurred: {e}")