Skip to content

Commit

Permalink
Script now checks if browser is text-based #3
Browse files Browse the repository at this point in the history
  • Loading branch information
luka1199 committed Nov 23, 2019
1 parent 30aa551 commit 2185d6f
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions geo_heatmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
from progressbar import ProgressBar, Bar, ETA, Percentage


TEXT_BASED_BROWSERS = [webbrowser.GenericBrowser, webbrowser.Elinks]

class Generator:
def __init__(self):
self.coordinates = collections.defaultdict(int)
Expand Down Expand Up @@ -75,6 +77,21 @@ def run(self, data_file, output_file):
m = self.generateMap()
print("Saving map to {}...".format(output_file))
m.save(output_file)


def isTextBasedBrowser(browser):
"""Returns if browser is a text-based browser
Arguments:
browser {webbrowser.BaseBrowser} -- A browser
Returns:
bool -- True if browser is text-based, False if browser is not text-based
"""
for tb_browser in TEXT_BASED_BROWSERS:
if type(browser) is tb_browser:
return True
return False


if __name__ == "__main__":
Expand All @@ -83,8 +100,10 @@ def run(self, data_file, output_file):
output_file = "heatmap.html"
generator = Generator()
generator.run(data_file, output_file)
print("Opening {} in browser...".format(output_file))
webbrowser.open('file://' + os.path.realpath(output_file))
# Check if browser is text-based
if not isTextBasedBrowser(webbrowser.get()):
print("Opening {} in browser...".format(output_file))
webbrowser.open('file://' + os.path.realpath(output_file))
else:
print("Usage: python geo_heatmap.py <file>")
sys.exit()
Expand Down

0 comments on commit 2185d6f

Please sign in to comment.