{"action":"created","comment":{"url":"https://api.github.com/repos/4teamwork/ftw.aare/pulls/comments/171548567","pull_request_review_id":100418717,"id":171548567,"diff_hunk":"@@ -1,15 +1,66 @@\n import click\n import requests\n+import itertools\n+import datetime\n \n \n @click.command()\n-def aare():\n+@click.option('--statistics', help='show the hottest and the coolest temperature of the last 7 days', is_flag=\"True\")\n+def aare(statistics):\n     \"\"\"A simple command which displays the current aare temperature\"\"\"\n+    if statistics:\n+        display_stats()\n+    else:\n+        display_current_temp()\n+\n+\n+def display_current_temp():\n     api_url = 'http://aare.schwumm.ch/aare.json'\n     response = requests.get(api_url)\n     aare_json = response.json()\n     click.echo(\"Current temperature of the aare: {}° C\".format(aare_json[\"temperature\"]))\n \n \n+def get_min_max_date_of_datetime_temp_group(group):\n+    min_temp = 0\n+    max_temp = 0\n+    day = \"\"\n+    initial = True\n+    # group contains no index, therefore inital-bool is used to get the first entry\n+    for item in group:\n+        if initial:\n+            min_temp = item[1]\n+            max_temp = item[1]\n+            day = item[0].strftime(\"%Y-%m-%d\")\n+            initial = False\n+        if min_temp > item[1]:\n+            min_temp = item[1]\n+        if max_temp < item[1]:\n+            max_temp = item[1]\n+    return min_temp, max_temp, day\n+\n+\n+def display_stats():\n+    api_url = 'http://aare.schwumm.ch/api/archive'\n+    params = {\"from\": \"now\", \"to\": \"-7 days\"}\n+    # The website denies unknown user agents. So we have to impersonate a general webbrowser to gain access\n+    headers = {\n+        'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) '\n+                      'Chrome/50.0.2661.102 Safari/537.36'}\n+    response = requests.get(api_url, params, headers=headers)\n+    response_json = response.json()\n+    temperatures = response_json['data']['temperature']\n+    dates = [datetime.datetime.strptime(item, '%Y-%m-%d %H:%M:%S') for item in response_json['data']['datetime']]\n+    data = list(zip(dates, temperatures))\n+\n+    # Remove data points not having a temperature\n+    data = list(filter(lambda item: item[1], data))\n+    for key, group in itertools.groupby(data, lambda item: datetime.date(item[0].year, item[0].month, item[0].day)):\n+        # group can be iterated only once because after the iteration it will be cleared automatically\n+        min_temp, max_temp, day_string = get_min_max_date_of_datetime_temp_group(group)","path":"aare/aare.py","position":61,"original_position":61,"commit_id":"1ea829e0d61927e6ff551f9f7f5d44d247939309","original_commit_id":"1ea829e0d61927e6ff551f9f7f5d44d247939309","user":{"login":"mbaechtold","id":28220,"avatar_url":"https://avatars3.githubusercontent.com/u/28220?v=4","gravatar_id":"","url":"https://api.github.com/users/mbaechtold","html_url":"https://github.com/mbaechtold","followers_url":"https://api.github.com/users/mbaechtold/followers","following_url":"https://api.github.com/users/mbaechtold/following{/other_user}","gists_url":"https://api.github.com/users/mbaechtold/gists{/gist_id}","starred_url":"https://api.github.com/users/mbaechtold/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbaechtold/subscriptions","organizations_url":"https://api.github.com/users/mbaechtold/orgs","repos_url":"https://api.github.com/users/mbaechtold/repos","events_url":"https://api.github.com/users/mbaechtold/events{/privacy}","received_events_url":"https://api.github.com/users/mbaechtold/received_events","type":"User","site_admin":false},"body":"You could use this instead:\r\n\r\n```python\r\ntemperatures = [item[1] for item in tuple(group)]\r\nmin_temp = min(temperatures)\r\nmax_temp = max(temperatures)\r\nday_string = key.strftime('%Y-%m-%d')\r\n```","created_at":"2018-03-01T12:51:27Z","updated_at":"2018-03-01T12:52:40Z","html_url":"https://github.com/4teamwork/ftw.aare/pull/7#discussion_r171548567","pull_request_url":"https://api.github.com/repos/4teamwork/ftw.aare/pulls/7","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/4teamwork/ftw.aare/pulls/comments/171548567"},"html":{"href":"https://github.com/4teamwork/ftw.aare/pull/7#discussion_r171548567"},"pull_request":{"href":"https://api.github.com/repos/4teamwork/ftw.aare/pulls/7"}}},"pull_request":{"url":"https://api.github.com/repos/4teamwork/ftw.aare/pulls/7","id":172225620,"html_url":"https://github.com/4teamwork/ftw.aare/pull/7","diff_url":"https://github.com/4teamwork/ftw.aare/pull/7.diff","patch_url":"https://github.com/4teamwork/ftw.aare/pull/7.patch","issue_url":"https://api.github.com/repos/4teamwork/ftw.aare/issues/7","number":7,"state":"open","locked":false,"title":"Spi/implement statistics","user":{"login":"stevenpi","id":16802792,"avatar_url":"https://avatars3.githubusercontent.com/u/16802792?v=4","gravatar_id":"","url":"https://api.github.com/users/stevenpi","html_url":"https://github.com/stevenpi","followers_url":"https://api.github.com/users/stevenpi/followers","following_url":"https://api.github.com/users/stevenpi/following{/other_user}","gists_url":"https://api.github.com/users/stevenpi/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenpi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenpi/subscriptions","organizations_url":"https://api.github.com/users/stevenpi/orgs","repos_url":"https://api.github.com/users/stevenpi/repos","events_url":"https://api.github.com/users/stevenpi/events{/privacy}","received_events_url":"https://api.github.com/users/stevenpi/received_events","type":"User","site_admin":false},"body":"Statistics option implemented. \r\nExample output:\r\n```\r\n2018-02-22: min 4.71° C, max 5.05° C\r\n2018-02-23: min 4.66° C, max 5° C\r\n2018-02-24: min 4.62° C, max 5.16° C\r\n2018-02-25: min 3.81° C, max 5.06° C\r\n2018-02-26: min 3.26° C, max 4.77° C\r\n2018-02-27: min 2.73° C, max 4.6° C\r\n2018-02-28: min 2.75° C, max 5° C\r\n2018-03-01: min 2.95° C, max 4.07° C\r\n```\r\n","created_at":"2018-03-01T12:39:53Z","updated_at":"2018-03-01T12:52:40Z","closed_at":null,"merged_at":null,"merge_commit_sha":"642ca59ece4a8cbc9936672cc00024994c5135ff","assignee":{"login":"stevenpi","id":16802792,"avatar_url":"https://avatars3.githubusercontent.com/u/16802792?v=4","gravatar_id":"","url":"https://api.github.com/users/stevenpi","html_url":"https://github.com/stevenpi","followers_url":"https://api.github.com/users/stevenpi/followers","following_url":"https://api.github.com/users/stevenpi/following{/other_user}","gists_url":"https://api.github.com/users/stevenpi/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenpi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenpi/subscriptions","organizations_url":"https://api.github.com/users/stevenpi/orgs","repos_url":"https://api.github.com/users/stevenpi/repos","events_url":"https://api.github.com/users/stevenpi/events{/privacy}","received_events_url":"https://api.github.com/users/stevenpi/received_events","type":"User","site_admin":false},"assignees":[{"login":"stevenpi","id":16802792,"avatar_url":"https://avatars3.githubusercontent.com/u/16802792?v=4","gravatar_id":"","url":"https://api.github.com/users/stevenpi","html_url":"https://github.com/stevenpi","followers_url":"https://api.github.com/users/stevenpi/followers","following_url":"https://api.github.com/users/stevenpi/following{/other_user}","gists_url":"https://api.github.com/users/stevenpi/gists{/gist_id}","starred_url":"https://api.github.com/users/stevenpi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stevenpi/subscriptions","organizations_url":"https://api.github.com/users/stevenpi/orgs","repos_url":"https://api.github.com/users/stevenpi/repos","events_url":"https://api.github.com/users/stevenpi/events{/privacy}","received_events_url":"https://api.github.com/users/stevenpi/received_events","type":"User","site_admin":false}],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/4teamwork/ftw.aare/pulls/7/commits","review_comments_url":"https://api.github.com/repos/4teamwork/ftw.aare/pulls/7/comments","review_comment_url":"https://api.github.com/repos/4teamwork/ftw.aare/pulls/comments{/number}","comments_url":"https://api.github.com/repos/4teamwork/ftw.aare/issues/7/comments","statuses_url":"https://api.github.com/repos/4teamwork/ftw.aare/statuses/1ea829e0d61927e6ff551f9f7f5d44d247939309","head":{"label":"4teamwork:spi/implement_statistics","ref":"spi/implement_statistics","sha":"1ea829e0d61927e6ff551f9f7f5d44d247939309","user":{"login":"4teamwork","id":681821,"avatar_url":"https://avatars2.githubusercontent.com/u/681821?v=4","gravatar_id":"","url":"https://api.github.com/users/4teamwork","html_url":"https://github.com/4teamwork","followers_url":"https://api.github.com/users/4teamwork/followers","following_url":"https://api.github.com/users/4teamwork/following{/other_user}","gists_url":"https://api.github.com/users/4teamwork/gists{/gist_id}","starred_url":"https://api.github.com/users/4teamwork/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/4teamwork/subscriptions","organizations_url":"https://api.github.com/users/4teamwork/orgs","repos_url":"https://api.github.com/users/4teamwork/repos","events_url":"https://api.github.com/users/4teamwork/events{/privacy}","received_events_url":"https://api.github.com/users/4teamwork/received_events","type":"Organization","site_admin":false},"repo":{"id":122596892,"name":"ftw.aare","full_name":"4teamwork/ftw.aare","owner":{"login":"4teamwork","id":681821,"avatar_url":"https://avatars2.githubusercontent.com/u/681821?v=4","gravatar_id":"","url":"https://api.github.com/users/4teamwork","html_url":"https://github.com/4teamwork","followers_url":"https://api.github.com/users/4teamwork/followers","following_url":"https://api.github.com/users/4teamwork/following{/other_user}","gists_url":"https://api.github.com/users/4teamwork/gists{/gist_id}","starred_url":"https://api.github.com/users/4teamwork/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/4teamwork/subscriptions","organizations_url":"https://api.github.com/users/4teamwork/orgs","repos_url":"https://api.github.com/users/4teamwork/repos","events_url":"https://api.github.com/users/4teamwork/events{/privacy}","received_events_url":"https://api.github.com/users/4teamwork/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/4teamwork/ftw.aare","description":"A Shell Command which displays the current temperature of the Aare in Bern, Switzerland","fork":false,"url":"https://api.github.com/repos/4teamwork/ftw.aare","forks_url":"https://api.github.com/repos/4teamwork/ftw.aare/forks","keys_url":"https://api.github.com/repos/4teamwork/ftw.aare/keys{/key_id}","collaborators_url":"https://api.github.com/repos/4teamwork/ftw.aare/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/4teamwork/ftw.aare/teams","hooks_url":"https://api.github.com/repos/4teamwork/ftw.aare/hooks","issue_events_url":"https://api.github.com/repos/4teamwork/ftw.aare/issues/events{/number}","events_url":"https://api.github.com/repos/4teamwork/ftw.aare/events","assignees_url":"https://api.github.com/repos/4teamwork/ftw.aare/assignees{/user}","branches_url":"https://api.github.com/repos/4teamwork/ftw.aare/branches{/branch}","tags_url":"https://api.github.com/repos/4teamwork/ftw.aare/tags","blobs_url":"https://api.github.com/repos/4teamwork/ftw.aare/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/4teamwork/ftw.aare/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/4teamwork/ftw.aare/git/refs{/sha}","trees_url":"https://api.github.com/repos/4teamwork/ftw.aare/git/trees{/sha}","statuses_url":"https://api.github.com/repos/4teamwork/ftw.aare/statuses/{sha}","languages_url":"https://api.github.com/repos/4teamwork/ftw.aare/languages","stargazers_url":"https://api.github.com/repos/4teamwork/ftw.aare/stargazers","contributors_url":"https://api.github.com/repos/4teamwork/ftw.aare/contributors","subscribers_url":"https://api.github.com/repos/4teamwork/ftw.aare/subscribers","subscription_url":"https://api.github.com/repos/4teamwork/ftw.aare/subscription","commits_url":"https://api.github.com/repos/4teamwork/ftw.aare/commits{/sha}","git_commits_url":"https://api.github.com/repos/4teamwork/ftw.aare/git/commits{/sha}","comments_url":"https://api.github.com/repos/4teamwork/ftw.aare/comments{/number}","issue_comment_url":"https://api.github.com/repos/4teamwork/ftw.aare/issues/comments{/number}","contents_url":"https://api.github.com/repos/4teamwork/ftw.aare/contents/{+path}","compare_url":"https://api.github.com/repos/4teamwork/ftw.aare/compare/{base}...{head}","merges_url":"https://api.github.com/repos/4teamwork/ftw.aare/merges","archive_url":"https://api.github.com/repos/4teamwork/ftw.aare/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/4teamwork/ftw.aare/downloads","issues_url":"https://api.github.com/repos/4teamwork/ftw.aare/issues{/number}","pulls_url":"https://api.github.com/repos/4teamwork/ftw.aare/pulls{/number}","milestones_url":"https://api.github.com/repos/4teamwork/ftw.aare/milestones{/number}","notifications_url":"https://api.github.com/repos/4teamwork/ftw.aare/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/4teamwork/ftw.aare/labels{/name}","releases_url":"https://api.github.com/repos/4teamwork/ftw.aare/releases{/id}","deployments_url":"https://api.github.com/repos/4teamwork/ftw.aare/deployments","created_at":"2018-02-23T08:55:53Z","updated_at":"2018-02-23T10:17:21Z","pushed_at":"2018-03-01T12:39:54Z","git_url":"git://github.com/4teamwork/ftw.aare.git","ssh_url":"git@github.com:4teamwork/ftw.aare.git","clone_url":"https://github.com/4teamwork/ftw.aare.git","svn_url":"https://github.com/4teamwork/ftw.aare","homepage":null,"size":6,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":4,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"base":{"label":"4teamwork:master","ref":"master","sha":"3d2b70c86a2474924457027fe91f780e02f20b5c","user":{"login":"4teamwork","id":681821,"avatar_url":"https://avatars2.githubusercontent.com/u/681821?v=4","gravatar_id":"","url":"https://api.github.com/users/4teamwork","html_url":"https://github.com/4teamwork","followers_url":"https://api.github.com/users/4teamwork/followers","following_url":"https://api.github.com/users/4teamwork/following{/other_user}","gists_url":"https://api.github.com/users/4teamwork/gists{/gist_id}","starred_url":"https://api.github.com/users/4teamwork/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/4teamwork/subscriptions","organizations_url":"https://api.github.com/users/4teamwork/orgs","repos_url":"https://api.github.com/users/4teamwork/repos","events_url":"https://api.github.com/users/4teamwork/events{/privacy}","received_events_url":"https://api.github.com/users/4teamwork/received_events","type":"Organization","site_admin":false},"repo":{"id":122596892,"name":"ftw.aare","full_name":"4teamwork/ftw.aare","owner":{"login":"4teamwork","id":681821,"avatar_url":"https://avatars2.githubusercontent.com/u/681821?v=4","gravatar_id":"","url":"https://api.github.com/users/4teamwork","html_url":"https://github.com/4teamwork","followers_url":"https://api.github.com/users/4teamwork/followers","following_url":"https://api.github.com/users/4teamwork/following{/other_user}","gists_url":"https://api.github.com/users/4teamwork/gists{/gist_id}","starred_url":"https://api.github.com/users/4teamwork/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/4teamwork/subscriptions","organizations_url":"https://api.github.com/users/4teamwork/orgs","repos_url":"https://api.github.com/users/4teamwork/repos","events_url":"https://api.github.com/users/4teamwork/events{/privacy}","received_events_url":"https://api.github.com/users/4teamwork/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/4teamwork/ftw.aare","description":"A Shell Command which displays the current temperature of the Aare in Bern, Switzerland","fork":false,"url":"https://api.github.com/repos/4teamwork/ftw.aare","forks_url":"https://api.github.com/repos/4teamwork/ftw.aare/forks","keys_url":"https://api.github.com/repos/4teamwork/ftw.aare/keys{/key_id}","collaborators_url":"https://api.github.com/repos/4teamwork/ftw.aare/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/4teamwork/ftw.aare/teams","hooks_url":"https://api.github.com/repos/4teamwork/ftw.aare/hooks","issue_events_url":"https://api.github.com/repos/4teamwork/ftw.aare/issues/events{/number}","events_url":"https://api.github.com/repos/4teamwork/ftw.aare/events","assignees_url":"https://api.github.com/repos/4teamwork/ftw.aare/assignees{/user}","branches_url":"https://api.github.com/repos/4teamwork/ftw.aare/branches{/branch}","tags_url":"https://api.github.com/repos/4teamwork/ftw.aare/tags","blobs_url":"https://api.github.com/repos/4teamwork/ftw.aare/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/4teamwork/ftw.aare/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/4teamwork/ftw.aare/git/refs{/sha}","trees_url":"https://api.github.com/repos/4teamwork/ftw.aare/git/trees{/sha}","statuses_url":"https://api.github.com/repos/4teamwork/ftw.aare/statuses/{sha}","languages_url":"https://api.github.com/repos/4teamwork/ftw.aare/languages","stargazers_url":"https://api.github.com/repos/4teamwork/ftw.aare/stargazers","contributors_url":"https://api.github.com/repos/4teamwork/ftw.aare/contributors","subscribers_url":"https://api.github.com/repos/4teamwork/ftw.aare/subscribers","subscription_url":"https://api.github.com/repos/4teamwork/ftw.aare/subscription","commits_url":"https://api.github.com/repos/4teamwork/ftw.aare/commits{/sha}","git_commits_url":"https://api.github.com/repos/4teamwork/ftw.aare/git/commits{/sha}","comments_url":"https://api.github.com/repos/4teamwork/ftw.aare/comments{/number}","issue_comment_url":"https://api.github.com/repos/4teamwork/ftw.aare/issues/comments{/number}","contents_url":"https://api.github.com/repos/4teamwork/ftw.aare/contents/{+path}","compare_url":"https://api.github.com/repos/4teamwork/ftw.aare/compare/{base}...{head}","merges_url":"https://api.github.com/repos/4teamwork/ftw.aare/merges","archive_url":"https://api.github.com/repos/4teamwork/ftw.aare/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/4teamwork/ftw.aare/downloads","issues_url":"https://api.github.com/repos/4teamwork/ftw.aare/issues{/number}","pulls_url":"https://api.github.com/repos/4teamwork/ftw.aare/pulls{/number}","milestones_url":"https://api.github.com/repos/4teamwork/ftw.aare/milestones{/number}","notifications_url":"https://api.github.com/repos/4teamwork/ftw.aare/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/4teamwork/ftw.aare/labels{/name}","releases_url":"https://api.github.com/repos/4teamwork/ftw.aare/releases{/id}","deployments_url":"https://api.github.com/repos/4teamwork/ftw.aare/deployments","created_at":"2018-02-23T08:55:53Z","updated_at":"2018-02-23T10:17:21Z","pushed_at":"2018-03-01T12:39:54Z","git_url":"git://github.com/4teamwork/ftw.aare.git","ssh_url":"git@github.com:4teamwork/ftw.aare.git","clone_url":"https://github.com/4teamwork/ftw.aare.git","svn_url":"https://github.com/4teamwork/ftw.aare","homepage":null,"size":6,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":4,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit"},"forks":0,"open_issues":4,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/4teamwork/ftw.aare/pulls/7"},"html":{"href":"https://github.com/4teamwork/ftw.aare/pull/7"},"issue":{"href":"https://api.github.com/repos/4teamwork/ftw.aare/issues/7"},"comments":{"href":"https://api.github.com/repos/4teamwork/ftw.aare/issues/7/comments"},"review_comments":{"href":"https://api.github.com/repos/4teamwork/ftw.aare/pulls/7/comments"},"review_comment":{"href":"https://api.github.com/repos/4teamwork/ftw.aare/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/4teamwork/ftw.aare/pulls/7/commits"},"statuses":{"href":"https://api.github.com/repos/4teamwork/ftw.aare/statuses/1ea829e0d61927e6ff551f9f7f5d44d247939309"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"mbaechtold"}}