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