stvtermux 1.0.7__py3-none-any.whl → 1.0.8__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
stvtermux/cli.py CHANGED
@@ -5,7 +5,7 @@ def main():
5
5
 
6
6
  print("===== 🌐 STVTermux Login System 🌐 =====")
7
7
  while True:
8
- choice = input("👉 Bạn muốn:\n(1) Đăng ký hay\n(2) Đăng nhập? ")
8
+ choice = input("👉 Bạn muốn:\n(1) Đăng ký hay\n(2) Đăng nhập ")
9
9
  if choice == "1":
10
10
  u = input("username: ")
11
11
  p = input("password: ")
stvtermux/core.py CHANGED
@@ -1,7 +1,6 @@
1
1
  import requests
2
2
  import json
3
3
  import subprocess
4
- import os
5
4
 
6
5
  FIREBASE_URL = "https://sever-login-ae5cc-default-rtdb.firebaseio.com/player.json"
7
6
 
@@ -29,20 +28,23 @@ class Auth:
29
28
  print("❌ Đăng ký thất bại!")
30
29
  return False
31
30
 
32
- def login(self, username: str, password: str) -> bool:
31
+ def login(self, username: str, password: str):
33
32
  res = requests.get(self.firebase_url)
34
33
  if res.status_code != 200:
35
34
  print("❌ Lỗi kết nối server!")
36
- return False
35
+ return None
37
36
 
38
37
  data = res.json() or {}
39
- for _, user in data.items():
38
+ for user_id, user in data.items():
40
39
  if user.get("username") == username and user.get("password") == password:
41
40
  print("✅ Đăng nhập thành công!")
42
- # 👉 Lấy đường dẫn tuyệt đối tới index.py trong package
43
- module_path = os.path.join(os.path.dirname(__file__), "index.py")
44
- subprocess.run(["python", module_path])
45
- return True
41
+ # Ghi user_id ra file tạm để nhom.py đọc
42
+ with open("user.json", "w", encoding="utf-8") as f:
43
+ json.dump({"user_id": user_id}, f)
44
+ subprocess.run(["python", "index.py"])
45
+ return user_id
46
46
 
47
47
  print("❌ Sai username hoặc password!")
48
- return False
48
+ return None
49
+
50
+
stvtermux/nhom.py CHANGED
@@ -1,53 +1,69 @@
1
1
  import requests
2
- import json
3
2
  import threading
4
3
  import time
4
+ import json
5
5
  import os
6
- import sys
7
6
 
8
- FIREBASE_URL = "https://sever-login-ae5cc-default-rtdb.firebaseio.com/chatnhom.json"
7
+ FIREBASE_CHAT = "https://sever-login-ae5cc-default-rtdb.firebaseio.com/chatnhom.json"
8
+ FIREBASE_PLAYER = "https://sever-login-ae5cc-default-rtdb.firebaseio.com/player.json"
9
9
 
10
+ # Lấy tên user từ player.json dựa vào user_id
11
+ def get_name(user_id: str) -> str:
12
+ try:
13
+ res = requests.get(FIREBASE_PLAYER)
14
+ if res.status_code != 200:
15
+ return "Ẩn danh"
16
+ data = res.json() or {}
17
+ user = data.get(user_id, {})
18
+ return user.get("username", "Ẩn danh")
19
+ except Exception:
20
+ return "Ẩn danh"
21
+
22
+ # Luồng hiển thị tin nhắn
10
23
  def listen_messages():
11
- last_seen = None
24
+ last_data = None
12
25
  while True:
13
26
  try:
14
- res = requests.get(FIREBASE_URL)
27
+ res = requests.get(FIREBASE_CHAT)
15
28
  if res.status_code == 200:
16
29
  data = res.json() or {}
17
- sorted_msgs = sorted(data.items(), key=lambda x: x[0])
18
- for k, v in sorted_msgs:
19
- if last_seen is None or k > last_seen:
20
- print(f"\n💬 {v.get('name')}: {v.get('msg')}")
21
- last_seen = k
22
- except Exception:
23
- pass
30
+ if data != last_data:
31
+ os.system("clear")
32
+ print("===== 💬 Tin nhắn nhóm =====")
33
+ for _, msg in data.items():
34
+ print(f"[{msg.get('name')}] {msg.get('text')}")
35
+ print("============================")
36
+ last_data = data
37
+ except Exception as e:
38
+ print("❌ Lỗi khi lấy tin nhắn:", e)
24
39
  time.sleep(2)
25
40
 
26
- def send_message(name):
27
- while True:
28
- msg = input("")
29
- if msg.strip() == "":
30
- continue
31
- data = {"name": name, "msg": msg}
32
- try:
33
- requests.post(FIREBASE_URL, data=json.dumps(data))
34
- except Exception:
35
- print("❌ Lỗi gửi tin nhắn!")
41
+ def chat():
42
+ # Đọc user_id từ file user.json
43
+ try:
44
+ with open("user.json", "r", encoding="utf-8") as f:
45
+ user_data = json.load(f)
46
+ user_id = user_data.get("user_id")
47
+ except FileNotFoundError:
48
+ print("❌ Bạn chưa đăng nhập!")
49
+ return
36
50
 
