{"action":"created","comment":{"url":"https://api.github.com/repos/mattallinson/NuclearTrains/pulls/comments/242970502","pull_request_review_id":186608605,"id":242970502,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI0Mjk3MDUwMg==","diff_hunk":"@@ -145,90 +158,58 @@ def populate(self):\n             return False\n         else:\n             self.webpage_checksum = md5sum\n-\n-        soup = BeautifulSoup(r.text, \"html.parser\")\n-        if soup.text == NO_SCHEDULE:\n+        \n+        if 'realtimeActivated' not in r.json().keys():\n             self.running = False\n-            raise RuntimeError(\"schedule not found\")\n-        # Top of page shows schedule info, including if a\n-        # runs-as-required train is active\n-        schedule_info = soup.find(\"div\",\n-                                  attrs={\"class\": \"detailed-schedule-info\"})\n-        # Text in schedule_info isn't tagged well\n-        if \"Running\" in schedule_info.text:\n+            #raise RuntimeError(\"schedule not found\")\n+        else:\n             self.running = True\n-        # Important info is in <strong> tags. Their absolute position\n-        # is used, assuming it won't change as rtt isn't maintained\n-        info = schedule_info.find_all(\"strong\")\n-        self.stp_code = info[0]\n \n-        self.update_locations(soup)\n+        self.update_locations(r.json())\n         return True\n \n-\n def _location_datetime(loc_date, loc_timestring):\n     \"\"\"Creates a datetime object for a train calling location from\n     loc_date: a given date as a date object, and\n-    loc_timestring: the location's 4- or 5-digit time string\"\"\"\n+    \"\"\"\n     # Some values will not translate to a datetime object\n-    if loc_timestring in [\"\", \"pass\", \"N/R\"]:\n-        return None\n     # First four digits are in the simple form of HHMM\n     loc_time = datetime.datetime.strptime(loc_timestring[:4],\n                                           TIME_FORMAT).time()\n     loc_datetime = datetime.datetime.combine(loc_date, loc_time)\n-    # Sometimes there is a final fractional digit, whose value in\n-    # seconds stored as timedeltas can be looked up\n-    if len(loc_timestring) == 5:\n-        loc_datetime += FRAC_TIMES[loc_timestring[4]]\n+    # Sometimes the time is actual a 6 digit Hrs Mins Secs time\n+    if len(loc_timestring) == 6:\n+        loc_datetime += datetime.timedelta(seconds= int(loc_timestring[4:]))\n     return loc_datetime\n \n-\n-def _search_url(station, search_date=None, to_station=None,\n-                from_time=None, to_time=None):\n+def _search_url(station, search_date=None, to_station=None, to_time=None):\n     if search_date is None:\n         search_date = datetime.datetime.today()\n     url_date = search_date.strftime(DATE_FORMAT)\n-    if from_time is not None:\n-        from_string = from_time.strftime(TIME_FORMAT)\n-    else:\n-        from_string = DEFAULT_FROM\n-    if to_time is not None:\n-        to_string = to_time.strftime(TIME_FORMAT)\n-    else:\n-        to_string = DEFAULT_TO\n-    url_time = from_string + \"-\" + to_string\n+    \n     if to_station is not None:\n-        return \"/\".join([URL_PREFIX, \"search/advanced\", station,\n-                         \"to\", to_station, url_date, url_time])\n+        search_url = \"/\".join([URL_PREFIX, LOCATION_SEARCH, station, \"to\", to_station, url_date])\n     else:\n-        return \"/\".join([URL_PREFIX, \"search/advanced\",\n-                         station, url_date, url_time])\n+        search_url = \"/\".join([URL_PREFIX, LOCATION_SEARCH, station, url_date])\n+    \n+    if to_time is not None: #adds time specific searching\n+        time_string = to_time.strftime(TIME_FORMAT)\n+        search_url += \"/\"+time_string \n \n+    return search_url\n \n-def search(station, search_date=None, to_station=None,\n-           from_time=None, to_time=None):\n+def search(api_key, station, search_date = None, to_station=None, time=None):\n     trains = []\n     if search_date is None:\n         search_date = datetime.datetime.today()\n-    # This could be a one-liner but Exception handling of the request\n-    # will need to be implemented at some point\n-    url = _search_url(station, search_date, to_station, from_time, to_time)\n-    request = requests.get(url)\n-    page = BeautifulSoup(request.text, \"html.parser\")\n-    # For one, there is only the one table on the page\n-    table = page.find(\"table\")\n-    if table is None:\n-        return None\n-    # Discard the first table row, as it is the header\n-    rows = table.find_all(\"tr\")[1:]\n-\n-    for row in rows:\n-        id_url = row.find(\"a\")[\"href\"]\n-        # url is in form of \".../train/H61429/2016/04/23/advanced\"\n-        # we want the UID, the third part of this\n-        uid = id_url.split(\"/\")[2]\n-\n-        trains.append(Train(uid, search_date))\n+\n+    url = _search_url(station, to_station = to_station, search_date = search_date,  to_time = time)","path":"realtimetrains.py","position":258,"original_position":258,"commit_id":"b216aa00dd4a4becaa4937109c851a47996dd59f","original_commit_id":"b216aa00dd4a4becaa4937109c851a47996dd59f","user":{"login":"keirwl","id":9267895,"node_id":"MDQ6VXNlcjkyNjc4OTU=","avatar_url":"https://avatars3.githubusercontent.com/u/9267895?v=4","gravatar_id":"","url":"https://api.github.com/users/keirwl","html_url":"https://github.com/keirwl","followers_url":"https://api.github.com/users/keirwl/followers","following_url":"https://api.github.com/users/keirwl/following{/other_user}","gists_url":"https://api.github.com/users/keirwl/gists{/gist_id}","starred_url":"https://api.github.com/users/keirwl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keirwl/subscriptions","organizations_url":"https://api.github.com/users/keirwl/orgs","repos_url":"https://api.github.com/users/keirwl/repos","events_url":"https://api.github.com/users/keirwl/events{/privacy}","received_events_url":"https://api.github.com/users/keirwl/received_events","type":"User","site_admin":false},"body":"Spacing","created_at":"2018-12-19T15:56:06Z","updated_at":"2018-12-19T15:59:08Z","html_url":"https://github.com/mattallinson/NuclearTrains/pull/5#discussion_r242970502","pull_request_url":"https://api.github.com/repos/mattallinson/NuclearTrains/pulls/5","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/mattallinson/NuclearTrains/pulls/comments/242970502"},"html":{"href":"https://github.com/mattallinson/NuclearTrains/pull/5#discussion_r242970502"},"pull_request":{"href":"https://api.github.com/repos/mattallinson/NuclearTrains/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/mattallinson/NuclearTrains/pulls/5","id":239791703,"node_id":"MDExOlB1bGxSZXF1ZXN0MjM5NzkxNzAz","html_url":"https://github.com/mattallinson/NuclearTrains/pull/5","diff_url":"https://github.com/mattallinson/NuclearTrains/pull/5.diff","patch_url":"https://github.com/mattallinson/NuclearTrains/pull/5.patch","issue_url":"https://api.github.com/repos/mattallinson/NuclearTrains/issues/5","number":5,"state":"open","locked":false,"title":"Api rtt","user":{"login":"mattallinson","id":13021480,"node_id":"MDQ6VXNlcjEzMDIxNDgw","avatar_url":"https://avatars0.githubusercontent.com/u/13021480?v=4","gravatar_id":"","url":"https://api.github.com/users/mattallinson","html_url":"https://github.com/mattallinson","followers_url":"https://api.github.com/users/mattallinson/followers","following_url":"https://api.github.com/users/mattallinson/following{/other_user}","gists_url":"https://api.github.com/users/mattallinson/gists{/gist_id}","starred_url":"https://api.github.com/users/mattallinson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattallinson/subscriptions","organizations_url":"https://api.github.com/users/mattallinson/orgs","repos_url":"https://api.github.com/users/mattallinson/repos","events_url":"https://api.github.com/users/mattallinson/events{/privacy}","received_events_url":"https://api.github.com/users/mattallinson/received_events","type":"User","site_admin":false},"body":"Okay this should make the whole thing run from the API only but I think main.py might also require more updates, I've not tried to run a test verion of the whole thing yet, but made rtt.py generate lists of trains from searches and as far as i can tell from those it's working correctly. ","created_at":"2018-12-19T10:52:18Z","updated_at":"2018-12-19T15:59:08Z","closed_at":null,"merged_at":null,"merge_commit_sha":"453dce0b399a1c7d88630d579adbc8750af84a43","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/mattallinson/NuclearTrains/pulls/5/commits","review_comments_url":"https://api.github.com/repos/mattallinson/NuclearTrains/pulls/5/comments","review_comment_url":"https://api.github.com/repos/mattallinson/NuclearTrains/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mattallinson/NuclearTrains/issues/5/comments","statuses_url":"https://api.github.com/repos/mattallinson/NuclearTrains/statuses/b216aa00dd4a4becaa4937109c851a47996dd59f","head":{"label":"mattallinson:api-rtt","ref":"api-rtt","sha":"b216aa00dd4a4becaa4937109c851a47996dd59f","user":{"login":"mattallinson","id":13021480,"node_id":"MDQ6VXNlcjEzMDIxNDgw","avatar_url":"https://avatars0.githubusercontent.com/u/13021480?v=4","gravatar_id":"","url":"https://api.github.com/users/mattallinson","html_url":"https://github.com/mattallinson","followers_url":"https://api.github.com/users/mattallinson/followers","following_url":"https://api.github.com/users/mattallinson/following{/other_user}","gists_url":"https://api.github.com/users/mattallinson/gists{/gist_id}","starred_url":"https://api.github.com/users/mattallinson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattallinson/subscriptions","organizations_url":"https://api.github.com/users/mattallinson/orgs","repos_url":"https://api.github.com/users/mattallinson/repos","events_url":"https://api.github.com/users/mattallinson/events{/privacy}","received_events_url":"https://api.github.com/users/mattallinson/received_events","type":"User","site_admin":false},"repo":{"id":56329677,"node_id":"MDEwOlJlcG9zaXRvcnk1NjMyOTY3Nw==","name":"NuclearTrains","full_name":"mattallinson/NuclearTrains","private":false,"owner":{"login":"mattallinson","id":13021480,"node_id":"MDQ6VXNlcjEzMDIxNDgw","avatar_url":"https://avatars0.githubusercontent.com/u/13021480?v=4","gravatar_id":"","url":"https://api.github.com/users/mattallinson","html_url":"https://github.com/mattallinson","followers_url":"https://api.github.com/users/mattallinson/followers","following_url":"https://api.github.com/users/mattallinson/following{/other_user}","gists_url":"https://api.github.com/users/mattallinson/gists{/gist_id}","starred_url":"https://api.github.com/users/mattallinson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattallinson/subscriptions","organizations_url":"https://api.github.com/users/mattallinson/orgs","repos_url":"https://api.github.com/users/mattallinson/repos","events_url":"https://api.github.com/users/mattallinson/events{/privacy}","received_events_url":"https://api.github.com/users/mattallinson/received_events","type":"User","site_admin":false},"html_url":"https://github.com/mattallinson/NuclearTrains","description":"Twitter bot that live-tweets when UK Nuclear Waste trains are on the move","fork":false,"url":"https://api.github.com/repos/mattallinson/NuclearTrains","forks_url":"https://api.github.com/repos/mattallinson/NuclearTrains/forks","keys_url":"https://api.github.com/repos/mattallinson/NuclearTrains/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mattallinson/NuclearTrains/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mattallinson/NuclearTrains/teams","hooks_url":"https://api.github.com/repos/mattallinson/NuclearTrains/hooks","issue_events_url":"https://api.github.com/repos/mattallinson/NuclearTrains/issues/events{/number}","events_url":"https://api.github.com/repos/mattallinson/NuclearTrains/events","assignees_url":"https://api.github.com/repos/mattallinson/NuclearTrains/assignees{/user}","branches_url":"https://api.github.com/repos/mattallinson/NuclearTrains/branches{/branch}","tags_url":"https://api.github.com/repos/mattallinson/NuclearTrains/tags","blobs_url":"https://api.github.com/repos/mattallinson/NuclearTrains/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mattallinson/NuclearTrains/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mattallinson/NuclearTrains/git/refs{/sha}","trees_url":"https://api.github.com/repos/mattallinson/NuclearTrains/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mattallinson/NuclearTrains/statuses/{sha}","languages_url":"https://api.github.com/repos/mattallinson/NuclearTrains/languages","stargazers_url":"https://api.github.com/repos/mattallinson/NuclearTrains/stargazers","contributors_url":"https://api.github.com/repos/mattallinson/NuclearTrains/contributors","subscribers_url":"https://api.github.com/repos/mattallinson/NuclearTrains/subscribers","subscription_url":"https://api.github.com/repos/mattallinson/NuclearTrains/subscription","commits_url":"https://api.github.com/repos/mattallinson/NuclearTrains/commits{/sha}","git_commits_url":"https://api.github.com/repos/mattallinson/NuclearTrains/git/commits{/sha}","comments_url":"https://api.github.com/repos/mattallinson/NuclearTrains/comments{/number}","issue_comment_url":"https://api.github.com/repos/mattallinson/NuclearTrains/issues/comments{/number}","contents_url":"https://api.github.com/repos/mattallinson/NuclearTrains/contents/{+path}","compare_url":"https://api.github.com/repos/mattallinson/NuclearTrains/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mattallinson/NuclearTrains/merges","archive_url":"https://api.github.com/repos/mattallinson/NuclearTrains/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mattallinson/NuclearTrains/downloads","issues_url":"https://api.github.com/repos/mattallinson/NuclearTrains/issues{/number}","pulls_url":"https://api.github.com/repos/mattallinson/NuclearTrains/pulls{/number}","milestones_url":"https://api.github.com/repos/mattallinson/NuclearTrains/milestones{/number}","notifications_url":"https://api.github.com/repos/mattallinson/NuclearTrains/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mattallinson/NuclearTrains/labels{/name}","releases_url":"https://api.github.com/repos/mattallinson/NuclearTrains/releases{/id}","deployments_url":"https://api.github.com/repos/mattallinson/NuclearTrains/deployments","created_at":"2016-04-15T15:17:51Z","updated_at":"2018-11-29T15:55:12Z","pushed_at":"2018-12-19T13:06:18Z","git_url":"git://github.com/mattallinson/NuclearTrains.git","ssh_url":"git@github.com:mattallinson/NuclearTrains.git","clone_url":"https://github.com/mattallinson/NuclearTrains.git","svn_url":"https://github.com/mattallinson/NuclearTrains","homepage":"https://nucleartrains.wordpress.com/","size":702,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":3,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"base":{"label":"mattallinson:master","ref":"master","sha":"ac598a4a5e310708f3dae1678e6f9959c501f661","user":{"login":"mattallinson","id":13021480,"node_id":"MDQ6VXNlcjEzMDIxNDgw","avatar_url":"https://avatars0.githubusercontent.com/u/13021480?v=4","gravatar_id":"","url":"https://api.github.com/users/mattallinson","html_url":"https://github.com/mattallinson","followers_url":"https://api.github.com/users/mattallinson/followers","following_url":"https://api.github.com/users/mattallinson/following{/other_user}","gists_url":"https://api.github.com/users/mattallinson/gists{/gist_id}","starred_url":"https://api.github.com/users/mattallinson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattallinson/subscriptions","organizations_url":"https://api.github.com/users/mattallinson/orgs","repos_url":"https://api.github.com/users/mattallinson/repos","events_url":"https://api.github.com/users/mattallinson/events{/privacy}","received_events_url":"https://api.github.com/users/mattallinson/received_events","type":"User","site_admin":false},"repo":{"id":56329677,"node_id":"MDEwOlJlcG9zaXRvcnk1NjMyOTY3Nw==","name":"NuclearTrains","full_name":"mattallinson/NuclearTrains","private":false,"owner":{"login":"mattallinson","id":13021480,"node_id":"MDQ6VXNlcjEzMDIxNDgw","avatar_url":"https://avatars0.githubusercontent.com/u/13021480?v=4","gravatar_id":"","url":"https://api.github.com/users/mattallinson","html_url":"https://github.com/mattallinson","followers_url":"https://api.github.com/users/mattallinson/followers","following_url":"https://api.github.com/users/mattallinson/following{/other_user}","gists_url":"https://api.github.com/users/mattallinson/gists{/gist_id}","starred_url":"https://api.github.com/users/mattallinson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattallinson/subscriptions","organizations_url":"https://api.github.com/users/mattallinson/orgs","repos_url":"https://api.github.com/users/mattallinson/repos","events_url":"https://api.github.com/users/mattallinson/events{/privacy}","received_events_url":"https://api.github.com/users/mattallinson/received_events","type":"User","site_admin":false},"html_url":"https://github.com/mattallinson/NuclearTrains","description":"Twitter bot that live-tweets when UK Nuclear Waste trains are on the move","fork":false,"url":"https://api.github.com/repos/mattallinson/NuclearTrains","forks_url":"https://api.github.com/repos/mattallinson/NuclearTrains/forks","keys_url":"https://api.github.com/repos/mattallinson/NuclearTrains/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mattallinson/NuclearTrains/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mattallinson/NuclearTrains/teams","hooks_url":"https://api.github.com/repos/mattallinson/NuclearTrains/hooks","issue_events_url":"https://api.github.com/repos/mattallinson/NuclearTrains/issues/events{/number}","events_url":"https://api.github.com/repos/mattallinson/NuclearTrains/events","assignees_url":"https://api.github.com/repos/mattallinson/NuclearTrains/assignees{/user}","branches_url":"https://api.github.com/repos/mattallinson/NuclearTrains/branches{/branch}","tags_url":"https://api.github.com/repos/mattallinson/NuclearTrains/tags","blobs_url":"https://api.github.com/repos/mattallinson/NuclearTrains/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mattallinson/NuclearTrains/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mattallinson/NuclearTrains/git/refs{/sha}","trees_url":"https://api.github.com/repos/mattallinson/NuclearTrains/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mattallinson/NuclearTrains/statuses/{sha}","languages_url":"https://api.github.com/repos/mattallinson/NuclearTrains/languages","stargazers_url":"https://api.github.com/repos/mattallinson/NuclearTrains/stargazers","contributors_url":"https://api.github.com/repos/mattallinson/NuclearTrains/contributors","subscribers_url":"https://api.github.com/repos/mattallinson/NuclearTrains/subscribers","subscription_url":"https://api.github.com/repos/mattallinson/NuclearTrains/subscription","commits_url":"https://api.github.com/repos/mattallinson/NuclearTrains/commits{/sha}","git_commits_url":"https://api.github.com/repos/mattallinson/NuclearTrains/git/commits{/sha}","comments_url":"https://api.github.com/repos/mattallinson/NuclearTrains/comments{/number}","issue_comment_url":"https://api.github.com/repos/mattallinson/NuclearTrains/issues/comments{/number}","contents_url":"https://api.github.com/repos/mattallinson/NuclearTrains/contents/{+path}","compare_url":"https://api.github.com/repos/mattallinson/NuclearTrains/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mattallinson/NuclearTrains/merges","archive_url":"https://api.github.com/repos/mattallinson/NuclearTrains/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mattallinson/NuclearTrains/downloads","issues_url":"https://api.github.com/repos/mattallinson/NuclearTrains/issues{/number}","pulls_url":"https://api.github.com/repos/mattallinson/NuclearTrains/pulls{/number}","milestones_url":"https://api.github.com/repos/mattallinson/NuclearTrains/milestones{/number}","notifications_url":"https://api.github.com/repos/mattallinson/NuclearTrains/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mattallinson/NuclearTrains/labels{/name}","releases_url":"https://api.github.com/repos/mattallinson/NuclearTrains/releases{/id}","deployments_url":"https://api.github.com/repos/mattallinson/NuclearTrains/deployments","created_at":"2016-04-15T15:17:51Z","updated_at":"2018-11-29T15:55:12Z","pushed_at":"2018-12-19T13:06:18Z","git_url":"git://github.com/mattallinson/NuclearTrains.git","ssh_url":"git@github.com:mattallinson/NuclearTrains.git","clone_url":"https://github.com/mattallinson/NuclearTrains.git","svn_url":"https://github.com/mattallinson/NuclearTrains","homepage":"https://nucleartrains.wordpress.com/","size":702,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":3,"license":{"key":"mit","name":"MIT License","spdx_id":"MIT","url":"https://api.github.com/licenses/mit","node_id":"MDc6TGljZW5zZTEz"},"forks":0,"open_issues":3,"watchers":0,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mattallinson/NuclearTrains/pulls/5"},"html":{"href":"https://github.com/mattallinson/NuclearTrains/pull/5"},"issue":{"href":"https://api.github.com/repos/mattallinson/NuclearTrains/issues/5"},"comments":{"href":"https://api.github.com/repos/mattallinson/NuclearTrains/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/mattallinson/NuclearTrains/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/mattallinson/NuclearTrains/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mattallinson/NuclearTrains/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/mattallinson/NuclearTrains/statuses/b216aa00dd4a4becaa4937109c851a47996dd59f"}},"author_association":"OWNER"}}
{"actor":{"display_login":"keirwl"}}