Skip to content
This repository has been archived by the owner on Feb 2, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from LeagueOfPoro/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
LeagueOfPoro committed Jul 7, 2022
2 parents d3538f1 + b690f93 commit abca555
Show file tree
Hide file tree
Showing 4 changed files with 102 additions and 18 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# Sensitive configs
config.dev.yaml

# Byte-compiled optimized DLL files
__pycache__
.py[cod]
Expand Down
35 changes: 31 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ This tool makes the Chrome browser watch the matches for you!
## Features
- Checks for new live matches
- Closes finished matches
- Automatically logs user in
- Runs in background

## Requirements
- [Chrome browser](https://www.google.com/chrome/)
Expand All @@ -20,8 +22,34 @@ This tool makes the Chrome browser watch the matches for you!
3. Log in
4. Sit back and relax

## Configuration
**The configuration file ([config.yaml](config.yaml)) must be present in the same folder as the executable!**

Default configuration:
```yaml
version: 1.1

headless: false
autologin:
enable: false
```
If you wish to enable automatic login and to run the browser in the background:
```yaml
version: 1.1

headless: true
autologin:
enable: true
username: YourUsername
password: YourPassword
```
## Installation (simple)
Download and run the latest CapsuleFarmer.exe from [Releases tab](https://github.com/LeagueOfPoro/EsportsCapsuleFarmer/releases).
1. Download and run the latest CapsuleFarmer.zip from [Releases tab](https://github.com/LeagueOfPoro/EsportsCapsuleFarmer/releases)
2. Extract the archive
3. (Optional) Edit the configuration file with a text editor (e.g. Notepad) - see [Configuration](#configuration) for details
4. Run `CapsuleFarmer.exe`

## Installation (advanced)

Expand All @@ -33,16 +61,15 @@ Download and run the latest CapsuleFarmer.exe from [Releases tab](https://github
1. Clone this repo - `git clone https://github.com/LeagueOfPoro/EsportsCapsuleFarmer.git`
2. Move to the directory - `cd EsportsCapsuleFarmer`
3. Install the Python virtual environment - `pipenv install`
4. Run the tool - `pipenv run python .\main.py`
4. (Optional) Edit the configuration file
5. Run the tool - `pipenv run python .\main.py`

### Create EXE
1. `pipenv install --dev`
2. `pipenv run pyinstaller -F --icon=poro.ico .\main.py`

## Future features
- Force the video player to use Twitch (in progress)
- Automatic log in
- Headless browser (if possible)

## Support my work
<a href='https://www.youtube.com/channel/UCwgpdTScSd788qILhLnyyyw/join' target='_blank'><img height='35' style='border:0px;height:46px;' src='https://share.leagueofporo.com/yt_member.png' border='0' alt='Become a channel member on YouTube' />
7 changes: 7 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 1.1

headless: false # set to true to run the browser in the background; autologin needs to be enabled
autologin:
enable: false # set to true to enable automatic login
username: YourUsername
password: YourPassword
75 changes: 61 additions & 14 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import logging
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as ec
from selenium.common.exceptions import TimeoutException
import chromedriver_autoinstaller
import time
from pprint import pprint
Expand All @@ -13,9 +16,11 @@
"https://lolesports.com/live/lpl":"https://lolesports.com/live/lpl/lpl",
"https://lolesports.com/live/lck":"https://lolesports.com/live/lck/lck",
"https://lolesports.com/live/lec":"https://lolesports.com/live/lec/lec",
"https://lolesports.com/live/lcs":"https://lolesports.com/live/lcs/lcs"
"https://lolesports.com/live/lcs":"https://lolesports.com/live/lcs/lcs",
"https://lolesports.com/live/cblol_academy":"https://lolesports.com/live/cblol_academy/cblol"
}
CONFIG_LOCATION="config.yaml"
#CONFIG_LOCATION="config.dev.yaml" # development only

def getLiveMatches(driver):
matches = []
Expand All @@ -28,40 +33,82 @@ def readConfig(filepath):
with open(filepath, "r") as f:
return yaml.safe_load(f)

# def logIn(driver, username, password):
# driver.get("https://lolesports.com/")
# time.sleep(2)
# pass
def logIn(driver, username, password):
driver.get("https://lolesports.com/")
time.sleep(2)

log.info("Moving to log in page")
el = driver.find_element(by=By.CSS_SELECTOR, value="a[data-riotbar-link-id=login]")
driver.execute_script("arguments[0].click();", el)

log.info("Logging in")

wait = WebDriverWait(driver, 20)
usernameInput = wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "input[name=username]")))
usernameInput.send_keys(username)
passwordInput = wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "input[name=password]")))
passwordInput.send_keys(password)
submitButton = wait.until(ec.element_to_be_clickable((By.CSS_SELECTOR, "button[type=submit]")))
driver.execute_script("arguments[0].click();", submitButton)

log.info("Credentials submited")
# wait until the login process finishes
wait.until(ec.presence_of_element_located((By.CSS_SELECTOR, "div.riotbar-summoner-name")))



#https://auth.riotgames.com/login
###################################################
log = logging.getLogger("League of Poro")
log.setLevel('DEBUG')
chromedriver_autoinstaller.install()

hasValidConfig = False
username = None
password = None
hasAutoLogin = False
isHeadless = False
username = "NoUsernameInConfig" # None
password = "NoPasswordInConfig" # None
try:
config = readConfig(CONFIG_LOCATION)
hasValidConfig = True
pprint(config)
if "autologin" in config:
if config["autologin"]["enable"]:
username = config["autologin"]["username"]
password = config["autologin"]["password"]
hasAutoLogin = True
if "headless" in config:
isHeadless = config["headless"]
except FileNotFoundError:
log.warn("Configuration file not found. IGNORING...")
log.warning("Configuration file not found. IGNORING...")
except (yaml.scanner.ScannerError, yaml.parser.ParserError) as e:
log.warn("Invalid configuration file. IGNORING...")
log.warning("Invalid configuration file. IGNORING...")
except KeyError:
log.warning("Configuration file is missing mandatory entries. Using default values instead...")

options = webdriver.ChromeOptions()
options.add_argument('log-level=3')
if isHeadless and hasAutoLogin:
options.add_argument("--headless")
driver = webdriver.Chrome(options=options)
driver.get("https://lolesports.com/")
time.sleep(2)

if hasAutoLogin:
try:
logIn(driver, username, password)
except TimeoutException:
log.error("Automatic login failed, incorrect credentials?")
if isHeadless:
driver.quit()
log.info("Exitting...")
exit()

while not driver.find_elements(by=By.CSS_SELECTOR, value="div.riotbar-summoner-name"):
log.info("Waiting for log in")
if not hasAutoLogin:
log.info("Waiting for log in")
else:
log.info("Please log in manually")
time.sleep(5)
log.info("Okay, we're in")
time.sleep(5)

currentWindows = {}
originalWindow = driver.current_window_handle
Expand All @@ -70,7 +117,7 @@ def readConfig(filepath):
driver.switch_to.window(originalWindow) # just to be sure
time.sleep(5)
driver.get("https://lolesports.com/")
time.sleep(15)
time.sleep(5)
liveMatches = getLiveMatches(driver)
log.info(f"{len(liveMatches)} matches live")

Expand Down

0 comments on commit abca555

Please sign in to comment.