maps update. pep8 edits

This commit is contained in:
Blacktwin 2018-03-16 15:31:27 -04:00
parent da3427c33a
commit 6afbb692d3

View File

@ -32,8 +32,6 @@ from collections import OrderedDict
import argparse import argparse
import numpy as np import numpy as np
import time import time
from collections import Counter
import webbrowser import webbrowser
## EDIT THESE SETTINGS ## ## EDIT THESE SETTINGS ##
@ -95,6 +93,7 @@ class UserIPs(object):
self.play_count = d['play_count'] self.play_count = d['play_count']
self.platform = d['platform'] self.platform = d['platform']
def get_get_users_tables(users='', length=''): def get_get_users_tables(users='', length=''):
# Get the users list from PlexPy # Get the users list from PlexPy
@ -124,6 +123,7 @@ def get_get_users_tables(users='', length=''):
except Exception as e: except Exception as e:
sys.stderr.write("PlexPy API 'get_get_users_tables' request failed: {0}.".format(e)) sys.stderr.write("PlexPy API 'get_get_users_tables' request failed: {0}.".format(e))
def get_get_users_ips(user_id, length): def get_get_users_ips(user_id, length):
# Get the user IP list from PlexPy # Get the user IP list from PlexPy
payload = {'apikey': PLEXPY_APIKEY, payload = {'apikey': PLEXPY_APIKEY,
@ -139,6 +139,7 @@ def get_get_users_ips(user_id, length):
except Exception as e: except Exception as e:
sys.stderr.write("PlexPy API 'get_get_users_ips' request failed: {0}.".format(e)) sys.stderr.write("PlexPy API 'get_get_users_ips' request failed: {0}.".format(e))
def get_geoip_info(ip_address=''): def get_geoip_info(ip_address=''):
# Get the geo IP lookup from PlexPy # Get the geo IP lookup from PlexPy
payload = {'apikey': PLEXPY_APIKEY, payload = {'apikey': PLEXPY_APIKEY,
@ -161,6 +162,7 @@ def get_geoip_info(ip_address=''):
sys.stderr.write("PlexPy API 'get_geoip_lookup' request failed: {0}.".format(e)) sys.stderr.write("PlexPy API 'get_geoip_lookup' request failed: {0}.".format(e))
pass pass
def get_stream_type_by_top_10_platforms(): def get_stream_type_by_top_10_platforms():
# Get the user IP list from PlexPy # Get the user IP list from PlexPy
payload = {'apikey': PLEXPY_APIKEY, payload = {'apikey': PLEXPY_APIKEY,
@ -174,6 +176,7 @@ def get_stream_type_by_top_10_platforms():
except Exception as e: except Exception as e:
sys.stderr.write("PlexPy API 'get_stream_type_by_top_10_platforms' request failed: {0}.".format(e)) sys.stderr.write("PlexPy API 'get_stream_type_by_top_10_platforms' request failed: {0}.".format(e))
def add_to_dictlist(d, key, val): def add_to_dictlist(d, key, val):
if key not in d: if key not in d:
d[key] = [val] d[key] = [val]
@ -183,6 +186,7 @@ def add_to_dictlist(d, key, val):
if (val['region'], val['city']) == (x['region'], x['city']): if (val['region'], val['city']) == (x['region'], x['city']):
x['location_count'] += 1 x['location_count'] += 1
def get_geo_dict(length, users): def get_geo_dict(length, users):
geo_dict = {SERVER_FRIENDLY: [{'lon': SERVER_LON, 'lat': SERVER_LAT, 'city': SERVER_CITY, 'region': SERVER_STATE, geo_dict = {SERVER_FRIENDLY: [{'lon': SERVER_LON, 'lat': SERVER_LAT, 'city': SERVER_CITY, 'region': SERVER_STATE,
'ip': REPLACEMENT_WAN_IP, 'play_count': 0, 'platform': SERVER_PLATFORM, 'ip': REPLACEMENT_WAN_IP, 'play_count': 0, 'platform': SERVER_PLATFORM,
@ -211,6 +215,7 @@ def get_geo_dict(length, users):
pass pass
return geo_dict return geo_dict
def get_geojson_dict(user_locations): def get_geojson_dict(user_locations):
locs = [] locs = []
for username, locations in user_locations.iteritems(): for username, locations in user_locations.iteritems():
@ -255,6 +260,7 @@ def get_geojson_dict(user_locations):
"features": locs "features": locs
} }
def draw_map(map_type, geo_dict, filename, headless): def draw_map(map_type, geo_dict, filename, headless):
import matplotlib as mpl import matplotlib as mpl
if headless: if headless:
@ -336,12 +342,10 @@ def draw_map(map_type, geo_dict, filename, headless):
line.set_dashes(dashes) line.set_dashes(dashes)
else: else:
lines = m.plot(x, y, marker=marker, color=color, markersize=0, label=legend, alpha=.4, zorder=zord, m.plot(x, y, marker=marker, color=color, markersize=0, label=legend, alpha=.4, zorder=zord,
linewidth=2) linewidth=2)
client_plot = m.plot(px, py, marker=marker, color=color, markersize=markersize, m.plot(px, py, marker=marker, color=color, markersize=markersize, label=legend, alpha=alph, zorder=zord)
label=legend, alpha=alph, zorder=zord)
handles, labels = plt.gca().get_legend_handles_labels() handles, labels = plt.gca().get_legend_handles_labels()
idx = labels.index('Location: {}, {}, User: {}\nPlatform: {}, IP: {}, Play Count: {}'. idx = labels.index('Location: {}, {}, User: {}\nPlatform: {}, IP: {}, Play Count: {}'.
@ -410,7 +414,7 @@ if __name__ == '__main__':
with open(''.join(opts.json)) as json_data: with open(''.join(opts.json)) as json_data:
geo_json = json.load(json_data) geo_json = json.load(json_data)
else: else:
print(opts) # print(opts)
if opts.ignore and opts.users == 'all': if opts.ignore and opts.users == 'all':
users = [x for x in user_lst if x not in opts.ignore] users = [x for x in user_lst if x not in opts.ignore]
else: else:
@ -445,4 +449,5 @@ 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:
print(geo_json)
draw_map(opts.location, geo_json, filename, opts.headless) draw_map(opts.location, geo_json, filename, opts.headless)