Update_population now updates the db with new stats.

This commit is contained in:
A. Svensson 2015-02-18 17:45:30 +01:00
parent 43058d4b19
commit b3877c3518

View File

@ -1,5 +1,9 @@
#!/usr/bin/env python #!/usr/bin/env python
from django.core.management.base import BaseCommand
from gameservers.models import Server, Population
import re import re
import logging import logging
@ -85,6 +89,26 @@ class ServerParser(object):
return server 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__': if __name__ == '__main__':
parser = ServerParser() parser = ServerParser()
parser.url = './dump.html' # Use a local file instead when testing parser.url = './dump.html' # Use a local file instead when testing