37
- def main():
38
- os.system("clear")
39
- print("══════════════════════════════════════")
40
- print("🌐 CHAT NHÓM STVTermux (Realtime) 🌐")
41
- print("══════════════════════════════════════")
51
+ name = get_name(user_id)
52
+ print(f"👋 Xin chào {name}, bạn đã vào nhóm chat!")
42
53
 
43
- # 👉 lấy tên từ sys.argv (username đã login)
44
- name = sys.argv[1] if len(sys.argv) > 1 else "Ẩn danh"
54
+ threading.Thread(target=listen_messages, daemon=True).start()
45
55
 
46
- t = threading.Thread(target=listen_messages, daemon=True)
47
- t.start()
56
+ while True:
57
+ text = input("✍️ Nhập tin nhắn: ")
58
+ if text.lower() in ["exit", "quit"]:
59
+ print("👋 Thoát nhóm chat...")
60
+ break
48
61
 
49
- print(f"✨ {name}, bắt đầu trò chuyện...")
50
- send_message(name)
62
+ msg = {"name": name, "text": text}
63
+ try:
64
+ requests.post(FIREBASE_CHAT, data=json.dumps(msg))
65
+ except Exception as e:
66
+ print("❌ Lỗi gửi tin nhắn:", e)
51
67
 
52
68
  if __name__ == "__main__":
53
- main()
69
+ chat()
@@ -1,5 +1,5 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: stvtermux
3
- Version: 1.0.7
3
+ Version: 1.0.8
4
4
  Requires-Dist: requests
5
5
  Dynamic: requires-dist
@@ -0,0 +1,10 @@
1
+ stvtermux/__init__.py,sha256=bk7kIC3tSACeEbiYSYrJEpHxwr6DswGbO-18EF-MDwM,45
2
+ stvtermux/cli.py,sha256=hpK610GHWzm526R3M6H5zlFdxgcWjBcLbm7lXZdK5K4,543
3
+ stvtermux/core.py,sha256=WN6F7EBvZcgQMV5KHbGZGNXofUeuYm2qqLIHt624D4I,1809
4
+ stvtermux/index.py,sha256=QazhR3QhyKZO3Uc3x_TapRCduCStOtxWT2HY5xfQ5gY,999
5
+ stvtermux/nhom.py,sha256=QsGAp-hdTUa2HBaieG1XwQwLPTaG7cxjPdnMfDTDrXE,2262
6
+ stvtermux-1.0.8.dist-info/METADATA,sha256=oM6WAiRnewg8jwuVyvZ4Usegi0OhGnK8TnzkI_-HKRs,100
7
+ stvtermux-1.0.8.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
+ stvtermux-1.0.8.dist-info/entry_points.txt,sha256=7b0IuLqKSWL2VMJxcTdMLZXBaPfYT1atz6wwBTqco9Q,43
9
+ stvtermux-1.0.8.dist-info/top_level.txt,sha256=6krSSYES7OG83FeLt7MWD5vG8MOwzYh_K3ju8lBNqwg,10
10
+ stvtermux-1.0.8.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- stvtermux/__init__.py,sha256=bk7kIC3tSACeEbiYSYrJEpHxwr6DswGbO-18EF-MDwM,45
2
- stvtermux/cli.py,sha256=pmjeY6GyZMqPiXN_lzdrScaG5gBFtS7EHlhmb_Ld1PM,544
3
- stvtermux/core.py,sha256=mTFyeko7yw9b38ZV6mDMcWC7L83Rbn3cPjAJUi2xhHY,1798
4
- stvtermux/index.py,sha256=QazhR3QhyKZO3Uc3x_TapRCduCStOtxWT2HY5xfQ5gY,999
5
- stvtermux/nhom.py,sha256=R-J804aLE7HN_oU_gYBkX3Zkqzy7J7p7FPyKrPY__G8,1736
6
- stvtermux-1.0.7.dist-info/METADATA,sha256=xBA2iI91BvCKvAk9ZVa8f1aVC0BdQbUoLcYgM_IjfSI,100
7
- stvtermux-1.0.7.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
8
- stvtermux-1.0.7.dist-info/entry_points.txt,sha256=7b0IuLqKSWL2VMJxcTdMLZXBaPfYT1atz6wwBTqco9Q,43
9
- stvtermux-1.0.7.dist-info/top_level.txt,sha256=6krSSYES7OG83FeLt7MWD5vG8MOwzYh_K3ju8lBNqwg,10
10
- stvtermux-1.0.7.dist-info/RECORD,,