-
Notifications
You must be signed in to change notification settings - Fork 0
/
ark.py
46 lines (38 loc) · 1.47 KB
/
ark.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import logging
import requests
import data
from log import getLogger
from player import Player
class Ark():
def __init__(self, name):
self.name = name
self._server_uri = None
self._api_uri = None
def __str__(self):
return '(Ark: {})'.format(self.name)
@property
def data_path(self):
return '/arks/{}'.format(self.name)
@property
def api_uri(self):
if not self._api_uri:
logger = getLogger('tribe-scraper.ark')
logger.debug('First time: Getting {} api_uri_format from firebase'.format(self))
api_uri_format = data.get_firebase_value('/configuration/api-uri-format')
self._api_uri = api_uri_format.format(self.server_uri)
return self._api_uri
@property
def server_uri(self):
if not self._server_uri:
logger = getLogger('tribe-scraper.ark')
logger.debug('First time: Getting {} server_uri from firebase'.format(self))
self._server_uri = data.get_firebase_value(self.data_path + '/connect_uri')
return self._server_uri
def get_active_players(self):
logger = getLogger('tribe-scraper.ark')
logger.info('Getting player list from {}'.format(self.api_uri))
response = requests.get(self.api_uri)
response.raise_for_status()
players = [Player(**p) for p in response.json()['players']]
logger.info('{}: {} player(s)'.format(response, len(players)))
return players