Untitled

mail@pastecode.io avatar
unknown
python
2 months ago
3.5 kB
10
Indexable
Never
import json
import hashlib
from hashlib import sha1
import requests
import hmac
import time
from base64 import b64encode
from hmac import new
from uuid import uuid4
from json_minify import json_minify

comId = 237285270
def timers():
     times =[
     {"start": int(time.time()), "end": int(time.time())+300}
     for times in range(30)]
     return times
class Client:
    def __init__(self, deviceId=None) -> None:
        self.api = f'https://proxy-nine-lac.vercel.app/proxy?url=https://service.narvii.com/api/v1'
        self.device_Id = self.dev() if not deviceId else deviceId
        self.headers = {
            "NDCDEVICEID": self.device_Id,
            #"NDC-MSG-SIG": dev.device_id_sig,
            "Accept-Language": "en-US",
            "Content-Type": "application/json; charset=utf-8",
            "User-Agent": "Apple iPhone12,1 iOS v15.5 Main/3.12.2",
            # "Host": "service.narvii.com",
            "Accept-Encoding": "gzip",
            "Connection": "Keep-Alive"
        }
        self.sid = None


    def generate_signature_message(self, data: str) -> str:
        signature_message = b64encode(
            bytes.fromhex("19") + new(bytes.fromhex("dfa5ed192dda6e88a12fe12130dc6206b1251e44"), data.encode("utf-8"), sha1).digest()).decode("utf-8")
        self.headers["NDC-MSG-SIG"] = signature_message
        return signature_message

    def dev(self):
        data = uuid4().bytes
        return ("19" + data.hex() + hmac.new(bytes.fromhex("E7309ECC0953C6FA60005B2765F99DBBC965C8E9"),bytes.fromhex("19") + data, hashlib.sha1).hexdigest()).upper()

    def login(self, email: str, password: str):
                data = json.dumps({
                    "email": email,
                    "v": 2,
                    "secret": f"0 {password}",
                    "deviceID": self.device_Id,
                    "clientType": 100,
                    "action": "normal",
                    "timestamp": int(time.time() * 1000)
                })
                self.headers["NDC-MSG-SIG"]=self.generate_signature_message(data)
                response = requests.post(f"{self.api}/g/s/auth/login", headers=self.headers, data=data).json()
                try:
                    self.sid = response["sid"]
                except:pass
                return response

    def join_community(self, comId: int):
        data = json.dumps({"timestamp": int(time.time() * 1000)})
        self.headers["NDC-MSG-SIG"]=self.generate_signature_message(data=data)
        response = requests.post(f"{self.api}/x{comId}/s/community/join?sid={self.sid}", headers=self.headers, data=data).json()
        return response
    
    def send_active_object(self, comId: int, timers: list = None, tz: int = -time.timezone // 1000):
        data = {
            "userActiveTimeChunkList": timers,
            "timestamp": int(time.time() * 1000),
            "optInAdsFlags": 2147483647,
            "timezone": tz
        }
        data = json_minify(json.dumps(data))
        self.headers["NDC-MSG-SIG"]=self.generate_signature_message(data=data)
        response = requests.post(f"{self.api}/x{comId}/s/community/stats/user-active-time?sid={self.sid}", headers=self.headers, data=data).json()
        return response


client = Client(deviceId="")

print(client.login("55", ""))
print(client.sid)
print(client.join_community(comId))
for _ in range(24):
    print(client.send_active_object(comId=comId,timers=timers()))
    time.sleep(10)
Leave a Comment