From 54e323e3d5c29f9153594030208708bd2d1d573b Mon Sep 17 00:00:00 2001 From: Sachin Kamath Date: May 31 2016 05:55:00 +0000 Subject: python3 enhancements --- diff --git a/main.py b/main.py index 5657d65..0ba867b 100644 --- a/main.py +++ b/main.py @@ -39,7 +39,7 @@ def main(): # Object inits and argument processing userstats = stats() output = draw() - userstats.values['user'] = args.user + userstats.values['user'] = str(args.user) userstats.values['delta'] = int(args.weeks) * 604800 output.mode = args.mode output.filename = args.output @@ -47,8 +47,15 @@ def main(): # For json and text output, we need the JSON rather than the categories if args.mode.lower() == 'svg' or args.mode.lower() == 'png': out_obj = userstats.return_categories() + # To handle user with no activity + if len(out_obj): + print ('[!] No activity found for user ' + str(args.user)) + return elif args.mode.lower() == 'json' or args.mode.lower() == 'text': out_obj = userstats.return_json() + if out_obj['total'] == 0: + print ('[!] No activity found for user ' + str(args.user)) + return title = "Category distribution for user " + str(args.user) output.show_output(out_obj, title) @@ -56,4 +63,3 @@ def main(): if __name__ == '__main__': main() - print("[*] All done :)") diff --git a/output.py b/output.py index 94dd89d..b77715b 100644 --- a/output.py +++ b/output.py @@ -26,7 +26,7 @@ class draw: pie_chart.title = str(title) for key in input_json: percent = input_json[key] / float(sum(input_json.values())) * 100 - pie_chart.add(str(key), round(percent,2)) + pie_chart.add(str(key), round(percent, 2)) return pie_chart def show_logs(self, unicode_json): diff --git a/stats.py b/stats.py index 3090c9f..5be5521 100644 --- a/stats.py +++ b/stats.py @@ -19,7 +19,6 @@ class stats: print('[*] Grabbing datagrepper values..') response = requests.get(self.baseurl, params=self.values) unicode_json = response.json() - print(unicode_json) return unicode_json def return_categories(self):