Skip to content
Open
Show file tree
Hide file tree
Changes from 10 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
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ ENV LC_ALL C.UTF-8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONFAULTHANDLER 1

# Webserver settings
ENV HOST="0.0.0.0"
ENV PORT="5000"
ENV WEBSERVER="False"

FROM base AS python-deps

# Install pipenv and compilation dependencies
Expand Down
3 changes: 3 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ beautifulsoup4 = "*"
pyyaml = "*"
rich = "*"
pyjwt = "*"
flask = "*"
flask-socketio = "*"
python-dotenv = "*"

[dev-packages]
autopep8 = "*"
Expand Down
50 changes: 50 additions & 0 deletions src/WebServer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
from flask_socketio import SocketIO,emit
from threading import Thread,Lock
from flask import Flask, render_template
from Stats import Stats


class WebServerThread(Thread):
def __init__(self, host, port,stats:Stats):
Thread.__init__(self)
self.host = host
self.port = port
self.app = Flask(__name__)
self.socketio = SocketIO(self.app,cors_allowed_origins="*")
self.stats = stats
self.thread = None
self.thread_lock = Lock()

def run(self):
# Default route
@self.app.route("/")
def default():
return render_template('index.html')


def handle_poro_data():
"""Sends the account data to front-end server"""
while True:
self.socketio.emit('my_response',{'stats':self.stats.accountData})
self.socketio.sleep(10)

@self.socketio.event
def connect():
with self.thread_lock:
if self.thread is None:
self.thread = self.socketio.start_background_task(handle_poro_data)
self.socketio.emit('my_response',{'stats':self.stats.accountData})

# Start the Flask web server
self.socketio.run(self.app, host=self.host, port=self.port)

class PoroWebServer(object):
def __init__(self, host, port,stats):
self.host = host
self.port = port
self.stats = stats

def start(self):
# Create and start the web server thread
web_thread = WebServerThread(self.host, self.port,self.stats)
web_thread.start()
19 changes: 17 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from distutils.util import strtobool
from dotenv import load_dotenv
from DataProviderThread import DataProviderThread
from Exceptions.CapsuleFarmerEvolvedException import CapsuleFarmerEvolvedException
from FarmThread import FarmThread
Expand All @@ -13,13 +15,13 @@
from time import sleep
from Restarter import Restarter
from SharedData import SharedData

import os
from Stats import Stats
from VersionManager import VersionManager
from WebServer import PoroWebServer

CURRENT_VERSION = 1.3


def init() -> tuple[logging.Logger, Config]:
parser = argparse.ArgumentParser(description='Farm Esports Capsules by watching all matches on lolesports.com.')
parser.add_argument('-c', '--config', dest="configPath", default="./config.yaml",
Expand Down Expand Up @@ -55,6 +57,19 @@ def main(log: logging.Logger, config: Config):
stats.initNewAccount(account)
restarter = Restarter(stats)

log.info(f"Starting the WebServer thread.")
# Web-server settings
load_dotenv()
host = os.getenv('HOST','0.0.0.0')
Comment thread
arctumn marked this conversation as resolved.
Outdated
port = int(os.getenv('PORT','5000'))
enableWebServer = strtobool(os.getenv('WEBSERVER','False'))

if enableWebServer:
print(f"Web-server online: http://{host}:{port}/")
webServer = PoroWebServer(host,port,stats)
webServer.daemon = True
webServer.start()

log.info(f"Starting a GUI thread.")
guiThread = GuiThread(log, config, stats, locks)
guiThread.daemon = True
Expand Down
126 changes: 126 additions & 0 deletions src/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<!DOCTYPE html>
<html lang="en-us">

<head>
<meta charset="UTF-8">
<title>Capsule Farmer Evolved</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.1.2/socket.io.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/x-icon" href="https://raw.githubusercontent.com/LeagueOfPoro/CapsuleFarmerEvolved/master/poro.ico">
<style>
body {
background-color: #141213;
}

table {
font-family: Arial, Helvetica, sans-serif;
border-collapse: collapse;
width: 100%;
}

td,
th {
border: 1px solid #ddd;
padding: 8px;
}

tr {
color: #f2f2f2;
}


th {
padding-top: 12px;
padding-bottom: 12px;
text-align: left;
color: white;
}
.center {
margin: auto;
width: 50%;
padding: 10px;
}
img {
width: 100%;
}
</style>
</head>

<body>
<div class="center">
<img src="https://raw.githubusercontent.com/LeagueOfPoro/CapsuleFarmerEvolved/master/.github/banner.png" alt="Capsule Farmer Evolved"/>
<table id="statsTable">
<thead>
<tr>
<th>Account</th>
<th>Status</th>
<th>Live Matches</th>
<th>Heartbeat</th>
<th>Last Drop</th>
<th>Total Drops</th>
<th>Failed Login Counter</th>

</tr>
</thead>
<tbody>
</tbody>
</table>
</div>

<script type="text/javascript">
var socket = io.connect('http://' + document.domain + ':' + location.port);

// Listen for the 'my_response' event
socket.on('my_response', function (data) {
var responseElement = document.getElementById('response');
displayStatsTable(data.stats);
});

// Display the stats in a table
function displayStatsTable(stats) {
var tableBody = document.querySelector('#statsTable tbody');
tableBody.innerHTML = '';

for (var username in stats) {
var statsRow = document.createElement('tr');
var userStats = stats[username];

var usernameCell = document.createElement('td');
usernameCell.innerText = username;
statsRow.appendChild(usernameCell);

var statusCell = document.createElement('td');
//force typing in js
const status = userStats.status + ""
const statusList = status.replace("[", "").split("]")
statusCell.style.color = statusList[0]
statusCell.innerText = statusList[1]
statsRow.appendChild(statusCell);

var liveMatchesCell = document.createElement('td');
liveMatchesCell.innerText = userStats.liveMatches;
statsRow.appendChild(liveMatchesCell);

var lastCheckCell = document.createElement('td');
lastCheckCell.innerText = userStats.lastCheck;
statsRow.appendChild(lastCheckCell);

var lastDropCell = document.createElement('td');
lastDropCell.innerText = userStats.lastDrop;
statsRow.appendChild(lastDropCell);

var totalDropsCell = document.createElement('td');
totalDropsCell.innerText = userStats.totalDrops;
statsRow.appendChild(totalDropsCell);

var failedLoginCounterCell = document.createElement('td');
failedLoginCounterCell.innerText = userStats.failedLoginCounter;
statsRow.appendChild(failedLoginCounterCell);

tableBody.appendChild(statsRow);
}
}
</script>
</body>

</html>