Compare commits
13 commits
releases/0
...
release
Author | SHA1 | Date | |
---|---|---|---|
|
5cbf13aae9 | ||
240ada35f7 | |||
ff112cf8ed | |||
ca5d14e7f5 | |||
7f2882b1c8 | |||
43b8ec9b8d | |||
|
2fc64ad5a4 | ||
|
bf11d10889 | ||
|
02711463a3 | ||
|
b4b0137e3f | ||
|
727617342f | ||
|
1403c746f4 | ||
|
608d4bfe10 |
7 changed files with 215 additions and 3 deletions
12
.github/dependabot.yaml
vendored
Normal file
12
.github/dependabot.yaml
vendored
Normal file
|
@ -0,0 +1,12 @@
|
|||
version: 2
|
||||
updates:
|
||||
- package-ecosystem: "pip"
|
||||
directory: "/"
|
||||
target-branch: "develop"
|
||||
schedule:
|
||||
interval: "daily"
|
||||
- package-ecosystem: "github-actions"
|
||||
directory: "/"
|
||||
target-branch: "develop"
|
||||
schedule:
|
||||
interval: "daily"
|
21
.github/workflows/create-release.yaml
vendored
Normal file
21
.github/workflows/create-release.yaml
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
name: Create release on tag push
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- 'releases/*'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
name: Create draft release
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout source code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Draft release
|
||||
uses: ncipollo/release-action@v1
|
||||
with:
|
||||
bodyFile: "CHANGELOG.md"
|
||||
draft: true
|
18
CHANGELOG.md
18
CHANGELOG.md
|
@ -1,3 +1,21 @@
|
|||
# devel
|
||||
|
||||
## Fixed
|
||||
|
||||
* Looking up a CMDR with public profile, but hidden activity (= no date of last
|
||||
activity) will no longer throw an exception.
|
||||
|
||||
-----
|
||||
|
||||
# 0.2 (2022-07-02)
|
||||
|
||||
## Added
|
||||
|
||||
* `traffic` endpoint of the `System` API. You can use this to access the traffic
|
||||
report for a system.
|
||||
|
||||
-----
|
||||
|
||||
# 0.1 (2021-03-17)
|
||||
|
||||
Initial alpha release.
|
||||
|
|
|
@ -29,7 +29,7 @@ request.
|
|||
- [ ] shipyard
|
||||
- [ ] outfitting
|
||||
- [ ] factions
|
||||
- [ ] traffic
|
||||
- [x] traffic
|
||||
- [ ] deaths
|
||||
- [ ] Systems
|
||||
- [x] system
|
||||
|
|
|
@ -49,7 +49,11 @@ class Commander(Positionable):
|
|||
json = logsApi.Position.getSystem(self.name, self.apiKey)
|
||||
self.profileUrl = json
|
||||
if 'dateLastActivity' in json:
|
||||
return dateparser.parse(json['dateLastActivity'])
|
||||
date = json['dateLastActivity']
|
||||
if date is None:
|
||||
return None
|
||||
else:
|
||||
return dateparser.parse(json['dateLastActivity'])
|
||||
else:
|
||||
return None
|
||||
|
||||
|
@ -135,6 +139,7 @@ class System(Positionable):
|
|||
2h)
|
||||
:attribute primaryStar: information about the primary star (dict)
|
||||
:attribute bodyCount: amount of bodies in the system (int)
|
||||
:attribute traffic: information about traffic in the system (dict, cached for 2h)
|
||||
|
||||
:method fetch: updates all attributes in one go
|
||||
"""
|
||||
|
@ -147,6 +152,7 @@ class System(Positionable):
|
|||
self.__permitName = None
|
||||
self.__information = {'cachedAt': None}
|
||||
self.__primaryStar = None
|
||||
self.__traffic = {'cachedAt' : None}
|
||||
|
||||
@property
|
||||
def coords(self):
|
||||
|
@ -166,7 +172,7 @@ class System(Positionable):
|
|||
return self.__id64
|
||||
@property
|
||||
def ids(self):
|
||||
return {id:self.id, id64:self.id64}
|
||||
return {'id':self.id, 'id64':self.id64}
|
||||
def __updateIDs(self):
|
||||
ids = systemsApi.System.getIds(self.name)
|
||||
self.__id = ids['id']
|
||||
|
@ -212,6 +218,14 @@ class System(Positionable):
|
|||
"""
|
||||
return len(systemApi.Bodies.getBodies(self.name)['bodies'])
|
||||
|
||||
@property
|
||||
def traffic(self):
|
||||
if self.__traffic['cachedAt'] == None or (datetime.datetime.now()
|
||||
- self.__traffic['cachedAt'] > datetime.timedelta(hours=2)):
|
||||
self.__traffic = systemApi.Traffic.getTraffic(self.name)
|
||||
self.__traffic['cachedAt'] = datetime.datetime.now()
|
||||
return self.__traffic
|
||||
|
||||
def fetch(self):
|
||||
"""
|
||||
Fetches all information about the system from the API (again). Useful if you
|
||||
|
|
|
@ -41,3 +41,42 @@ class Bodies(base.ApiEndpoint):
|
|||
|
||||
json = cls.query({'systemId': str(systemId)})
|
||||
return json
|
||||
|
||||
class Traffic(base.ApiEndpoint):
|
||||
"""
|
||||
The "traffic" endpoint of the "system" API
|
||||
|
||||
:attribute url: the API endpoint URL
|
||||
"""
|
||||
|
||||
url = base.ApiEndpoint.url + "system-v1/traffic"
|
||||
|
||||
@classmethod
|
||||
def query(cls, params):
|
||||
try:
|
||||
json = super().query(params)
|
||||
except exception.NotFoundError:
|
||||
raise exception.SystemNotFoundError(params)
|
||||
return json
|
||||
|
||||
@classmethod
|
||||
def getTraffic(cls, systemName):
|
||||
"""
|
||||
Requests information about traffic in a system.
|
||||
|
||||
:param systemName: name of the system in question
|
||||
"""
|
||||
|
||||
json = cls.query({'systemName': systemName})
|
||||
return json
|
||||
|
||||
@classmethod
|
||||
def getTrafficById(cls, systemId):
|
||||
"""
|
||||
Requests information about traffic in a system.
|
||||
|
||||
:param systemName: ID of the system in question
|
||||
"""
|
||||
|
||||
json = cls.query({'systemId' : str(systemId)})
|
||||
return json
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import unittest
|
||||
from . import exception
|
||||
from .systemApi import Bodies
|
||||
from .systemApi import Traffic
|
||||
|
||||
class BodiesTest(unittest.TestCase):
|
||||
|
||||
|
@ -125,3 +126,110 @@ class BodiesTest(unittest.TestCase):
|
|||
# FIXXME: I remember finding a system with “[]” in the name, but can’t
|
||||
# remember … and the search function in the usual tools aren’t very helpful
|
||||
# :)
|
||||
|
||||
class TrafficTest(unittest.TestCase):
|
||||
def test_getTraffic_Sol(self):
|
||||
json = Traffic.getTraffic('Sol')
|
||||
|
||||
self.assertIs(type(json), dict)
|
||||
|
||||
# system data
|
||||
self.assertEqual(27, json['id'])
|
||||
self.assertEqual(10477373803, json['id64'])
|
||||
self.assertEqual('Sol', json['name'])
|
||||
self.assertEqual('https://www.edsm.net/en/system/id/27/name/Sol', json['url'])
|
||||
self.assertEqual('J. Calvert (Joshua)', json['discovery']['commander'])
|
||||
self.assertEqual('2014-11-18 18:21:43', json['discovery']['date'])
|
||||
|
||||
# format
|
||||
self.assertIn('breakdown', json)
|
||||
self.assertIs(type(json['breakdown']), dict)
|
||||
|
||||
self.assertIn('traffic', json)
|
||||
self.assertIn('total', json['traffic'])
|
||||
self.assertIn('week', json['traffic'])
|
||||
self.assertIn('day', json['traffic'])
|
||||
self.assertIs(type(json['traffic']), dict)
|
||||
self.assertIs(type(json['traffic']['total']), int)
|
||||
self.assertIs(type(json['traffic']['week']), int)
|
||||
self.assertIs(type(json['traffic']['day']), int)
|
||||
|
||||
def test_getTrafficById_Sol(self):
|
||||
json = Traffic.getTrafficById(27)
|
||||
|
||||
self.assertIs(type(json), dict)
|
||||
|
||||
# system data
|
||||
self.assertEqual(27, json['id'])
|
||||
self.assertEqual(10477373803, json['id64'])
|
||||
self.assertEqual('Sol', json['name'])
|
||||
self.assertEqual('https://www.edsm.net/en/system/id/27/name/Sol', json['url'])
|
||||
self.assertEqual('J. Calvert (Joshua)', json['discovery']['commander'])
|
||||
self.assertEqual('2014-11-18 18:21:43', json['discovery']['date'])
|
||||
|
||||
# format
|
||||
self.assertIn('breakdown', json)
|
||||
self.assertIs(type(json['breakdown']), dict)
|
||||
|
||||
self.assertIn('traffic', json)
|
||||
self.assertIn('total', json['traffic'])
|
||||
self.assertIn('week', json['traffic'])
|
||||
self.assertIn('day', json['traffic'])
|
||||
self.assertIs(type(json['traffic']), dict)
|
||||
self.assertIs(type(json['traffic']['total']), int)
|
||||
self.assertIs(type(json['traffic']['week']), int)
|
||||
self.assertIs(type(json['traffic']['day']), int)
|
||||
|
||||
def test_getTraffic_HD43193(self):
|
||||
json = Traffic.getTraffic('HD 43193')
|
||||
|
||||
self.assertIs(type(json), dict)
|
||||
|
||||
# system data
|
||||
self.assertEqual(85920, json['id'])
|
||||
self.assertEqual(167244341, json['id64'])
|
||||
self.assertEqual('HD 43193', json['name'])
|
||||
self.assertEqual('https://www.edsm.net/en/system/id/85920/name/HD+43193', json['url'])
|
||||
self.assertEqual('Virosh Lich', json['discovery']['commander'])
|
||||
self.assertEqual('2015-02-11 19:20:59', json['discovery']['date'])
|
||||
|
||||
# format
|
||||
self.assertIn('breakdown', json)
|
||||
self.assertIs(type(json['breakdown']), dict)
|
||||
|
||||
self.assertIn('traffic', json)
|
||||
self.assertIn('total', json['traffic'])
|
||||
self.assertIn('week', json['traffic'])
|
||||
self.assertIn('day', json['traffic'])
|
||||
self.assertIs(type(json['traffic']), dict)
|
||||
self.assertIs(type(json['traffic']['total']), int)
|
||||
self.assertIs(type(json['traffic']['week']), int)
|
||||
self.assertIs(type(json['traffic']['day']), int)
|
||||
|
||||
def test_getTrafficById_HD43193(self):
|
||||
json = Traffic.getTrafficById(85920)
|
||||
|
||||
self.assertIs(type(json), dict)
|
||||
|
||||
# system data
|
||||
self.assertEqual(85920, json['id'])
|
||||
self.assertEqual(167244341, json['id64'])
|
||||
self.assertEqual('HD 43193', json['name'])
|
||||
self.assertEqual('https://www.edsm.net/en/system/id/85920/name/HD+43193', json['url'])
|
||||
self.assertEqual('Virosh Lich', json['discovery']['commander'])
|
||||
self.assertEqual('2015-02-11 19:20:59', json['discovery']['date'])
|
||||
|
||||
# format
|
||||
self.assertIn('breakdown', json)
|
||||
self.assertIs(type(json['breakdown']), dict)
|
||||
|
||||
self.assertIn('traffic', json)
|
||||
self.assertIn('total', json['traffic'])
|
||||
self.assertIn('week', json['traffic'])
|
||||
self.assertIn('day', json['traffic'])
|
||||
self.assertIs(type(json['traffic']), dict)
|
||||
self.assertIs(type(json['traffic']['total']), int)
|
||||
self.assertIs(type(json['traffic']['week']), int)
|
||||
self.assertIs(type(json['traffic']['day']), int)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue