From b3877c3518e5cbe8b47e37cadbecc3397ee0773e Mon Sep 17 00:00:00 2001 From: "A. Svensson" Date: Wed, 18 Feb 2015 17:45:30 +0100 Subject: [PATCH] Update_population now updates the db with new stats. --- .../management/commands/update_population.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/gameservers/management/commands/update_population.py b/src/gameservers/management/commands/update_population.py index 9587dc4..2f5404e 100755 --- a/src/gameservers/management/commands/update_population.py +++ b/src/gameservers/management/commands/update_population.py @@ -1,5 +1,9 @@ #!/usr/bin/env python +from django.core.management.base import BaseCommand + +from gameservers.models import Server, Population + import re import logging @@ -85,6 +89,26 @@ class ServerParser(object): return server +class Command(BaseCommand): + help = 'Update population stats for all ss13 servers.' + + def handle(self, *args, **kwargs): + parser = ServerParser() + parser.url = './dump.html' # Use a local file instead when testing + servers = parser.run() + + for data in servers: + server, created = Server.objects.get_or_create( + title=data['title'], + game_url=data['game_url'], + site_url=data['site_url'] or '', + ) + pop = Population.objects.create( + server=server, + players=data['player_count'], + ) + + if __name__ == '__main__': parser = ServerParser() parser.url = './dump.html' # Use a local file instead when testing