making it clear for the branch
This commit is contained in:
parent
4cf86b35d5
commit
de8ae5800f
Binary file not shown.
@ -1 +0,0 @@
|
||||
6969
|
@ -1,7 +0,0 @@
|
||||
userNames = {"1":"boyan", "2":"nikola"}
|
||||
usersCoins = {"1":"200", "2":"100"}
|
||||
|
||||
def checkBalance(ID):
|
||||
userName = userNames[f"{ID}"]
|
||||
userCoins = usersCoins[f"{ID}"]
|
||||
return userName, userCoins
|
@ -1,39 +0,0 @@
|
||||
import asyncio
|
||||
import websockets
|
||||
import logging
|
||||
from ratelimit import limits
|
||||
import time
|
||||
from databasefornow import *
|
||||
|
||||
logger = logging.getLogger('websockets')
|
||||
logger.setLevel(logging.INFO)
|
||||
logger.addHandler(logging.StreamHandler())
|
||||
|
||||
print("Ready")
|
||||
|
||||
# calls in number of requests
|
||||
# period in seconds
|
||||
@limits(calls=20, period=5)
|
||||
async def serveStuff(websocket, path):
|
||||
requestText = await websocket.recv()
|
||||
print(requestText)
|
||||
if requestText == "STATUSONCOIN":
|
||||
file = open("currency.txt","r")
|
||||
currencyStatus = file.readline()
|
||||
file.close()
|
||||
await websocket.send(currencyStatus)
|
||||
|
||||
# bad way to send balance to given user - FIX!!!
|
||||
elif requestText == "STATUSONUSER":
|
||||
name, balance = checkBalance("1")
|
||||
print(name)
|
||||
await websocket.send(f"Your balance is: {balance}")
|
||||
await websocket.send(f"Welcome, {name}!")
|
||||
else:
|
||||
await websocket.send("We don't accept DoS")
|
||||
|
||||
|
||||
start_server = websockets.serve(serveStuff, "localhost", 8765)
|
||||
|
||||
asyncio.get_event_loop().run_until_complete(start_server)
|
||||
asyncio.get_event_loop().run_forever()
|
@ -1,35 +0,0 @@
|
||||
@import url(https://fonts.googleapis.com/css?family=Roboto:300);
|
||||
|
||||
:root {
|
||||
--base-grid: 8px;
|
||||
--colour-white: #fff;
|
||||
--colour-black: #1a1a1a;
|
||||
}
|
||||
@viewport {
|
||||
width: device-width ;
|
||||
zoom: 1.0 ;
|
||||
}
|
||||
|
||||
*,
|
||||
:after,
|
||||
:before {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
html {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
background-position: 100%;
|
||||
}
|
||||
|
||||
body {
|
||||
position: absolute;
|
||||
left: 50%;
|
||||
margin-right: -50%;
|
||||
transform: translate(-50%, -50%);
|
||||
top: 50%;
|
||||
font-size: 1.2em;
|
||||
font-family: 'Roboto', sans-serif;
|
||||
line-height: 1.4;
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en" dir="ltr">
|
||||
<head>
|
||||
<link rel="stylesheet" href="css/home.css">
|
||||
<link rel="stylesheet" href="http://github.hubspot.com/odometer/themes/odometer-theme-default.css">
|
||||
<script src="http://github.hubspot.com/odometer/odometer.js"></script>
|
||||
<meta charset="utf-8">
|
||||
<title>Currency site</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1 id="odometer" class="odometer">This is where you'll see the thing</h1>
|
||||
<script type="text/javascript" src="scripts/getCurrentCoins.js"></script>
|
||||
<br>
|
||||
<h2 id="balance">Your balance is:</h2>
|
||||
<h2 id="username"></h2>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1 +0,0 @@
|
||||
document.cookie = "id=1";
|
@ -1,37 +0,0 @@
|
||||
socketAdress="ws://localhost:8765"
|
||||
// Lacking protocol for ids lmao
|
||||
document.cookie = "id=2";
|
||||
|
||||
function currencyTicker(){
|
||||
var ws = new WebSocket(socketAdress);
|
||||
|
||||
ws.onopen = function(){
|
||||
console.log("Connection is Established");
|
||||
ws.send("STATUSONCOIN");
|
||||
};
|
||||
|
||||
ws.onmessage = function(evt) {
|
||||
var received_msg = evt.data;
|
||||
w = document.getElementById("odometer").innerHTML = received_msg;
|
||||
|
||||
};
|
||||
}
|
||||
|
||||
function userBalance(){
|
||||
var ws = new WebSocket(socketAdress);
|
||||
ws.onopen = function(){
|
||||
ws.send("STATUSONUSER");
|
||||
};
|
||||
|
||||
ws.onmessage = function(evt){
|
||||
var balanceStatus = evt.data;
|
||||
// this doesnt work, fix pls
|
||||
w = document.getElementById("balance").innerHTML = balanceStatus;
|
||||
ws.onmessage = function(evt){
|
||||
w = document.getElementById("username").innerHTML = evt.data;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
var t=setInterval(currencyTicker,5000);
|
||||
var y=setInterval(userBalance,5000);
|
Reference in New Issue
Block a user