You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
90 lines
2.9 KiB
Python
90 lines
2.9 KiB
Python
"""
|
|
Links:
|
|
https://api.tracker.gg/api/v2/modern-warfare/standard/profile/battlenet/Hofei%232237
|
|
https://api.tracker.gg/api/v2/modern-warfare/standard/profile/battlenet/Hofei%232237/segments/killstreak?
|
|
https://api.tracker.gg/api/v2/modern-warfare/standard/profile/battlenet/Hofei%232237/segments/weapon?
|
|
"""
|
|
|
|
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
|
|
|
|
|
|
def load_toml(tomlfile):
|
|
with open(tomlfile, encoding="utf-8") as file:
|
|
inhalt = toml.loads(file.read())
|
|
return inhalt
|
|
|
|
|
|
SKRIPTPFAD = os.path.abspath(os.path.dirname(__file__))
|
|
CONFIG = load_toml(os.path.join(SKRIPTPFAD, "config.toml"))
|
|
STANDARD_STATS_URL = "https://api.tracker.gg/api/v2/modern-warfare/standard/profile/battlenet/{}"
|
|
|
|
|
|
def get_json_data(url):
|
|
r = requests.get(url)
|
|
return json.loads(r.text)
|
|
|
|
|
|
def check_user(user):
|
|
user_db, _ = db.CoDUser.get_or_create(
|
|
user=user
|
|
)
|
|
|
|
|
|
def get_standard_statistik(url, user):
|
|
url = url.format(user)
|
|
data = get_json_data(url)["data"]
|
|
check_user(user)
|
|
|
|
stats = data["segments"][0]["stats"]
|
|
db.CoDStandardStats.create(
|
|
ts=datetime.datetime.utcnow(),
|
|
user=user,
|
|
kills=stats["kills"]["value"],
|
|
deaths=stats["deaths"]["value"],
|
|
assists=stats["assists"]["value"],
|
|
suicides=stats["suicides"]["value"],
|
|
total_games_played=stats["totalGamesPlayed"]["value"],
|
|
wins=stats["wins"]["value"],
|
|
losses=stats["losses"]["value"],
|
|
ties=stats["ties"]["value"],
|
|
time_played_total=stats["timePlayedTotal"]["value"],
|
|
average_life=stats["averageLife"]["value"],
|
|
career_score=stats["careerScore"]["value"],
|
|
headshots=stats["headshots"]["value"],
|
|
total_shots=stats["totalShots"]["value"],
|
|
hits=stats["hits"]["value"],
|
|
misses=stats["misses"]["value"]
|
|
)
|
|
|
|
|
|
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:
|
|
|
|
db.DATABASE.initialize(PostgresqlDatabase(CONFIG["pg"]["pgdb"],
|
|
user=CONFIG["pg"]["pguser"], password=CONFIG["pg"]["pgpw"],
|
|
host="127.0.0.1",
|
|
port=server.local_bind_port))
|
|
db.create_tables()
|
|
try:
|
|
db.create_hypertable()
|
|
except DatabaseError:
|
|
db.DATABASE.rollback()
|
|
for user in CONFIG["users"]:
|
|
get_standard_statistik(STANDARD_STATS_URL, user)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|
|
"https://api.tracker.gg/api/v2/modern-warfare/standard/profile/battlenet/DaZimmi85%232712" |