Initial commit
This commit is contained in:
70
main.py
Executable file
70
main.py
Executable file
@@ -0,0 +1,70 @@
|
||||
import sys
|
||||
from lxml import html
|
||||
import json
|
||||
import requests
|
||||
import time
|
||||
import telnetlib
|
||||
from connection import *
|
||||
|
||||
with open('users.json', 'r') as f:
|
||||
users = json.load(f)
|
||||
|
||||
groups = {
|
||||
'COPPER': '6351',
|
||||
'BRONZE': '6352',
|
||||
'SILVER': '6353',
|
||||
'GOLD': '6354',
|
||||
'PLATINUM': '6355',
|
||||
'DIAMOND': '6356'
|
||||
}
|
||||
|
||||
|
||||
def run(*arg):
|
||||
cmnd = b""
|
||||
for i in arg:
|
||||
if isinstance(i, int):
|
||||
i = str(i)
|
||||
cmnd = cmnd + i.encode('ascii') + b" "
|
||||
|
||||
time.sleep(0.3)
|
||||
tn.write(cmnd + b"\n")
|
||||
return tn.read_until(b"msg").decode('ascii', 'ignore')
|
||||
|
||||
|
||||
tn = telnetlib.Telnet(HOST, PORT)
|
||||
|
||||
print(tn.read_sb_data().decode('ascii'))
|
||||
run("login", USER, PASS)
|
||||
run("use", SID)
|
||||
|
||||
raw_list = run("clientlist")
|
||||
print(raw_list)
|
||||
print("USERCOUNT: " + str(raw_list.count("client_nickname")-1))
|
||||
|
||||
nick = []
|
||||
last_index = 0
|
||||
for i in range(raw_list.count("client_nickname")):
|
||||
raw_list = raw_list[raw_list.find("client_nickname=", last_index) + len("client_nickname="):]
|
||||
nick.append(raw_list.split(" ", 1)[0])
|
||||
print(raw_list.split(" ", 1)[0])
|
||||
|
||||
for nick, cldbid in users.items():
|
||||
try:
|
||||
print("Setting rank for "+nick+"; "+str(cldbid))
|
||||
page = requests.get('https://r6.tracker.network/profile/pc/' + nick)
|
||||
tree = html.fromstring(page.content)
|
||||
|
||||
if tree.xpath('//div[@class="trn-text--dimmed trn-text--center"]/text()'):
|
||||
rank = tree.xpath('//div[@class="trn-text--dimmed trn-text--center"]/text()')[0] + " "
|
||||
print("Scraped rank: " + rank)
|
||||
|
||||
for r, id in groups.items():
|
||||
if rank.startswith(r):
|
||||
run("servergroupaddclient sgid=" + str(id), "cldbid=" + str(cldbid))
|
||||
else:
|
||||
run("servergroupdelclient sgid=" + str(id), "cldbid=" + str(cldbid))
|
||||
except:
|
||||
print("Something went wrong!")
|
||||
|
||||
tn.close()
|
||||
|
||||
Reference in New Issue
Block a user