Removed some old crap.
This commit is contained in:
parent
24ace58e88
commit
023916152a
@ -1,7 +1,6 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import logging
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
@ -16,9 +15,6 @@ URL = 'http://www.byond.com/games/exadv1/spacestation13'
|
|||||||
PLAYER_COUNT = re.compile('Logged in: (\d+) player')
|
PLAYER_COUNT = re.compile('Logged in: (\d+) player')
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
|
||||||
|
|
||||||
|
|
||||||
class ServerParser(object):
|
class ServerParser(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.url = URL
|
self.url = URL
|
||||||
@ -31,20 +27,17 @@ class ServerParser(object):
|
|||||||
|
|
||||||
def _download_data(self):
|
def _download_data(self):
|
||||||
'''Download raw data, either from local file or a web page.'''
|
'''Download raw data, either from local file or a web page.'''
|
||||||
logging.info('Downloading data from {} ...'.format(self.url))
|
|
||||||
if self.url.startswith('http://') or self.url.startswith('https://'):
|
if self.url.startswith('http://') or self.url.startswith('https://'):
|
||||||
raw_data = requests.get(self.url).text.strip()
|
raw_data = requests.get(self.url).text.strip()
|
||||||
else:
|
else:
|
||||||
# HACK: In case of local testing or debugging, since requests can't
|
# HACK: In case of local testing or debugging, since requests can't
|
||||||
# handle local files.
|
# handle local files.
|
||||||
logging.debug('Opening local file...')
|
|
||||||
with open(self.url, 'r') as f:
|
with open(self.url, 'r') as f:
|
||||||
raw_data = f.read().strip()
|
raw_data = f.read().strip()
|
||||||
return raw_data
|
return raw_data
|
||||||
|
|
||||||
def _parse_data(self, raw_data):
|
def _parse_data(self, raw_data):
|
||||||
'''Parse the raw data and run through all servers.'''
|
'''Parse the raw data and run through all servers.'''
|
||||||
logging.info('Parsing raw data...')
|
|
||||||
servers = []
|
servers = []
|
||||||
soup_data = BeautifulSoup(raw_data)
|
soup_data = BeautifulSoup(raw_data)
|
||||||
for server_data in soup_data.find_all('div', 'live_game_status'):
|
for server_data in soup_data.find_all('div', 'live_game_status'):
|
||||||
@ -52,7 +45,6 @@ class ServerParser(object):
|
|||||||
if server:
|
if server:
|
||||||
servers.append(server)
|
servers.append(server)
|
||||||
|
|
||||||
logging.info('Number of servers parsed: {}'.format(len(servers)))
|
|
||||||
return servers
|
return servers
|
||||||
|
|
||||||
def _parse_server_data(self, data):
|
def _parse_server_data(self, data):
|
||||||
@ -98,6 +90,7 @@ class Command(BaseCommand):
|
|||||||
|
|
||||||
def handle(self, *args, **kwargs):
|
def handle(self, *args, **kwargs):
|
||||||
parser = ServerParser()
|
parser = ServerParser()
|
||||||
|
#parser.url = './dump.html' # Use a local file instead when testing
|
||||||
servers = parser.run()
|
servers = parser.run()
|
||||||
history = PlayerHistory()
|
history = PlayerHistory()
|
||||||
now = time.time()
|
now = time.time()
|
||||||
@ -125,11 +118,3 @@ class Command(BaseCommand):
|
|||||||
history.add_point(server, now, data['player_count'])
|
history.add_point(server, now, data['player_count'])
|
||||||
history.trim_points(server)
|
history.trim_points(server)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
parser = ServerParser()
|
|
||||||
parser.url = './dump.html' # Use a local file instead when testing
|
|
||||||
servers = parser.run()
|
|
||||||
for tmp in servers:
|
|
||||||
print '{}\nPlayers: {}\n'.format(tmp['title'], tmp['player_count'])
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user