Skip to content
Merged
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
24 changes: 24 additions & 0 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Pylint

on: [push]

jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8"]
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
pip install pylint
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
2 changes: 2 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ flask-eso-dashboard/
├── app.py # Main Flask application
├── api_routes.py # API v1 routes
├── extensions.py # Add extensions like cache to app
├── .github/workflows/ # GitHub workflows
│ └── pylint.yml # Pylint
├── templates/ # HTML templates for the app
│ └── dashboard.html # Main dashboard page
├── static/ # Static assets (CSS, JS, images, videos)
Expand Down
25 changes: 16 additions & 9 deletions api_routes.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Setup API routes and cache for ESO server status and player counts."""

from flask import Blueprint, jsonify
import requests
from bs4 import BeautifulSoup
Expand All @@ -10,8 +12,9 @@

@cache.cached(timeout=120, key_prefix='eso_servers')
def get_servers():
"""Function fetching ESO server status."""
url = "https://esoserverstatus.net/"
response = requests.get(url)
response = requests.get(url, timeout=10)
soup = BeautifulSoup(response.text, 'html.parser')
servers = {}

Expand All @@ -25,41 +28,45 @@ def get_servers():
return servers

@api_v1_blueprint.route("/eso_servers")
def servers():
def eso_servers():
"""ESO server status route."""
return jsonify(get_servers())

@cache.cached(timeout=600, key_prefix='eso_current_players')
@api_v1_blueprint.route("/eso_current_players")
def eso_current_players():
"""Function fetching player count from Steam API."""
url = "https://api.steampowered.com/ISteamUserStats/GetNumberOfCurrentPlayers/v1/?appid=306130"
try:
response = requests.get(url)
response = requests.get(url, timeout=10)
data = response.json()
if data.get("response") and "player_count" in data["response"]:
player_count = data["response"]["player_count"]
else:
player_count = "Error: Unexpected API response"
except Exception as e:
except requests.exceptions.RequestException as e:
player_count = f"Error: {str(e)}"

return jsonify(player_count)

@cache.cached(timeout=600, key_prefix='steam_charts_current_players')
def get_steam_charts_player_count():
"""Function fetching player count from Steam Charts."""
url = "https://steamcharts.com/app/306130"
response = requests.get(url)
response = requests.get(url, timeout=10)
soup = BeautifulSoup(response.text, 'html.parser')
eso_current_players = {}
steam_charts_players = {}

heading = soup.select_one("#app-heading")
if heading:
nums = heading.find_all("span", class_="num")
if nums:
for idx, stat in enumerate(nums):
eso_current_players[STEAM_CHART_COUNTS[idx]] = stat.get_text(strip=True)
steam_charts_players[STEAM_CHART_COUNTS[idx]] = stat.get_text(strip=True)

return eso_current_players
return steam_charts_players

@api_v1_blueprint.route("/steam_charts_player_count")
def steam_charts_player_count():
return jsonify(get_steam_charts_player_count())
"""Steam charts player count route."""
return jsonify(get_steam_charts_player_count())
7 changes: 5 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
"""Flask application entry point."""

from flask import Flask, render_template
from extensions import cache # Import the cache object
from api_routes import api_v1_blueprint # Import the blueprint

app = Flask(__name__, static_folder='static')

cache = cache.init_app(app, config={'CACHE_TYPE': 'SimpleCache'})
cache.init_app(app, config={'CACHE_TYPE': 'SimpleCache'})

# Register the blueprint for API routes
app.register_blueprint(api_v1_blueprint, url_prefix="/api/v1")

@app.route("/")
def home():
return render_template("dashboard.html")
"""Home page route."""
return render_template("dashboard.html")
4 changes: 3 additions & 1 deletion extensions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
"""Cache extension for Flask application."""

from flask_caching import Cache

cache = Cache() # Initialize the cache object for use in the application
cache = Cache() # Initialize the cache object for use in the application