update_population uses the new model too.
--HG-- branch : history_model
This commit is contained in:
parent
65d1b043bf
commit
a532543121
@ -1,12 +1,10 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import time
|
|
||||||
|
|
||||||
from django.core.management.base import BaseCommand
|
from django.core.management.base import BaseCommand
|
||||||
from django.utils import timezone
|
|
||||||
|
|
||||||
from gameservers.models import Server, PlayerHistory
|
from gameservers.models import Server, ServerHistory
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
@ -94,9 +92,8 @@ class Command(BaseCommand):
|
|||||||
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
|
||||||
servers = parser.run()
|
servers = parser.run()
|
||||||
history = PlayerHistory()
|
|
||||||
now = time.mktime(timezone.now().timetuple())
|
|
||||||
servers_handled = []
|
servers_handled = []
|
||||||
|
new_items = []
|
||||||
|
|
||||||
for data in servers:
|
for data in servers:
|
||||||
# Prevent empty servers with identical names to other, active servers
|
# Prevent empty servers with identical names to other, active servers
|
||||||
@ -106,10 +103,6 @@ class Command(BaseCommand):
|
|||||||
else:
|
else:
|
||||||
servers_handled.append(data['title'])
|
servers_handled.append(data['title'])
|
||||||
|
|
||||||
# Keep the amount of data down in redis
|
|
||||||
history.trim_points(data['title'])
|
|
||||||
|
|
||||||
# TODO: do bulk insert instead!
|
|
||||||
server, created = Server.objects.update_or_create(
|
server, created = Server.objects.update_or_create(
|
||||||
title=data['title'],
|
title=data['title'],
|
||||||
defaults= dict(
|
defaults= dict(
|
||||||
@ -119,8 +112,9 @@ class Command(BaseCommand):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
# Update the player history
|
history = ServerHistory(server=server, players=data['player_count'])
|
||||||
history.add_point(server, now, data['player_count'])
|
new_items.append(history)
|
||||||
|
|
||||||
|
ServerHistory.objects.bulk_create(new_items)
|
||||||
Server.remove_old_servers()
|
Server.remove_old_servers()
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user