Compare commits

...

13 commits

Author SHA1 Message Date
dependabot[bot]
5cbf13aae9
Bump actions/checkout from 2 to 3
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>
2023-03-31 19:00:39 +00:00
240ada35f7
fixed exception when looking up a commander with hidden activity 2022-09-05 21:36:15 +02:00
ff112cf8ed 0.2 2022-07-02 15:55:23 +02:00
ca5d14e7f5 added github action for releases 2022-07-02 15:51:39 +02:00
7f2882b1c8 updated CHANGELOG/README 2022-07-02 15:36:05 +02:00
43b8ec9b8d dependabot 2022-06-01 09:09:37 +02:00
alterNERDtive
2fc64ad5a4
Merge pull request #5 from enderlein/traffic2 2022-03-12 04:07:11 +01:00
Kevin
bf11d10889 Put newline at end of file 2022-03-11 17:54:54 -05:00
Kevin
02711463a3 Add tests for 'getTraffic' and 'getTrafficById' 2022-03-02 15:05:55 -05:00
Kevin
b4b0137e3f - forgot to capitalize 'by' in 'getTrafficById' 2022-03-02 14:43:56 -05:00
Kevin
727617342f Fix bad dict (keys missing quotes) 2022-02-26 22:56:25 -05:00
Kevin
1403c746f4 Implement 'traffic' endpoint of 'System' API 2022-02-26 22:53:30 -05:00
Kevin
608d4bfe10 Add traffic endpoint for System API 2022-02-26 19:45:07 -05:00
7 changed files with 215 additions and 3 deletions

12
.github/dependabot.yaml vendored Normal file
View 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
View 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

View file

@ -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) # 0.1 (2021-03-17)
Initial alpha release. Initial alpha release.

View file

@ -29,7 +29,7 @@ request.
- [ ] shipyard - [ ] shipyard
- [ ] outfitting - [ ] outfitting
- [ ] factions - [ ] factions
- [ ] traffic - [x] traffic
- [ ] deaths - [ ] deaths
- [ ] Systems - [ ] Systems
- [x] system - [x] system

View file

@ -49,7 +49,11 @@ class Commander(Positionable):
json = logsApi.Position.getSystem(self.name, self.apiKey) json = logsApi.Position.getSystem(self.name, self.apiKey)
self.profileUrl = json self.profileUrl = json
if 'dateLastActivity' in 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: else:
return None return None
@ -135,6 +139,7 @@ class System(Positionable):
2h) 2h)
:attribute primaryStar: information about the primary star (dict) :attribute primaryStar: information about the primary star (dict)
:attribute bodyCount: amount of bodies in the system (int) :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 :method fetch: updates all attributes in one go
""" """
@ -147,6 +152,7 @@ class System(Positionable):
self.__permitName = None self.__permitName = None
self.__information = {'cachedAt': None} self.__information = {'cachedAt': None}
self.__primaryStar = None self.__primaryStar = None
self.__traffic = {'cachedAt' : None}
@property @property
def coords(self): def coords(self):
@ -166,7 +172,7 @@ class System(Positionable):
return self.__id64 return self.__id64
@property @property
def ids(self): def ids(self):
return {id:self.id, id64:self.id64} return {'id':self.id, 'id64':self.id64}
def __updateIDs(self): def __updateIDs(self):
ids = systemsApi.System.getIds(self.name) ids = systemsApi.System.getIds(self.name)
self.__id = ids['id'] self.__id = ids['id']
@ -212,6 +218,14 @@ class System(Positionable):
""" """
return len(systemApi.Bodies.getBodies(self.name)['bodies']) 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): def fetch(self):
""" """
Fetches all information about the system from the API (again). Useful if you Fetches all information about the system from the API (again). Useful if you

View file

@ -41,3 +41,42 @@ class Bodies(base.ApiEndpoint):
json = cls.query({'systemId': str(systemId)}) json = cls.query({'systemId': str(systemId)})
return json 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

View file

@ -1,6 +1,7 @@
import unittest import unittest
from . import exception from . import exception
from .systemApi import Bodies from .systemApi import Bodies
from .systemApi import Traffic
class BodiesTest(unittest.TestCase): class BodiesTest(unittest.TestCase):
@ -125,3 +126,110 @@ class BodiesTest(unittest.TestCase):
# FIXXME: I remember finding a system with “[]” in the name, but cant # FIXXME: I remember finding a system with “[]” in the name, but cant
# remember … and the search function in the usual tools arent very helpful # remember … and the search function in the usual tools arent 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)