-
Notifications
You must be signed in to change notification settings - Fork 0
/
gethourlyephemeris.py
35 lines (32 loc) · 1.08 KB
/
gethourlyephemeris.py
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
import os
import time
import urllib.request
import ftplib
#Gets the day of year
DOY = time.localtime().tm_yday
###Generate URL
#print ("Generating current hourly URL..." + '\n')
basefileurl = "ftp://cddis.gsfc.nasa.gov/gnss/data/hourly/"
fourdyear = time.localtime().tm_year
twodyear = str(fourdyear)[-2:]
pathfileurl = basefileurl + str(fourdyear) + "/" + str(DOY) + "/"
ephemerisfilename = "hour" + str(DOY) + "0." + str(twodyear) + "n.Z"
fullurl = pathfileurl + ephemerisfilename
#Sets up parsed URL if needed
parsedurl = urllib.parse.urlparse(fullurl)
#print ("URL Generated " + fullurl + '\n')
###Download File from URL
try:
print ("Connecting to FTP " + parsedurl.netloc)
ftp = ftplib.FTP(parsedurl.netloc)
print ("FTP Login...")
ftp.login()
print ("FTP Changing directory...")
ftp.cwd(os.path.dirname(parsedurl.path)[1:])
ftp.dir()
print ("Downloading hourly ephemeris data to " + ephemerisfilename)
ftp.retrbinary('RETR %s' % ephemerisfilename, open(ephemerisfilename, 'wb').write)
print ("Disconnecting from " + parsedurl.netloc)
ftp.quit()
except ftplib.all_errors as err:
print (err)