-
-
Notifications
You must be signed in to change notification settings - Fork 127
feat: Web-server implementation using flask #163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arctumn
wants to merge
20
commits into
LeagueOfPoro:master
Choose a base branch
from
arctumn:web-server-pr
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 10 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
37a5151
Web-server implementation using flask
a59ea9e
changes title to Capsule Farmer Evolved
940830a
changes localhost to 0.0.0.0 to allow remote connections
cadcb6c
adds icon to page, reduces the number of calls to every 10 secs
6ba0e78
adds html lang to en-us
cbc3d85
Adds controllable settings, via .env or by dockerfile
3f890ac
required pipfile
1643ac4
removes a weird arguments print
842fd9d
Readjusting dockerfile
982e706
fixes wrong table generation
26cad96
adjust on page css, removed .env dependecy switched to config.yaml
eb3681a
updated pipfile
a447e1b
removed docker env variables
a5611e6
Resolved merge conflict
b369049
Merge branch 'master' into web-server-pr
1c65a89
Merge branch 'master' into web-server-pr
dd727f7
fix break after merge
5673489
give table max width, readjust web-page to match the GUI table
334977d
Merge branch 'master' into web-server-pr
111b4c7
resolve merge conflits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.