Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Stuart Mumford <stuart@cadair.com>
  • Loading branch information
Shane Maloney and Cadair committed Feb 17, 2021
1 parent 47f0255 commit 381a120
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
4 changes: 2 additions & 2 deletions sunpy/net/dataretriever/sources/noaa.py
Expand Up @@ -196,8 +196,8 @@ def _get_url_for_timerange(self, timerange):
# cover a year, and look for individual srs file for this time range.
srs_urls = dict()
min_file_year = max_tarball_year if max_tarball_year else start_year
min_file_date = datetime(max_tarball_year, 12, 31, 23, 59, 59) if max_tarball_year else \
datetime(start_year, 1, 1, 0, 0, 0)
min_file_date = (datetime(max_tarball_year, 12, 31, 23, 59, 59) if max_tarball_year else
datetime(start_year, 1, 1, 0, 0, 0))
max_file_date = min(timerange.end.datetime, Time.now().datetime)
if min_file_date < max_file_date:
file_timerange = TimeRange(f'{min_file_year}-01-01', max_file_date)
Expand Down
2 changes: 1 addition & 1 deletion sunpy/net/dataretriever/sources/tests/test_noaa.py
Expand Up @@ -183,7 +183,7 @@ def test_srs_tar_unpack_midyear():
@mock.patch('ftplib.FTP.nlst', side_effect=[[''], ['20200101SRS.txt', '20200102SRS.txt']])
def test_srs_missing_tarball(mock_ftp_nlst):
qr = Fido.search(a.Time('2020-01-01', '2020-01-02'), a.Instrument.srs_table)
urls = [qrblock['Url'] for qrblock in qr[0]]
urls = [qrblock['url'] for qrblock in qr[0]]
assert urls[0].endswith('20200101SRS.txt')
assert urls[1].endswith('20200102SRS.txt')

Expand Down
22 changes: 9 additions & 13 deletions sunpy/util/scraper.py
Expand Up @@ -152,24 +152,20 @@ def _date_floor(date, timestep):
date_parts[-1] = date_parts[-1] % 60
date = datetime(*date_parts)
orig_time_tup = date.timetuple()
if timestep == relativedelta(seconds=1):
new_time_tup = (orig_time_tup.tm_year, orig_time_tup.tm_mon, orig_time_tup.tm_mday,
orig_time_tup.tm_hour, orig_time_tup.tm_min, orig_time_tup.tm_sec)
elif timestep == relativedelta(minutes=1):
new_time_tup = (orig_time_tup.tm_year, orig_time_tup.tm_mon, orig_time_tup.tm_mday,
orig_time_tup.tm_hour, orig_time_tup.tm_min, 0)
time_tup = [orig_time_tup.tm_year, orig_time_tup.tm_mon, orig_time_tup.tm_mday,
orig_time_tup.tm_hour, orig_time_tup.tm_min, orig_time_tup.tm_sec]
if timestep == relativedelta(minutes=1):
time_tup[-1] = 0
elif timestep == relativedelta(hours=1):
new_time_tup = (orig_time_tup.tm_year, orig_time_tup.tm_mon, orig_time_tup.tm_mday,
orig_time_tup.tm_hour, 0, 0)
time_tup[-2:] = [0, 0]
elif timestep == relativedelta(days=1):
new_time_tup = (orig_time_tup.tm_year, orig_time_tup.tm_mon, orig_time_tup.tm_mday,
0, 0, 0)
time_tup[-3:] = [0, 0, 0]
elif timestep == relativedelta(months=1):
new_time_tup = (orig_time_tup.tm_year, orig_time_tup.tm_mon, 1, 0, 0, 0)
time_tup[-4:] = [1, 0, 0, 0]
elif timestep == relativedelta(years=1):
new_time_tup = (orig_time_tup.tm_year, 1, 1, 0, 0, 0)
time_tup[-5:] = [1, 1, 0, 0, 0]

return datetime(*new_time_tup)
return datetime(*time_tup)

def _URL_followsPattern(self, url):
"""
Expand Down

0 comments on commit 381a120

Please sign in to comment.