|
|
|
@ -8,12 +8,12 @@ https://api.tracker.gg/api/v2/modern-warfare/standard/profile/battlenet/Hofei%23
|
|
|
|
|
import requests
|
|
|
|
|
import json
|
|
|
|
|
import toml
|
|
|
|
|
import pprint
|
|
|
|
|
import db_model as db
|
|
|
|
|
import datetime
|
|
|
|
|
from peewee import PostgresqlDatabase, DatabaseError
|
|
|
|
|
import os
|
|
|
|
|
from sshtunnel.sshtunnel import SSHTunnelForwarder
|
|
|
|
|
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def load_toml(tomlfile):
|
|
|
|
@ -38,6 +38,43 @@ def check_user(user):
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_game_mode_stats_raw(user):
|
|
|
|
|
url = "https://cod.tracker.gg/modern-warfare/profile/battlenet/{}/mp/modes".format(user)
|
|
|
|
|
source = requests.get(url).text
|
|
|
|
|
soup = BeautifulSoup(source, features="html5lib")
|
|
|
|
|
scripts = [script.string for script in soup.find_all("script") if script.string]
|
|
|
|
|
initial_state_script = None
|
|
|
|
|
for script in scripts:
|
|
|
|
|
if "__INITIAL_STATE__" in script:
|
|
|
|
|
initial_state_script = script
|
|
|
|
|
break
|
|
|
|
|
if not initial_state_script:
|
|
|
|
|
print("Script not found!")
|
|
|
|
|
return None
|
|
|
|
|
# NB: This can break easily!
|
|
|
|
|
initial_state_script = initial_state_script.replace("window.__INITIAL_STATE__=", "")
|
|
|
|
|
initial_state_script = initial_state_script.replace(
|
|
|
|
|
";(function(){var s;(s=document.currentScript||document.scripts[document.scripts.length-1])"
|
|
|
|
|
".parentNode.removeChild(s);}());",
|
|
|
|
|
"",
|
|
|
|
|
)
|
|
|
|
|
data = json.loads(initial_state_script)
|
|
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_hc_domination_stats(stats, user):
|
|
|
|
|
db.CoDHcDominationStats.create(
|
|
|
|
|
ts=datetime.datetime.utcnow(),
|
|
|
|
|
user=user,
|
|
|
|
|
kills=stats["kills"]["value"],
|
|
|
|
|
deaths=stats["deaths"]["value"],
|
|
|
|
|
score=stats["score"]["value"],
|
|
|
|
|
time_played=stats["timePlayed"]["value"],
|
|
|
|
|
captures=stats["captures"]["value"],
|
|
|
|
|
defends=stats["defends"]["value"]
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_standard_statistik(url, user):
|
|
|
|
|
url = url.format(user)
|
|
|
|
|
data = get_json_data(url)["data"]
|
|
|
|
@ -65,8 +102,14 @@ def get_standard_statistik(url, user):
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
def game_mode_handler(data, user):
|
|
|
|
|
for _, value in data.items():
|
|
|
|
|
for datensatz in value:
|
|
|
|
|
if datensatz["attributes"]["key"] == "hc_dom":
|
|
|
|
|
get_hc_domination_stats(datensatz["stats"], user)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
|
with SSHTunnelForwarder(
|
|
|
|
|
(CONFIG["ssh"]["ip_server"], CONFIG["ssh"]["ssh_port"]), ssh_username=CONFIG["ssh"]["user"],
|
|
|
|
|
ssh_password=CONFIG["ssh"]["pw"], remote_bind_address=('127.0.0.1', CONFIG["pg"]["pgport"])) as server:
|
|
|
|
@ -77,14 +120,16 @@ def main():
|
|
|
|
|
port=server.local_bind_port))
|
|
|
|
|
db.create_tables()
|
|
|
|
|
try:
|
|
|
|
|
db.create_hypertable()
|
|
|
|
|
db.create_hypertables()
|
|
|
|
|
except DatabaseError:
|
|
|
|
|
db.DATABASE.rollback()
|
|
|
|
|
for user in CONFIG["users"]:
|
|
|
|
|
get_standard_statistik(STANDARD_STATS_URL, user)
|
|
|
|
|
|
|
|
|
|
data = get_game_mode_stats_raw(user)
|
|
|
|
|
if data is not None:
|
|
|
|
|
game_mode_handler(data['stats-v2']['segments'], user)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
main()
|
|
|
|
|
|
|
|
|
|
"https://api.tracker.gg/api/v2/modern-warfare/standard/profile/battlenet/DaZimmi85%232712"
|