Skip to content

Commit

Permalink
Fix http to https support
Browse files Browse the repository at this point in the history
  • Loading branch information
kannkyo committed Sep 5, 2020
1 parent 631b3a9 commit 9d37a2c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions himawaripy/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from .utils import set_background, get_desktop_environment

import ssl

# Semantic Versioning: Major, Minor, Patch
HIMAWARIPY_VERSION = (2, 1, 0)
Expand Down Expand Up @@ -55,7 +56,7 @@ def download_chunk(args):
global counter

x, y, latest, level = args
url_format = "http://himawari8.nict.go.jp/img/D531106/{}d/{}/{}_{}_{}.png"
url_format = "https://himawari8.nict.go.jp/img/D531106/{}d/{}/{}_{}_{}.png"
url = url_format.format(level, WIDTH, strftime("%Y/%m/%d/%H%M%S", latest), x, y)

tiledata = download(url)
Expand All @@ -75,7 +76,7 @@ def download_chunk(args):

def parse_args():
parser = argparse.ArgumentParser(description="set (near-realtime) picture of Earth as your desktop background",
epilog="http://labs.boramalper.org/himawaripy")
epilog="https://labs.boramalper.org/himawaripy")

parser.add_argument("--version", action="version", version="%(prog)s {}.{}.{}".format(*HIMAWARIPY_VERSION))

Expand Down Expand Up @@ -130,7 +131,7 @@ def download(url):

for i in range(1, 4): # retry max 3 times
try:
with urllib.request.urlopen(url) as response:
with urllib.request.urlopen(url, context=ssl.SSLContext(ssl.PROTOCOL_TLS)) as response:
return response.read()
except Exception as e:
exception = e
Expand All @@ -151,7 +152,7 @@ def thread_main(args):
level = args.level # since we are going to use it a lot of times

print("Updating...")
latest_json = download("http://himawari8-dl.nict.go.jp/himawari8/img/D531106/latest.json")
latest_json = download("https://himawari8-dl.nict.go.jp/himawari8/img/D531106/latest.json")
latest = strptime(json.loads(latest_json.decode("utf-8"))["date"], "%Y-%m-%d %H:%M:%S")

print("Latest version: {} GMT.".format(strftime("%Y/%m/%d %H:%M:%S", latest)))
Expand Down

0 comments on commit 9d37a2c

Please sign in to comment.