Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi tle support #60

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions orbit_predictor/sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,20 @@ class EtcTLESource(TLESource):
def __init__(self, filename="/etc/latest_tle"):
self.filename = filename

def add_tle(self, sate_id, tle, epoch):
with open(self.filename, "w") as fd:
def add_tle(self, sate_id, tle, epoch, append=False):
with open(self.filename, "a+" if append else 'w') as fd:
fd.write(sate_id + "\n")
for l in tle:
fd.write(l + "\n")

def _get_tle(self, sate_id, date):
with open(self.filename) as fd:
data = fd.read()
lines = data.split("\n")
if not lines[0] == sate_id:
raise LookupError("Stored satellite id not found")
return tuple(lines[1:3])
data = fd.read().split("\n")
tle_lines = [data[i:i+3] for i in range(0, len(data), 3)]
for tle in tle_lines:
if tle[0] == sate_id:
return tuple(tle[1:])
raise LookupError("Stored satellite id not found")


class WSTLESource(TLESource):
Expand Down
13 changes: 13 additions & 0 deletions tests/test_sources.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,19 @@ def tearDown(self):
shutil.rmtree(self.dirname)


class TestEtcTLESourceMultiple(TestEtcTLESource):
def test_add_tle(self):
db = sources.EtcTLESource(self.filename)
sate_id_2 = SATE_ID + 'I'
db.add_tle(sate_id_2, SAMPLE_TLE2, dt.datetime.utcnow(), append=True)

tle_sat_1 = db._get_tle(SATE_ID, dt.datetime.utcnow())
self.assertEqual(tle_sat_1, SAMPLE_TLE)

tle_sat_2 = db._get_tle(sate_id_2, dt.datetime.utcnow())
self.assertEqual(tle_sat_2, SAMPLE_TLE2)


class TestWSTLESource(unittest.TestCase):
def setUp(self):
self.mock_json = {
Expand Down