Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '3'

services:
skinstats:
build: ./skinstats
depends_on:
- skin_ids
environment:
- steam_user=${steam_user}
- steam_pass=${steam_pass}
ports:
- "5000:5000"
restart: on-failure
skin_ids:
build: ./skin_ids
healthcheck:
test: wget -qO - skin_ids:5001/get_skin_ids > /dev/null || exit 1
interval: 0s
timeout: 1s
retries: 300
4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

36 changes: 36 additions & 0 deletions skin_ids/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
FROM debian:stretch-slim

RUN apt-get update
RUN apt-get install -y --no-install-recommends --no-install-suggests \
lib32stdc++6 \
lib32gcc1 \
wget \
ca-certificates \
python3 \
python3-pip \
python3-setuptools \
htop \
vim \
ipython3
RUN useradd -m steam
RUN su steam -c \
"mkdir -p /home/steam/steamcmd \
&& cd /home/steam/steamcmd \
&& wget -qO- 'https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz' | tar zxf -"
RUN apt-get clean autoclean
RUN apt-get autoremove -y
RUN rm -rf /var/lib/{apt,dpkg,cache,log}/

USER steam

WORKDIR /home/steam

RUN steamcmd/steamcmd.sh +login anonymous +force_install_dir ../games +app_update 740 +quit

RUN mkdir static

COPY . .

RUN pip3 install --user --no-cache-dir -r requirements.txt

CMD [ "python3", "main.py" ]
82 changes: 82 additions & 0 deletions skin_ids/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import atexit
import json
import logging
import re
import subprocess

from apscheduler.schedulers.background import BackgroundScheduler
from flask import Flask

logging.basicConfig(format="%(asctime)s | %(name)s | thread:%(thread)s | %(levelname)s | %(message)s",
level=logging.INFO)
LOG = logging.getLogger('SKIN ID GETTER')

app = Flask(__name__, static_url_path='')


@app.route('/')
def main():
return "SUP FUCKERS"


@app.route('/get_skin_ids')
def get_items():
return app.send_static_file('skin_ids.json')


def update_csgo_items():
p = subprocess.run(['steamcmd/steamcmd.sh', '+login', 'anonymous', '+force_install_dir', '../games', '+app_update', '740', '+quit'], stdout=subprocess.DEVNULL)
if p.returncode == 0:
update_items_json()
else:
LOG.error('Failed to update game')


def update_items_json():
name_matcher = re.compile(r'^\s*"(Paint[^"]+_Tag)"\s*"([^"]+)"$', re.I)
names = {}
with open('games/csgo/resource/csgo_english.txt', 'r', encoding='utf-16-le') as f:
for line in f.readlines():
match = name_matcher.match(line)
if match:
tag, name = match.groups()
tag = tag.lower()
names[tag] = name

id_matcher = re.compile(r'^.*"(\d+)"$')
tag_matcher = re.compile(r'^.*"description_tag".*"#(.*)"$')
ids = {}
with open('games/csgo/scripts/items/items_game.txt', 'r') as f:
in_paint_kits = True
for line in f.readlines():
if not in_paint_kits and '"paint_kits"' in line:
in_paint_kits = True
continue

id_match = id_matcher.match(line)
if id_match:
cur_id = id_match.groups()[0]
continue

tag_match = tag_matcher.match(line)
if tag_match:
tag = tag_match.groups()[0]
tag = tag.lower()
ids[cur_id] = tag

final_map = {}
for id_num, tag in ids.items():
final_map[id_num] = names.get(tag)

with open('static/skin_ids.json', 'w') as f:
f.write(json.dumps(final_map))


if __name__ == '__main__':
update_csgo_items()
sched = BackgroundScheduler()
sched.add_job(update_csgo_items, 'interval', minutes=30)
sched.start()
atexit.register(lambda: sched.shutdown())

app.run(debug=True, use_reloader=False, host='0.0.0.0', port=5001)
2 changes: 2 additions & 0 deletions skin_ids/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask
apscheduler
9 changes: 9 additions & 0 deletions skinstats/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3

WORKDIR /usr/src/app

COPY . .

RUN pip install --no-cache-dir -r requirements.txt

CMD [ "python", "./skinstats.py" ]
Loading