Skip to content
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

Chrome Notification & Config Refreshing #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
42 changes: 26 additions & 16 deletions app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,24 @@
import mcstatus, yaml, time, threading
from bottle import route, run, template, static_file, error

last_data = None
data = {}
json_response = None

with open('config.yml', 'r') as cfg_file:
servers_config = yaml.load(cfg_file)
def update_config():
with open('config.yml', 'r') as cfg_file:
servers_config = yaml.load(cfg_file)

# c = 0.0

for category in servers_config:
print category
data[category] = {}
for server in servers_config[category]:
print "- " + server + ": " + servers_config[category][server]
ip = servers_config[category][server]
if "/" not in ip:
ip += "/25565"
status = mcstatus.McServer(ip.split("/")[0], ip.split("/")[1])
# c += 1
data[category][server] = status
for category in servers_config:
print category
data[category] = {}
for server in servers_config[category]:
print "- " + server + ": " + servers_config[category][server]
ip = servers_config[category][server]
if "/" not in ip:
ip += "/25565"
status = mcstatus.McServer(ip.split("/")[0], ip.split("/")[1])
data[category][server] = status

def update_all():
# i = 0.0
Expand Down Expand Up @@ -65,13 +64,23 @@ def schedule_update():

def schedule_json():
threading.Timer(1.5, schedule_json).start()
global last_data
last_data = json_response
global json_response
json_response = generate_json()

def schedule_config():
threading.Timer(600, schedule_config).start()
update_config()

@route('/status')
def index():
return json_response

@route('/last')
def index():
return last_data

@route('/')
def server_static():
return static_file('index.html', '..')
Expand All @@ -84,10 +93,11 @@ def error404(error):
def server_static(filename):
return static_file(filename, root = '..')

schedule_config()
schedule_update()
schedule_json()

try:
run(host='localhost', port=8080)
run(host='127.0.0.1', port=8288)
except KeyboardInterrupt:
sys.exit(0)
59 changes: 56 additions & 3 deletions populate.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,57 @@
var last_data = null;

var chances = {};

function populate() {
$.getJSON('status?' + Math.floor(Math.random()*30000), function (data) {
$.getJSON('status?' + Math.floor(Math.random() * 30000), function(data) {
var x = "";

for (var chancer in chances) {
strings = chancer.split("_-_-_");
console.log( "Strings:" );
console.log( strings );
if( strings.length == 2 && strings[0] !== undefined && strings[1] !== undefined ) {
if( data.dead[strings[0]] !== undefined && $.inArray( strings[1], data.dead[strings[0]] ) > -1 ) {

if( chances[ chancer ] == 5 ) {
var notification = new Notification('A server on is down!', {
//icon: 'http://path.to.com/image.png',
body: "Hey! " + strings[1] + " is down on the " + strings[0] + " machine!",
});
}
if( (chances[ chancer ] % 100) == 0 ) {
var notification = new Notification('It\'s been a while!!', {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Branding needs to be removed

//icon: 'http://path.to.com/image.png',
body: "Hey! " + strings[1] + " is down on the " + strings[0] + " machine!",
});
}

chances[ chancer ] = chances[ chancer ] + 1;
console.log( "Chances add one for " + chancer + ".\nTotal: " + chances[ chancer ] );
} else {
console.log( "Not B." );
delete chances[ chancer ]
}
} else {
console.log( "Not A" );
delete chances[ chancer ];
}
}

if (last_data != null) {
for (var category in last_data.alive) {
for (var entry in last_data.alive[category]) {
if (data['dead'][category] !== undefined && $.inArray(entry, data['dead'][category]) > -1) {
console.log("dead: " + category + " - " + entry);
if( chances[ category + "_-_-_" + entry ] == undefined )
chances[ category + "_-_-_" + entry ] = 1;
}
}
}

}
last_data = data;

for (var category in data.alive) {
x += "<div class=\"row align-row\">";

Expand Down Expand Up @@ -32,7 +82,10 @@ function populate() {
});
}

$(document).ready(function () {
window.setInterval(populate, 3000);
$(document).ready(function() {
if (Notification.permission !== "granted")
Notification.requestPermission();

window.setInterval(populate, 5000);
populate();
});