Last active
December 6, 2018 19:57
-
-
Save naoki-mizuno/e2c8f4f4588dc4f78ea1806031cc9dfe to your computer and use it in GitHub Desktop.
Script to output download link for MGEX data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import argparse | |
import datetime | |
import dateutil.parser | |
def parse_opts(): | |
parser = argparse.ArgumentParser(add_help=False) | |
group = parser.add_mutually_exclusive_group(required=True) | |
group.add_argument('-h', '--hourly', | |
help='Retrieve hourly data', | |
action='store_true', | |
dest='hourly') | |
group.add_argument('-d', '--daily', | |
help='Retrieve daily data', | |
action='store_true', | |
dest='daily') | |
parser.add_argument('-g', '--glonass', | |
action='store_true', | |
dest='is_glonass') | |
parser.add_argument('--help', | |
help='show this help message and exit', | |
action='help') | |
parser.add_argument('time', | |
help='the date/time to get the URL for') | |
return parser | |
def hourly(timestamp_str): | |
timestamp = dateutil.parser.parse(timestamp_str) | |
fmt = '%Y/%j/hour/%jm.%yn.Z' | |
return timestamp.strftime(fmt) | |
def daily(timestamp_str, is_glonass=False): | |
if is_glonass: | |
# For GLONASS | |
suffix = 'g' | |
else: | |
# For GPS | |
suffix = 'n' | |
timestamp = dateutil.parser.parse(timestamp_str) | |
fmt = '%Y/%j/%y{0}/brdc%j0.%y{0}.Z'.format(suffix) | |
return timestamp.strftime(fmt) | |
def main(): | |
parser = parse_opts() | |
args = parser.parse_args() | |
if args.daily: | |
url_prefix = 'ftp://cddis.nasa.gov/gnss/data/daily/' | |
url = daily(args.time, args.is_glonass) | |
else: | |
url_prefix = 'ftp://cddis.nasa.gov/gnss/data/hourly/' | |
url = hourly(args.time) | |
print(url_prefix + url) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment