Rubika Login Example
This is a simple example showing how to use the rulog Python library to:
- Send a verification code to a phone number.
- Login to Rubika using the received code.
- Register the device.
Installation
Make sure you have installed the rulog library:
pip install rulog
Example Code
from rulog import Client
# Create a Client instance
Client = Client()
# ===== Send code =====
def send_code(phone):
try:
# Try sending via Android platform with send_type=True
response = Client.sendCode("android", phone, send_type=True)
return response['data']['phone_code_hash']
except Exception as e:
print("❌ Android send failed. Trying Web...")
try:
response = Client.sendCode("web", phone)
return response['data']['phone_code_hash']
except Exception as e:
print("❌ Sending code failed:", e)
return None
# ===== Login =====
def login(phone, hash_code, code):
try:
response = Client.signIn("android", phone, hash_code, code)
print("✅ Login successful.")
return response
except Exception as e:
print("❌ Login failed:", e)
return None
# ===== Register device =====
def register(auth, key):
try:
result = Client.register(platform="android", auths=auth, keys=key)
if result:
print("✅ Registration successful.")
return True
else:
print("❌ Registration failed.")
return False
except Exception as e:
print("❌ Registration error:", e)
return False
# ===== Main execution =====
if __name__ == "__main__":
phone = input("📱 Enter your phone number (e.g., 9891...): ").strip()
hash_code = send_code(phone)
if not hash_code:
print("🚫 Code sending failed. Exiting.")
exit()
code = input("🔢 Enter the received code: ").strip()
login_response = login(phone, hash_code, code)
if login_response:
register(login_response['Auth'], login_response['Key'])
How it works
- Send code: Sends a verification code to the phone using Android first, then Web if failed.
- Login: Signs in using the phone number, hash code, and received code.
- Register: Registers the device using the authentication keys received after login.
Notes
- Ensure your phone number format is correct.
- The script handles simple retries for sending codes.
- The library
rulogmust be installed.
Metadata
Release files for rulog 1.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| rulog-1.0.3.tar.gz | 11.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| rulog-1.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.6 kB
Release files / rulog-1.0.3.tar.gz
| Download URL | rulog-1.0.3.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bb5befd394a3573c069f83c674c4b302ad012e81759b043c8857c80254710f42
|
|
BLAKE2b-256 checksum How to use checksums |
dcfb0ff4c724aafeb51464cea7d71d933a9f5341232433ae3a1adc7bacc5beb7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.4
|
Release files / rulog-1.0.3-py3-none-any.whl
| Download URL | rulog-1.0.3-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d078512ea4ca33c173c925803dfebae453f7418023427848c5253a206220c07c
|
|
BLAKE2b-256 checksum How to use checksums |
958eb3559862d6e40e3dbdc754114b90b81061377d1a18593f29f9a852a6ba32
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.11.4
|