headless support
This commit is contained in:
parent
4de951428f
commit
5a0503fd01
@ -19,6 +19,7 @@ optional arguments:
|
|||||||
Filename of map. None will not save. (default: Map_YYYYMMDD-HHMMSS)
|
Filename of map. None will not save. (default: Map_YYYYMMDD-HHMMSS)
|
||||||
-j [], --json [] Filename of json file to use.
|
-j [], --json [] Filename of json file to use.
|
||||||
(choices: {List of .json files in current dir})
|
(choices: {List of .json files in current dir})
|
||||||
|
--headless Run headless.
|
||||||
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -254,10 +255,13 @@ def get_geojson_dict(user_locations):
|
|||||||
"features": locs
|
"features": locs
|
||||||
}
|
}
|
||||||
|
|
||||||
def draw_map(map_type, geo_dict, filename):
|
def draw_map(map_type, geo_dict, filename, headless):
|
||||||
|
import matplotlib as mpl
|
||||||
|
if headless:
|
||||||
|
mpl.use("Agg")
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
from mpl_toolkits.basemap import Basemap
|
from mpl_toolkits.basemap import Basemap
|
||||||
import matplotlib as mpl
|
|
||||||
## Map stuff ##
|
## Map stuff ##
|
||||||
plt.figure(figsize=(16, 9), dpi=100, frameon=False, tight_layout=True)
|
plt.figure(figsize=(16, 9), dpi=100, frameon=False, tight_layout=True)
|
||||||
lon_r = 0
|
lon_r = 0
|
||||||
@ -360,13 +364,13 @@ def draw_map(map_type, geo_dict, filename):
|
|||||||
plt.setp(text, color='#A5A5A7')
|
plt.setp(text, color='#A5A5A7')
|
||||||
|
|
||||||
plt.title(title_string)
|
plt.title(title_string)
|
||||||
mng = plt.get_current_fig_manager()
|
|
||||||
### works on Ubuntu??? >> did NOT working on windows
|
|
||||||
# mng.resize(*mng.window.maxsize())
|
|
||||||
mng.window.state('zoomed')
|
|
||||||
if filename:
|
if filename:
|
||||||
plt.savefig('{}.png'.format(filename))
|
plt.savefig('{}.png'.format(filename))
|
||||||
plt.show()
|
print('Image saved as: {}.png'.format(filename))
|
||||||
|
if not headless:
|
||||||
|
mng = plt.get_current_fig_manager()
|
||||||
|
mng.window.state('zoomed')
|
||||||
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
@ -394,7 +398,7 @@ if __name__ == '__main__':
|
|||||||
help='Filename of map. None will not save. \n(default: %(default)s)')
|
help='Filename of map. None will not save. \n(default: %(default)s)')
|
||||||
parser.add_argument('-j', '--json', nargs='?', type=str, choices=json_check, metavar='',
|
parser.add_argument('-j', '--json', nargs='?', type=str, choices=json_check, metavar='',
|
||||||
help='Filename of json file to use. \n(choices: %(choices)s)')
|
help='Filename of json file to use. \n(choices: %(choices)s)')
|
||||||
|
parser.add_argument('--headless', help='Run headless.', action='store_true')
|
||||||
|
|
||||||
opts = parser.parse_args()
|
opts = parser.parse_args()
|
||||||
if opts.json:
|
if opts.json:
|
||||||
@ -441,4 +445,4 @@ if __name__ == '__main__':
|
|||||||
print(r.json()['html_url'])
|
print(r.json()['html_url'])
|
||||||
webbrowser.open(r.json()['html_url'])
|
webbrowser.open(r.json()['html_url'])
|
||||||
else:
|
else:
|
||||||
draw_map(opts.location, geo_json, filename)
|
draw_map(opts.location, geo_json, filename, opts.headless)
|
||||||
|
Loading…
Reference in New Issue
Block a user