File: add-amsat.py

package info (click to toggle)
gpredict 2.3-115-g0f3beb6-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 12,252 kB
  • sloc: ansic: 40,123; makefile: 479; python: 143; sh: 85
file content (45 lines) | stat: -rwxr-xr-x 1,178 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/python
#
# Add satellites from AMSAT website that were not in the Celestrak database
# 
import os
import string
import urllib


webfile = 'https://www.amsat.org/amsat/ftp/keps/current/nasabare.txt'
localfile = './in/amsat.txt'
print 'Fetching ' + webfile + ' => ' + localfile
urllib.urlretrieve (webfile, localfile)

tlefile = open(localfile, 'r')
catfile = open('./out/amateur.cat', 'a')
datfile = open('./out/satellites.dat', 'a')

while 1:
    # read three lines at a time; strip trailing whitespaces
    line1 = tlefile.readline().strip()
    if not line1: break
    line2 = tlefile.readline().strip()
    line3 = tlefile.readline().strip()

    # catalog number; strip leading zeroes
    catnum = line2[2:7].lstrip('0')

    satfilename = './tmp/' + catnum + '.sat'
    if os.path.isfile(satfilename): continue

    print " Adding " + catnum + " ..."

    catfile.write(catnum+'\n')

    datfile.write("\n["+catnum+"]\n")
    datfile.write('VERSION=1.1\n')
    datfile.write('NAME='+line1+'\n')
    datfile.write('NICKNAME='+line1+'\n')
    datfile.write('TLE1='+line2+'\n')
    datfile.write('TLE2='+line3+'\n')

tlefile.close()
catfile.close()
datfile.close()