From 62af87f7a365991af43be182275471fbeea7578b Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Wed, 27 Jul 2016 18:47:37 -0700 Subject: [PATCH 1/3] There's a big warning before bot login and 2s wait for exit if the health report is turned on. Anonymous login succ/failed/relogin/logout info without any user account info will be sent to GA. The function is not called to wait Signal system merge. --- configs/config.json.example | 1 + configs/config.json.pokemons.example | 1 + pokecli.py | 7 ++++++ pokemongo_bot/health_record/__init__.py | 3 +++ pokemongo_bot/health_record/bot_event.py | 31 ++++++++++++++++++++++++ requirements.txt | 1 + 6 files changed, 44 insertions(+) create mode 100644 pokemongo_bot/health_record/__init__.py create mode 100644 pokemongo_bot/health_record/bot_event.py diff --git a/configs/config.json.example b/configs/config.json.example index afdd07e1b2..820a2fffd9 100644 --- a/configs/config.json.example +++ b/configs/config.json.example @@ -11,6 +11,7 @@ "action_wait_max": 4, "debug": false, "test": false, + "health_record": true, "location_cache": true, "distance_unit": "km", "reconnecting_timeout": 15, diff --git a/configs/config.json.pokemons.example b/configs/config.json.pokemons.example index 2e4539a99d..5d629d10cb 100644 --- a/configs/config.json.pokemons.example +++ b/configs/config.json.pokemons.example @@ -11,6 +11,7 @@ "action_wait_max": 4, "debug": false, "test": false, + "health_record": true, "location_cache": true, "distance_unit": "km", "item_filter": { diff --git a/pokecli.py b/pokecli.py index 5d80f89a72..a13064abe5 100755 --- a/pokecli.py +++ b/pokecli.py @@ -176,6 +176,13 @@ def init_config(): type=float, default=15.0 ) + parser.add_argument( + "-hr", + "--health_record", + help="Send anonymous bot event to GA for bot health record. Set \"health_record\":false if you need disable it.", + type=bool, + default=True + ) # Start to parse other attrs config = parser.parse_args() diff --git a/pokemongo_bot/health_record/__init__.py b/pokemongo_bot/health_record/__init__.py new file mode 100644 index 0000000000..a40a959a1c --- /dev/null +++ b/pokemongo_bot/health_record/__init__.py @@ -0,0 +1,3 @@ +# -*- coding: utf-8 -*- + +from bot_event import BotEvent diff --git a/pokemongo_bot/health_record/bot_event.py b/pokemongo_bot/health_record/bot_event.py new file mode 100644 index 0000000000..5efd8603e9 --- /dev/null +++ b/pokemongo_bot/health_record/bot_event.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +from UniversalAnalytics import Tracker +from pokemongo_bot import logger +from time import sleep + +class BotEvent(object): + def __init__(self,bot): + self.bot = bot + # UniversalAnalytics can be reviewed here: + # https://github.com/analytics-pros/universal-analytics-python + # For central TensorFlow training, forbiden any personally information + # report to server + # Review Very Carefully for the following line, forbiden ID changed PR: + if bot.config.health_record: + logger.log('[x] Send anonymous bot health report to server, it can be disabled by config \"health_record\":false in config file', 'red') + logger.log('[x] Wait for 2 seconds ', 'red') + sleep(3) + self.tracker = Tracker.create('UA-81469507-1', use_post=True) + # No RAW send function to be added here, to keep everything clean + def login_success(self): + if self.bot.config.health_record: + self.tracker.send('pageview', '/health_record', title='succ') + def login_failed(self): + if self.bot.config.health_record: + self.tracker.send('pageview', '/health_record', title='fail') + def login_retry(self): + if self.bot.config.health_record: + self.tracker.send('pageview', '/health_record', title='relogin') + def logout(self): + if self.bot.config.health_record: + self.tracker.send('pageview', '/health_record', title='logout') diff --git a/requirements.txt b/requirements.txt index cd60f8c2bd..4675c8a1c2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,3 +11,4 @@ enum34==1.1.6 pyyaml==3.11 haversine==0.4.5 polyline==1.3.1 +universal-analytics-python==0.2.4 From 929fa371c20ac41e40bc82857a879a8dcd0a89b7 Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Wed, 27 Jul 2016 18:52:18 -0700 Subject: [PATCH 2/3] Fixed page view is not true. --- pokemongo_bot/health_record/bot_event.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pokemongo_bot/health_record/bot_event.py b/pokemongo_bot/health_record/bot_event.py index 5efd8603e9..e8ba9fec6b 100644 --- a/pokemongo_bot/health_record/bot_event.py +++ b/pokemongo_bot/health_record/bot_event.py @@ -19,13 +19,13 @@ def __init__(self,bot): # No RAW send function to be added here, to keep everything clean def login_success(self): if self.bot.config.health_record: - self.tracker.send('pageview', '/health_record', title='succ') + self.tracker.send('pageview', '/loggedin', title='succ') def login_failed(self): if self.bot.config.health_record: - self.tracker.send('pageview', '/health_record', title='fail') + self.tracker.send('pageview', '/login', title='fail') def login_retry(self): if self.bot.config.health_record: - self.tracker.send('pageview', '/health_record', title='relogin') + self.tracker.send('pageview', '/relogin', title='relogin') def logout(self): if self.bot.config.health_record: - self.tracker.send('pageview', '/health_record', title='logout') + self.tracker.send('pageview', '/logout', title='logout') From 092504d16552e21eb2ce38be7954689386920083 Mon Sep 17 00:00:00 2001 From: Simba Zhang Date: Wed, 27 Jul 2016 19:07:32 -0700 Subject: [PATCH 3/3] Removed [x] since we ditched it. --- pokemongo_bot/health_record/bot_event.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pokemongo_bot/health_record/bot_event.py b/pokemongo_bot/health_record/bot_event.py index e8ba9fec6b..26189c344d 100644 --- a/pokemongo_bot/health_record/bot_event.py +++ b/pokemongo_bot/health_record/bot_event.py @@ -12,8 +12,8 @@ def __init__(self,bot): # report to server # Review Very Carefully for the following line, forbiden ID changed PR: if bot.config.health_record: - logger.log('[x] Send anonymous bot health report to server, it can be disabled by config \"health_record\":false in config file', 'red') - logger.log('[x] Wait for 2 seconds ', 'red') + logger.log('Send anonymous bot health report to server, it can be disabled by config \"health_record\":false in config file', 'red') + logger.log('Wait for 2 seconds ', 'red') sleep(3) self.tracker = Tracker.create('UA-81469507-1', use_post=True) # No RAW send function to be added here, to keep everything clean