{"action":"created","comment":{"url":"https://api.github.com/repos/ultrabug/py3status/pulls/comments/106793020","pull_request_review_id":27735699,"id":106793020,"diff_hunk":"@@ -61,43 +74,38 @@ def on_click(self, event):\n         else:\n             self.mode = 'ip'\n \n-    def _get_my_ip_and_location(self):\n+    def _get_my_ip_info(self):\n         \"\"\"\n         \"\"\"\n         try:\n-            if self.py3.format_contains(self.format, 'country'):\n-                resp = urlopen(self.url_geo, timeout=self.timeout).read()\n-                resp = json.loads(resp)\n-                country = resp['country']\n-                ip = resp['query']\n-            else:\n-                country = None\n-                ip = urlopen(self.url, timeout=self.timeout).read()\n-                ip = ip.decode('utf-8')\n+            resp = self.py3.request(self.url_geo, timeout=self.timeout).json()\n+            info = {}\n+            for placeholder in self.py3.get_placeholders_list(self.format):\n+                if placeholder in resp:\n+                    info[placeholder] = resp[placeholder]\n+            for old, new in self.substitutions.items():\n+                info[old] = resp.get(new)\n+            return info\n         except Exception:\n-            country = None\n-            ip = None\n-        return country, ip\n+            return None\n \n     def whatismyip(self):\n         \"\"\"\n         \"\"\"\n-        country, ip = self._get_my_ip_and_location()\n+        info = self._get_my_ip_info()\n         response = {\n             'cached_until': self.py3.time_in(self.negative_cache_timeout)\n         }\n \n-        if ip is None and self.hide_when_offline:\n+        if info is None and self.hide_when_offline:\n             response['full_text'] = ''\n-        elif ip is not None:\n+        elif info is not None:\n             response['cached_until'] = self.py3.time_in(self.cache_timeout)\n             if self.mode == 'ip':\n-                response['full_text'] = self.py3.safe_format(self.format, {\n-                    'country': country,\n-                    'ip': ip})\n+                response['full_text'] = self.py3.safe_format(self.format, info)\n             else:\n                 response['full_text'] = self.format_online\n-                response['color'] = self.py3.COLOR_GOOD\n+            response['color'] = self.py3.COLOR_GOOD","path":"py3status/modules/whatismyip.py","position":125,"original_position":125,"commit_id":"3e928ded0311c7071b334533e8bb2f046f19adce","original_commit_id":"3e928ded0311c7071b334533e8bb2f046f19adce","user":{"login":"lasers","id":852504,"avatar_url":"https://avatars1.githubusercontent.com/u/852504?v=3","gravatar_id":"","url":"https://api.github.com/users/lasers","html_url":"https://github.com/lasers","followers_url":"https://api.github.com/users/lasers/followers","following_url":"https://api.github.com/users/lasers/following{/other_user}","gists_url":"https://api.github.com/users/lasers/gists{/gist_id}","starred_url":"https://api.github.com/users/lasers/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lasers/subscriptions","organizations_url":"https://api.github.com/users/lasers/orgs","repos_url":"https://api.github.com/users/lasers/repos","events_url":"https://api.github.com/users/lasers/events{/privacy}","received_events_url":"https://api.github.com/users/lasers/received_events","type":"User","site_admin":false},"body":"I think this should be moved to line 104 because I feel if we keep it here, someone eventually will view this as a mis-indentation in the future. ","created_at":"2017-03-18T22:37:21Z","updated_at":"2017-03-18T22:37:35Z","html_url":"https://github.com/ultrabug/py3status/pull/819#discussion_r106793020","pull_request_url":"https://api.github.com/repos/ultrabug/py3status/pulls/819","_links":{"self":{"href":"https://api.github.com/repos/ultrabug/py3status/pulls/comments/106793020"},"html":{"href":"https://github.com/ultrabug/py3status/pull/819#discussion_r106793020"},"pull_request":{"href":"https://api.github.com/repos/ultrabug/py3status/pulls/819"}}},"pull_request":{"url":"https://api.github.com/repos/ultrabug/py3status/pulls/819","id":111409724,"html_url":"https://github.com/ultrabug/py3status/pull/819","diff_url":"https://github.com/ultrabug/py3status/pull/819.diff","patch_url":"https://github.com/ultrabug/py3status/pull/819.patch","issue_url":"https://api.github.com/repos/ultrabug/py3status/issues/819","number":819,"state":"open","locked":false,"title":"[whatismyip] Support any format placeholder, always use `url_geo` with a better default","user":{"login":"maximbaz","id":1177900,"avatar_url":"https://avatars1.githubusercontent.com/u/1177900?v=3","gravatar_id":"","url":"https://api.github.com/users/maximbaz","html_url":"https://github.com/maximbaz","followers_url":"https://api.github.com/users/maximbaz/followers","following_url":"https://api.github.com/users/maximbaz/following{/other_user}","gists_url":"https://api.github.com/users/maximbaz/gists{/gist_id}","starred_url":"https://api.github.com/users/maximbaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maximbaz/subscriptions","organizations_url":"https://api.github.com/users/maximbaz/orgs","repos_url":"https://api.github.com/users/maximbaz/repos","events_url":"https://api.github.com/users/maximbaz/events{/privacy}","received_events_url":"https://api.github.com/users/maximbaz/received_events","type":"User","site_admin":false},"body":"A better way to approach #817.\r\n\r\nAdjustments to the `whatismyip` module:\r\n\r\n- Support any format placeholder that is available in JSON response of `url_geo`, not only hardcoded ones.\r\n- Use a better default value for `url_geo`, which doesn't have DNS issues.\r\n- Remove `url` and always use `url_geo` to simplify the code.\r\n- Ensure the COLOR_GOOD is always used when online.\r\n\r\n@tobes please have a look and let me know what you think, I'll test more later today and fix lint issues if they occur.","created_at":"2017-03-18T13:08:30Z","updated_at":"2017-03-18T22:37:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"7d894708cae0c7e47721f6366b6f3c0d4fdaedda","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/ultrabug/py3status/pulls/819/commits","review_comments_url":"https://api.github.com/repos/ultrabug/py3status/pulls/819/comments","review_comment_url":"https://api.github.com/repos/ultrabug/py3status/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ultrabug/py3status/issues/819/comments","statuses_url":"https://api.github.com/repos/ultrabug/py3status/statuses/3e928ded0311c7071b334533e8bb2f046f19adce","head":{"label":"maximbaz:whatismyip-allow-any-format-options","ref":"whatismyip-allow-any-format-options","sha":"3e928ded0311c7071b334533e8bb2f046f19adce","user":{"login":"maximbaz","id":1177900,"avatar_url":"https://avatars1.githubusercontent.com/u/1177900?v=3","gravatar_id":"","url":"https://api.github.com/users/maximbaz","html_url":"https://github.com/maximbaz","followers_url":"https://api.github.com/users/maximbaz/followers","following_url":"https://api.github.com/users/maximbaz/following{/other_user}","gists_url":"https://api.github.com/users/maximbaz/gists{/gist_id}","starred_url":"https://api.github.com/users/maximbaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maximbaz/subscriptions","organizations_url":"https://api.github.com/users/maximbaz/orgs","repos_url":"https://api.github.com/users/maximbaz/repos","events_url":"https://api.github.com/users/maximbaz/events{/privacy}","received_events_url":"https://api.github.com/users/maximbaz/received_events","type":"User","site_admin":false},"repo":{"id":44889392,"name":"py3status","full_name":"maximbaz/py3status","owner":{"login":"maximbaz","id":1177900,"avatar_url":"https://avatars1.githubusercontent.com/u/1177900?v=3","gravatar_id":"","url":"https://api.github.com/users/maximbaz","html_url":"https://github.com/maximbaz","followers_url":"https://api.github.com/users/maximbaz/followers","following_url":"https://api.github.com/users/maximbaz/following{/other_user}","gists_url":"https://api.github.com/users/maximbaz/gists{/gist_id}","starred_url":"https://api.github.com/users/maximbaz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/maximbaz/subscriptions","organizations_url":"https://api.github.com/users/maximbaz/orgs","repos_url":"https://api.github.com/users/maximbaz/repos","events_url":"https://api.github.com/users/maximbaz/events{/privacy}","received_events_url":"https://api.github.com/users/maximbaz/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/maximbaz/py3status","description":"py3status is an extensible i3status wrapper written in python","fork":true,"url":"https://api.github.com/repos/maximbaz/py3status","forks_url":"https://api.github.com/repos/maximbaz/py3status/forks","keys_url":"https://api.github.com/repos/maximbaz/py3status/keys{/key_id}","collaborators_url":"https://api.github.com/repos/maximbaz/py3status/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/maximbaz/py3status/teams","hooks_url":"https://api.github.com/repos/maximbaz/py3status/hooks","issue_events_url":"https://api.github.com/repos/maximbaz/py3status/issues/events{/number}","events_url":"https://api.github.com/repos/maximbaz/py3status/events","assignees_url":"https://api.github.com/repos/maximbaz/py3status/assignees{/user}","branches_url":"https://api.github.com/repos/maximbaz/py3status/branches{/branch}","tags_url":"https://api.github.com/repos/maximbaz/py3status/tags","blobs_url":"https://api.github.com/repos/maximbaz/py3status/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/maximbaz/py3status/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/maximbaz/py3status/git/refs{/sha}","trees_url":"https://api.github.com/repos/maximbaz/py3status/git/trees{/sha}","statuses_url":"https://api.github.com/repos/maximbaz/py3status/statuses/{sha}","languages_url":"https://api.github.com/repos/maximbaz/py3status/languages","stargazers_url":"https://api.github.com/repos/maximbaz/py3status/stargazers","contributors_url":"https://api.github.com/repos/maximbaz/py3status/contributors","subscribers_url":"https://api.github.com/repos/maximbaz/py3status/subscribers","subscription_url":"https://api.github.com/repos/maximbaz/py3status/subscription","commits_url":"https://api.github.com/repos/maximbaz/py3status/commits{/sha}","git_commits_url":"https://api.github.com/repos/maximbaz/py3status/git/commits{/sha}","comments_url":"https://api.github.com/repos/maximbaz/py3status/comments{/number}","issue_comment_url":"https://api.github.com/repos/maximbaz/py3status/issues/comments{/number}","contents_url":"https://api.github.com/repos/maximbaz/py3status/contents/{+path}","compare_url":"https://api.github.com/repos/maximbaz/py3status/compare/{base}...{head}","merges_url":"https://api.github.com/repos/maximbaz/py3status/merges","archive_url":"https://api.github.com/repos/maximbaz/py3status/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/maximbaz/py3status/downloads","issues_url":"https://api.github.com/repos/maximbaz/py3status/issues{/number}","pulls_url":"https://api.github.com/repos/maximbaz/py3status/pulls{/number}","milestones_url":"https://api.github.com/repos/maximbaz/py3status/milestones{/number}","notifications_url":"https://api.github.com/repos/maximbaz/py3status/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/maximbaz/py3status/labels{/name}","releases_url":"https://api.github.com/repos/maximbaz/py3status/releases{/id}","deployments_url":"https://api.github.com/repos/maximbaz/py3status/deployments","created_at":"2015-10-24T23:43:23Z","updated_at":"2015-10-24T23:43:25Z","pushed_at":"2017-03-18T22:19:59Z","git_url":"git://github.com/maximbaz/py3status.git","ssh_url":"git@github.com:maximbaz/py3status.git","clone_url":"https://github.com/maximbaz/py3status.git","svn_url":"https://github.com/maximbaz/py3status","homepage":"","size":2647,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"ultrabug:master","ref":"master","sha":"638a63c156d342fe081fb3fec3b863ee59e3807f","user":{"login":"ultrabug","id":474389,"avatar_url":"https://avatars0.githubusercontent.com/u/474389?v=3","gravatar_id":"","url":"https://api.github.com/users/ultrabug","html_url":"https://github.com/ultrabug","followers_url":"https://api.github.com/users/ultrabug/followers","following_url":"https://api.github.com/users/ultrabug/following{/other_user}","gists_url":"https://api.github.com/users/ultrabug/gists{/gist_id}","starred_url":"https://api.github.com/users/ultrabug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ultrabug/subscriptions","organizations_url":"https://api.github.com/users/ultrabug/orgs","repos_url":"https://api.github.com/users/ultrabug/repos","events_url":"https://api.github.com/users/ultrabug/events{/privacy}","received_events_url":"https://api.github.com/users/ultrabug/received_events","type":"User","site_admin":false},"repo":{"id":8292338,"name":"py3status","full_name":"ultrabug/py3status","owner":{"login":"ultrabug","id":474389,"avatar_url":"https://avatars0.githubusercontent.com/u/474389?v=3","gravatar_id":"","url":"https://api.github.com/users/ultrabug","html_url":"https://github.com/ultrabug","followers_url":"https://api.github.com/users/ultrabug/followers","following_url":"https://api.github.com/users/ultrabug/following{/other_user}","gists_url":"https://api.github.com/users/ultrabug/gists{/gist_id}","starred_url":"https://api.github.com/users/ultrabug/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ultrabug/subscriptions","organizations_url":"https://api.github.com/users/ultrabug/orgs","repos_url":"https://api.github.com/users/ultrabug/repos","events_url":"https://api.github.com/users/ultrabug/events{/privacy}","received_events_url":"https://api.github.com/users/ultrabug/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ultrabug/py3status","description":"py3status is an extensible i3status wrapper written in python","fork":false,"url":"https://api.github.com/repos/ultrabug/py3status","forks_url":"https://api.github.com/repos/ultrabug/py3status/forks","keys_url":"https://api.github.com/repos/ultrabug/py3status/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ultrabug/py3status/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ultrabug/py3status/teams","hooks_url":"https://api.github.com/repos/ultrabug/py3status/hooks","issue_events_url":"https://api.github.com/repos/ultrabug/py3status/issues/events{/number}","events_url":"https://api.github.com/repos/ultrabug/py3status/events","assignees_url":"https://api.github.com/repos/ultrabug/py3status/assignees{/user}","branches_url":"https://api.github.com/repos/ultrabug/py3status/branches{/branch}","tags_url":"https://api.github.com/repos/ultrabug/py3status/tags","blobs_url":"https://api.github.com/repos/ultrabug/py3status/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ultrabug/py3status/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ultrabug/py3status/git/refs{/sha}","trees_url":"https://api.github.com/repos/ultrabug/py3status/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ultrabug/py3status/statuses/{sha}","languages_url":"https://api.github.com/repos/ultrabug/py3status/languages","stargazers_url":"https://api.github.com/repos/ultrabug/py3status/stargazers","contributors_url":"https://api.github.com/repos/ultrabug/py3status/contributors","subscribers_url":"https://api.github.com/repos/ultrabug/py3status/subscribers","subscription_url":"https://api.github.com/repos/ultrabug/py3status/subscription","commits_url":"https://api.github.com/repos/ultrabug/py3status/commits{/sha}","git_commits_url":"https://api.github.com/repos/ultrabug/py3status/git/commits{/sha}","comments_url":"https://api.github.com/repos/ultrabug/py3status/comments{/number}","issue_comment_url":"https://api.github.com/repos/ultrabug/py3status/issues/comments{/number}","contents_url":"https://api.github.com/repos/ultrabug/py3status/contents/{+path}","compare_url":"https://api.github.com/repos/ultrabug/py3status/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ultrabug/py3status/merges","archive_url":"https://api.github.com/repos/ultrabug/py3status/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ultrabug/py3status/downloads","issues_url":"https://api.github.com/repos/ultrabug/py3status/issues{/number}","pulls_url":"https://api.github.com/repos/ultrabug/py3status/pulls{/number}","milestones_url":"https://api.github.com/repos/ultrabug/py3status/milestones{/number}","notifications_url":"https://api.github.com/repos/ultrabug/py3status/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ultrabug/py3status/labels{/name}","releases_url":"https://api.github.com/repos/ultrabug/py3status/releases{/id}","deployments_url":"https://api.github.com/repos/ultrabug/py3status/deployments","created_at":"2013-02-19T14:59:13Z","updated_at":"2017-03-18T17:44:14Z","pushed_at":"2017-03-18T22:03:40Z","git_url":"git://github.com/ultrabug/py3status.git","ssh_url":"git@github.com:ultrabug/py3status.git","clone_url":"https://github.com/ultrabug/py3status.git","svn_url":"https://github.com/ultrabug/py3status","homepage":"","size":2744,"stargazers_count":386,"watchers_count":386,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":143,"mirror_url":null,"open_issues_count":55,"forks":143,"open_issues":55,"watchers":386,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ultrabug/py3status/pulls/819"},"html":{"href":"https://github.com/ultrabug/py3status/pull/819"},"issue":{"href":"https://api.github.com/repos/ultrabug/py3status/issues/819"},"comments":{"href":"https://api.github.com/repos/ultrabug/py3status/issues/819/comments"},"review_comments":{"href":"https://api.github.com/repos/ultrabug/py3status/pulls/819/comments"},"review_comment":{"href":"https://api.github.com/repos/ultrabug/py3status/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ultrabug/py3status/pulls/819/commits"},"statuses":{"href":"https://api.github.com/repos/ultrabug/py3status/statuses/3e928ded0311c7071b334533e8bb2f046f19adce"}}}}
{"actor":{"display_login":"lasers"}}