Untitled
send active apiunknown
python
2 years ago
3.4 kB
3
Indexable
Never
import os import sys import requests import time import heroku3 from time import time as timestamp from time import timezone import uvicorn import platform,socket,re,uuid import names import base64 import random from hashlib import sha1 import hmac from base64 import b85decode, b64decode from fastapi import FastAPI, Request ,Header import json from typing import Optional from fastapi.responses import JSONResponse from time import sleep import hmac from json_minify import json_minify import requests_random_user_agent key=os.environ["key"] name=os.environ["app"] def res(): heroku_conn = heroku3.from_key(key) botapp= heroku_conn.apps()[name] botapp.restart() def r(): s = requests.Session() return s.headers['User-Agent'] def sigg(data): key='f8e7a61ac3f725941e3ac7cae2d688be97f30b93' mac = hmac.new(bytes.fromhex(key), data.encode("utf-8"), sha1) digest = bytes.fromhex("42") + mac.digest() return base64.b64encode(digest).decode("utf-8") def dev(): hw=(names.get_full_name()+str(random.randint(0,10000000))+platform.version()+platform.machine()+names.get_first_name()+socket.gethostbyname(socket.gethostname())+':'.join(re.findall('..', '%012x' % uuid.getnode()))+platform.processor()) identifier=sha1(hw.encode('utf-8')).digest() key='02b258c63559d8804321c5d5065af320358d366f' mac = hmac.new(bytes.fromhex(key), b"\x42" + identifier, sha1) return (f"42{identifier.hex()}{mac.hexdigest()}").upper() def header(sid): headers = { "NDCDEVICEID": dev(), "Accept-Language": "en-US", "Content-Type": "application/json; charset=utf-8", "User-Agent":r(), "Host": "service.narvii.com", "Accept-Encoding": "gzip", "Connection": "Keep-Alive"} headers["NDCAUTH"] = f"sid={sid}" return headers def sendActive(comId: str,data:str,sid): """ Send A Active Time To Community **Returns** - **Success**: Post Request objects ( - **WssClient**: A Client With Amino Socket Functions (Class) - **Success**: Post Request objects """ data = json_minify(json.dumps(data)) headers=header(sid) headers["NDC-MSG-SIG"] =sigg(data) headers["Content-Length"] = str(len(data)) response = requests.post(f"https://service.narvii.com/api/v1/x{comId}/s/community/stats/user-active-time", headers=headers, data=data) if response.status_code == 403: error=json.dumps({"api:statuscode":69,"api:message":"wait ip is changing"}) res() return error else: resp=response.json() if resp["api:statuscode"]==110: res() return resp return resp app = FastAPI() @app.get('/') async def get_webpage(): return "coin server" @app.get('/reset') async def ress(): res() return "restarted" @app.post("/{comId}/send-active-obj/{sid}") async def submit_report(request: Request,comId:int,sid:str): data = await request.json() #print(data) #os.system("sudo service tor restart") #head=request.headers rang=40 rr=sendActive(comId,data,sid) print(rr) return rr