Update_population now updates the db with new stats.
This commit is contained in:
parent
43058d4b19
commit
b3877c3518
@ -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
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user