diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml new file mode 100644 index 0000000..367ad24 --- /dev/null +++ b/.github/workflows/pylint.yml @@ -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') diff --git a/README.MD b/README.MD index 14fb205..34c47a5 100644 --- a/README.MD +++ b/README.MD @@ -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) diff --git a/api_routes.py b/api_routes.py index a0c115c..d7811f0 100644 --- a/api_routes.py +++ b/api_routes.py @@ -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 @@ -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 = {} @@ -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()) \ No newline at end of file + """Steam charts player count route.""" + return jsonify(get_steam_charts_player_count()) diff --git a/app.py b/app.py index e5a6bc4..85ffd43 100644 --- a/app.py +++ b/app.py @@ -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") \ No newline at end of file + """Home page route.""" + return render_template("dashboard.html") diff --git a/extensions.py b/extensions.py index fd9b980..a0b124a 100644 --- a/extensions.py +++ b/extensions.py @@ -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 \ No newline at end of file +cache = Cache() # Initialize the cache object for use in the application