Skip to content
This repository has been archived by the owner on Sep 11, 2021. It is now read-only.

Commit

Permalink
Add automatic check for new releases of LoLBuilds
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiaswold committed Jul 29, 2020
1 parent 1c01e48 commit 9e21319
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
16 changes: 9 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import os
import sys

import sources
from sources import SOURCES
from utils import config, versions

LOLBUILDS_VERSION = "1.2.0"


def clear():
""" Clears the terminal """
Expand All @@ -18,16 +20,19 @@ def print_script_info():
""" Prints script title and version info """
print("#####################")
print("# LoLBuilds #")
print("# v1.1.0 #")
print(f"# v{LOLBUILDS_VERSION} #")
print("# by Mathias Wold #")
print("#####################")
print()

# check for new releases of LoLBuilds
versions.check_lolbuilds_version(LOLBUILDS_VERSION)

# compare local item set version to current source and LoL version to check if item sets are outdated
current_lol_version = versions.get_lol_version()
print(f"Current LoL version: {current_lol_version}")
print()
for source in sources.SOURCES:
for source in SOURCES:
versions.check_source_version(source, current_lol_version)
print()

Expand Down Expand Up @@ -86,9 +91,6 @@ def main():

update_league_path()

# imports all sources from sources/__init__.py
SOURCES = sources.SOURCES

# choose between importing or deleting item sets
answer = None

Expand Down Expand Up @@ -121,7 +123,7 @@ def main():
else:
# delete old item sets and import new ones from all sources
# uses multiprocessing to import from multiple sources at once

# for macos support
if sys.platform == "darwin":
multiprocessing.set_start_method("fork")
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ pycodestyle==2.6.0
requests==2.23.0
soupsieve==2.0.1
urllib3==1.25.9
packaging==20.4
30 changes: 28 additions & 2 deletions utils/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,36 @@
from datetime import date

import requests
from bs4 import BeautifulSoup
from packaging import version

from utils import config


def check_lolbuilds_version(local_version):
""" Compares the local version of LoLBuilds to the latest release from github """

response = requests.get(
"https://github.com/MathiasWold/lolbuilds/releases/latest")

html = response.text

soup = BeautifulSoup(html, "html.parser")

latest_version = soup.find(
"span", {"class": "css-truncate-target"}).text.replace("v", "")

# if local version is outdated
if version.parse(local_version) < version.parse(latest_version):
print(f"A new release of LoLBuilds is available! (v{latest_version})")
print("---> Download from https://github.com/MathiasWold/lolbuilds")
print()
answer = None
while answer == None:
answer = input("Press any key to continue")
print()


def get_lol_version():
""" Get current League of Legends version """
versions = json.loads(requests.get(
Expand All @@ -24,7 +50,7 @@ def check_source_version(source, lol_version):
if float(lol_version) > float(source_version):
source_outdated = " (Not updated to new patch yet)"
except:
# source_verson is not a number
# source_version is not a number
pass

local_version = config.get(source.name)
Expand All @@ -33,7 +59,7 @@ def check_source_version(source, lol_version):
if float(source_version) > float(local_version):
local_outdated = " (outdated!)"
except:
# source_verson is not a number
# local_version is not a number
pass

print(
Expand Down

0 comments on commit 9e21319

Please sign in to comment.