# Path: credits.py
# def fileVersion(program=None, year=False):
#     ver = '?'
#     ver_yr = '????'
#     if program == None:
#         check = sys.argv[0]
#     else:
#         s = program.rfind('.')
#         if s > 0 and program[s:] == '.html':
#             check = program
#         elif s < len(program) - 4:
#             check = program + sys.argv[0][sys.argv[0].rfind('.'):]
#         else:
#             check = program
#     if check[-3:] == '.py':
#         try:
#             modtime = datetime.fromtimestamp(os.path.getmtime(check))
#             ver = '3.0.%04d.%d%02d' % (modtime.year, modtime.month, modtime.day)
#             ver_yr = '%04d' % modtime.year
#         except:
#             pass
#     elif check[-5:] == '.html':
#         try:
#             modtime = datetime.fromtimestamp(os.path.getmtime(check))
#             ver = '3.0.%04d.%d%02d' % (modtime.year, modtime.month, modtime.day)
#             ver_yr = '%04d' % modtime.year
#         except:
#             pass
#     else:
#         if sys.platform == 'win32' or sys.platform == 'cygwin':
#             try:
#                 if check.find('\\') >= 0:  # if full path
#                     info = GetFileVersionInfo(check, '\\')
#                 else:
#                     info = GetFileVersionInfo(os.getcwd() + '\\' + check, '\\')
#                 ms = info['ProductVersionMS']
#               #  ls = info['FileVersionLS']
#                 ls = info['ProductVersionLS']
#                 ver = str(HIWORD(ms)) + '.' + str(LOWORD(ms)) + '.' + str(HIWORD(ls)) + '.' + str(LOWORD(ls))
#                 ver_yr = str(HIWORD(ls))
#             except:
#                 try:
#                     info = os.path.getmtime(os.getcwd() + '\\' + check)
#                     ver = '3.0.' + datetime.fromtimestamp(info).strftime('%Y.%m%d')
#                     ver_yr = datetime.fromtimestamp(info).strftime('%Y')
#                     if ver[9] == '0':
#                         ver = ver[:9] + ver[10:]
#                 except:
#                     pass
#     if year:
#         return ver_yr
#     else:
#         return ver


from urllib3 import PoolManager
from PyQt5 import QtCore, QtGui, QtWidgets
from credits import fileVersion
import math
import os
import sys
import tempfile
import configparser   # decode .ini file
import displayobject
import worldwindow
        url = self.url
        if len(self.subs) > 0:
            self.sub_ctr += 1
            if self.sub_ctr >= len(self.subs):
                self.sub_ctr = 0
            url = url.replace('[]', self.subs[self.sub_ctr])
        file_name = str(x) + '_' + str(y) + '.png'
        url_tail = self.url_tail.replace('/zoom', '/' + str(zoom))
        url_tail = url_tail.replace('/x', '/' + str(x))
        url_tail = url_tail.replace('/y', '/' + str(y))
        if 1 == 2: # Google?
            url_tail = self.url_tail.replace('z=zoom', 'z=' + str(zoom))
            url_tail = url_tail.replace('x=x', 'x=' + str(x))
            url_tail = url_tail.replace('y=y', 'y=' + str(y))
        if self.batch:
            print(url + url_tail)
        user_agent = {'User-agent': 'getmap ' + fileVersion() + ' contact siren@sen.asn.au'}
        http = PoolManager(headers=user_agent)
        if self.batch:
            print('Retrieving ' + url_tail)
        response = http.request('GET', url + url_tail)
        if response.status == 200 and response.reason == 'OK':
            if self.batch:
                print(url_tail + ' retrieved')
            f = open(self.tmp_location + file_name, 'wb')
            f.write(response.data)
            f.close()
            message = 'OK'
        else:
            message = url_tail + ' failed\n' + str(response.status) + ' ' + response.reason

# Path: credits.py
# def fileVersion(program=None, year=False):
#     ver = '?'
#     ver_yr = '????'
#     if program == None:
#         check = sys.argv[0]
#     else:
#         s = program.rfind('.')
#         if s > 0 and program[s:] == '.html':
#             check = program
#         elif s < len(program) - 4:
#             check = program + sys.argv[0][sys.argv[0].rfind('.'):]
#         else:
#             check = program
#     if check[-3:] == '.py':
#         try:
#             modtime = datetime.fromtimestamp(os.path.getmtime(check))
#             ver = '3.0.%04d.%d%02d' % (modtime.year, modtime.month, modtime.day)
#             ver_yr = '%04d' % modtime.year
#         except:
#             pass
#     elif check[-5:] == '.html':
#         try:
#             modtime = datetime.fromtimestamp(os.path.getmtime(check))
#             ver = '3.0.%04d.%d%02d' % (modtime.year, modtime.month, modtime.day)
#             ver_yr = '%04d' % modtime.year
#         except:
#             pass
#     else:
#         if sys.platform == 'win32' or sys.platform == 'cygwin':
#             try:
#                 if check.find('\\') >= 0:  # if full path
#                     info = GetFileVersionInfo(check, '\\')
#                 else:
#                     info = GetFileVersionInfo(os.getcwd() + '\\' + check, '\\')
#                 ms = info['ProductVersionMS']
#               #  ls = info['FileVersionLS']
#                 ls = info['ProductVersionLS']
#                 ver = str(HIWORD(ms)) + '.' + str(LOWORD(ms)) + '.' + str(HIWORD(ls)) + '.' + str(LOWORD(ls))
#                 ver_yr = str(HIWORD(ls))
#             except:
#                 try:
#                     info = os.path.getmtime(os.getcwd() + '\\' + check)
#                     ver = '3.0.' + datetime.fromtimestamp(info).strftime('%Y.%m%d')
#                     ver_yr = datetime.fromtimestamp(info).strftime('%Y')
#                     if ver[9] == '0':
#                         ver = ver[:9] + ver[10:]
#                 except:
#                     pass
#     if year:
#         return ver_yr
#     else:
#         return ver


# Path: getmap.py
from urllib3 import PoolManager
from PyQt5 import QtCore, QtGui, QtWidgets
from credits import fileVersion
import math
import os
import sys
import tempfile
import configparser   # decode .ini file
import displayobject
import worldwindow

        url = self.url
        if len(self.subs) > 0:
            self.sub_ctr += 1
            if self.sub_ctr >= len(self.subs):
                self.sub_ctr = 0
            url = url.replace('[]', self.subs[self.sub_ctr])
        file_name = str(x) + '_' + str(y) + '.png'
        url_tail = self.url_tail.replace('/zoom', '/' + str(zoom))
        url_tail = url_tail.replace('/x', '/' + str(x))
        url_tail = url_tail.replace('/y', '/' + str(y))
        if 1 == 2: # Google?
            url_tail = self.url_tail.replace('z=zoom', 'z=' + str(zoom))
            url_tail = url_tail.replace('x=x', 'x=' + str(x))
            url_tail = url_tail.replace('y=y', 'y=' + str(y))
        if self.batch:
            print(url + url_tail)
        user_agent = {'User-agent': 'getmap ' + fileVersion() + ' contact siren@sen.asn.au'}
        http = PoolManager(headers=user_agent)
        if self.batch:
            print('Retrieving ' + url_tail)
        response = http.request('GET', url + url_tail)
        if response.status == 200 and response.reason == 'OK':
            if self.batch:
                print(url_tail + ' retrieved')
            f = open(self.tmp_location + file_name, 'wb')
            f.write(response.data)
            f.close()
            message = 'OK'
        else:
            message = url_tail + ' failed\n' + str(response.status) + ' ' + response.reason

        return message, file_name