Skip to content

add get all platforms function and generator getting one platform to processing #84

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ nosetests.xml

# rope
.ropeproject
/.vs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/.vs
.vs

I don't think the / is needed.

39 changes: 39 additions & 0 deletions pyorbital/tlefile.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,44 @@ def read(platform, tle_file=None, line1=None, line2=None):
return Tle(platform, tle_file=tle_file, line1=line1, line2=line2)


def get_all_platforms(tle_file=None):
"""Read all *platform* name from tle file
tle_file - list path files
"""
platforms = list()
fid = io.open(tle_file, 'rb')
for line in fid:
line = line.decode('utf-8')
line = line.strip()
if not line.startswith('1') and not line.startswith('2') and len(line) > 0:
platforms.append(line)
l_1 = next(fid).decode('utf-8')
l_2 = next(fid).decode('utf-8')
fid.close()

return platforms


def get_platform(tle_file=None):
"""Read *platform* name from tle file
tle_file - path to tle file
"""
try:
fid = io.open(tle_file, 'rb')
for line in fid:
line = line.decode('utf-8')
line = line.strip()
if not line.startswith('1') and not line.startswith('2') and len(line) > 0:
yield line
l_1 = next(fid).decode('utf-8')
l_2 = next(fid).decode('utf-8')
except IOError:
LOGGER.error("TLE file %s not found.", tle_file)
finally:
if fid:
fid.close()


def fetch(destination):
"""Fetch TLE from internet and save it to `destination`."""
with io.open(destination, mode="w", encoding="utf-8") as dest:
Expand Down Expand Up @@ -213,6 +251,7 @@ def _open(filename):
for l_0 in fid:
l_0 = l_0.decode('utf-8')
if l_0.strip() == self._platform:
if l_0.strip().upper() == self._platform:
l_1 = next(fid).decode('utf-8')
l_2 = next(fid).decode('utf-8')
tle = l_1.strip() + "\n" + l_2.strip()
Expand Down