Changeset - d5f3c416fe84
[Not reviewed]
default
0 1 0
Dennis Fink - 11 years ago 2014-01-24 00:16:12
dennis.fink@c3l.lu
log when server is set to offline or unknown
1 file changed with 3 insertions and 0 deletions:
0 comments (0 inline, 0 general)
ennstatus/status/functions.py
Show inline comments
 
import os
 
import os.path
 
import json
 

	
 
from collections import defaultdict
 
from datetime import datetime
 

	
 
from flask import current_app
 

	
 
def _check_server(data):
 

	
 
    date = datetime.strptime(data['last_updated'], '%d-%m-%Y %H:%M:%S')
 
    now = datetime.utcnow()
 
    delta = now - date
 

	
 
    if delta.seconds >= 3600:
 
        status = 'Offline'
 
    elif delta.seconds >= 1200:
 
        status = 'Unknown'
 
    else:
 
        status = None
 

	
 
    if status is not None:
 
        current_app.logger.error("%s is set to %s" % (data['server_name'],
 
                                 status))
 
        for key in ('server_status', 'tor_status'):
 
            data[key] = status
 

	
 
    filename = os.path.join('data', data['server_name'].lower()+'.json')
 

	
 
    with open(filename, mode='w', encoding='utf-8') as file_object:
 
        json.dump(data, file_object)
 

	
 
    return data
 

	
 

	
 
def _load_single_server(filename):
0 comments (0 inline, 0 general)