Skip to content

Commit

Permalink
Small Corrections added referer url and used new Vessel Image
Browse files Browse the repository at this point in the history
  • Loading branch information
reyemb committed Dec 19, 2023
1 parent 1ac63c8 commit 89296f7
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 203 deletions.
21 changes: 5 additions & 16 deletions aisexplorer/AIS.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,6 @@
from tenacity import retry, stop_after_attempt, wait_fixed


def renew_proxy_and_retry(retry_state):
"""Renew the proxy and print a retry message.
Args:
retry_state (tenacity.RetryCallState): The current state of the retry logic.
"""
obj = retry_state.args[0]
obj.check_proxy()


def raise_no_results_error(retry_state):
"""Raise a NoResultsError after a certain number of attempts.
Expand Down Expand Up @@ -67,7 +57,6 @@ class AIS:
retry_options = {
"stop": stop_after_attempt(10),
"wait": wait_fixed(15),
"after": renew_proxy_and_retry,
"retry_error_callback": raise_no_results_error,
}

Expand Down Expand Up @@ -112,7 +101,7 @@ def configure_session(self, proxy, verbose, proxy_config):
self.session.headers.update(
{
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
"Vessel-Image": "001b6192a3cc77daab750f70cab85f527b18",
"Vessel-Image": "00b3ac45291acfd4e2e0dc4e46b24ec56c05",
}
)
if proxy:
Expand Down Expand Up @@ -225,7 +214,7 @@ def get_fleets(self):
"https://www.marinetraffic.com/en/search/fleetList",
headers={
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
"vessel-image": "001b6192a3cc77daab750f70cab85f527b18",
"vessel-image": "00b3ac45291acfd4e2e0dc4e46b24ec56c05",
"x-requested-with": "XMLHttpRequest",
},
)
Expand Down Expand Up @@ -611,9 +600,9 @@ def return_response(self, request_url, referer_url):
response = self.session.get(
request_url,
headers={
# "Referer": referer_url,
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36",
"vessel-image": "005bf958a6548a79c6d3a42eba493e339624",
"Referer": referer_url,
"user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36",
"vessel-image": "0026501dd5e7cae9b8afd72aa41a3f831929",
"x-requested-with": "XMLHttpRequest",
},
)
Expand Down
119 changes: 20 additions & 99 deletions examples/Short_Example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,98 +47,19 @@
},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>SHIP_ID</th>\n",
" <th>IMO</th>\n",
" <th>MMSI</th>\n",
" <th>CALLSIGN</th>\n",
" <th>SHIPNAME</th>\n",
" <th>TYPE_COLOR</th>\n",
" <th>LAST_POS</th>\n",
" <th>TIMEZONE</th>\n",
" <th>CODE2</th>\n",
" <th>COUNTRY</th>\n",
" <th>...</th>\n",
" <th>LENGTH</th>\n",
" <th>WIDTH</th>\n",
" <th>STATUS</th>\n",
" <th>ETA_UPDATED</th>\n",
" <th>DISTANCE_TO_GO</th>\n",
" <th>AREA_NAME</th>\n",
" <th>PORT_ID</th>\n",
" <th>CURRENT_PORT</th>\n",
" <th>COLLECTION_NAME</th>\n",
" <th>CTA_ROUTE_FORECAST</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>460780</td>\n",
" <td>7302225</td>\n",
" <td>211281610</td>\n",
" <td>DBUI</td>\n",
" <td>SEA WATCH 3</td>\n",
" <td>3</td>\n",
" <td>1683190098</td>\n",
" <td>2</td>\n",
" <td>DE</td>\n",
" <td>Germany</td>\n",
" <td>...</td>\n",
" <td>50.3</td>\n",
" <td>11.6</td>\n",
" <td>ACTIVE</td>\n",
" <td>None</td>\n",
" <td>0</td>\n",
" <td>Antwerp Area</td>\n",
" <td>122</td>\n",
" <td>GHENT</td>\n",
" <td>-</td>\n",
" <td>false</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"<p>1 rows × 40 columns</p>\n",
"</div>"
],
"text/plain": [
" SHIP_ID IMO MMSI CALLSIGN SHIPNAME TYPE_COLOR LAST_POS \\\n",
"0 460780 7302225 211281610 DBUI SEA WATCH 3 3 1683190098 \n",
"\n",
" TIMEZONE CODE2 COUNTRY ... LENGTH WIDTH STATUS ETA_UPDATED \\\n",
"0 2 DE Germany ... 50.3 11.6 ACTIVE None \n",
"\n",
" DISTANCE_TO_GO AREA_NAME PORT_ID CURRENT_PORT COLLECTION_NAME \\\n",
"0 0 Antwerp Area 122 GHENT - \n",
"\n",
" CTA_ROUTE_FORECAST \n",
"0 false \n",
"\n",
"[1 rows x 40 columns]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
"ename": "NoResultsError",
"evalue": "After 10 attempts still no results are given. If you think this is an error in the module raise an issue at https://github.com/reyemb/AISExplorer ",
"output_type": "error",
"traceback": [
"\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[1;31mNoResultsError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[1;32mIn[2], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[43mAIS\u001b[49m\u001b[43m(\u001b[49m\u001b[43mreturn_df\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_location\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m211281610\u001b[39;49m\u001b[43m)\u001b[49m\n",
"File \u001b[1;32mc:\\Users\\Meyer\\OneDrive\\Desktop\\Projekte\\aisexplorer\\AISExplorer\\.venv\\Lib\\site-packages\\tenacity\\__init__.py:289\u001b[0m, in \u001b[0;36mBaseRetrying.wraps.<locals>.wrapped_f\u001b[1;34m(*args, **kw)\u001b[0m\n\u001b[0;32m 287\u001b[0m \u001b[38;5;129m@functools\u001b[39m\u001b[38;5;241m.\u001b[39mwraps(f)\n\u001b[0;32m 288\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mwrapped_f\u001b[39m(\u001b[38;5;241m*\u001b[39margs: t\u001b[38;5;241m.\u001b[39mAny, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkw: t\u001b[38;5;241m.\u001b[39mAny) \u001b[38;5;241m-\u001b[39m\u001b[38;5;241m>\u001b[39m t\u001b[38;5;241m.\u001b[39mAny:\n\u001b[1;32m--> 289\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mf\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkw\u001b[49m\u001b[43m)\u001b[49m\n",
"File \u001b[1;32mc:\\Users\\Meyer\\OneDrive\\Desktop\\Projekte\\aisexplorer\\AISExplorer\\.venv\\Lib\\site-packages\\tenacity\\__init__.py:379\u001b[0m, in \u001b[0;36mRetrying.__call__\u001b[1;34m(self, fn, *args, **kwargs)\u001b[0m\n\u001b[0;32m 377\u001b[0m retry_state \u001b[38;5;241m=\u001b[39m RetryCallState(retry_object\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mself\u001b[39m, fn\u001b[38;5;241m=\u001b[39mfn, args\u001b[38;5;241m=\u001b[39margs, kwargs\u001b[38;5;241m=\u001b[39mkwargs)\n\u001b[0;32m 378\u001b[0m \u001b[38;5;28;01mwhile\u001b[39;00m \u001b[38;5;28;01mTrue\u001b[39;00m:\n\u001b[1;32m--> 379\u001b[0m do \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43miter\u001b[49m\u001b[43m(\u001b[49m\u001b[43mretry_state\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mretry_state\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 380\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(do, DoAttempt):\n\u001b[0;32m 381\u001b[0m \u001b[38;5;28;01mtry\u001b[39;00m:\n",
"File \u001b[1;32mc:\\Users\\Meyer\\OneDrive\\Desktop\\Projekte\\aisexplorer\\AISExplorer\\.venv\\Lib\\site-packages\\tenacity\\__init__.py:322\u001b[0m, in \u001b[0;36mBaseRetrying.iter\u001b[1;34m(self, retry_state)\u001b[0m\n\u001b[0;32m 320\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mstop(retry_state):\n\u001b[0;32m 321\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mretry_error_callback:\n\u001b[1;32m--> 322\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mretry_error_callback\u001b[49m\u001b[43m(\u001b[49m\u001b[43mretry_state\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 323\u001b[0m retry_exc \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mretry_error_cls(fut)\n\u001b[0;32m 324\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mreraise:\n",
"File \u001b[1;32m~\\OneDrive\\Desktop\\Projekte\\AISExplorer\\AISExplorer\\aisexplorer\\AIS.py:48\u001b[0m, in \u001b[0;36mraise_no_results_error\u001b[1;34m(retry_state)\u001b[0m\n\u001b[0;32m 42\u001b[0m attempt_num \u001b[38;5;241m=\u001b[39m retry_state\u001b[38;5;241m.\u001b[39mattempt_number\n\u001b[0;32m 43\u001b[0m error_message \u001b[38;5;241m=\u001b[39m (\n\u001b[0;32m 44\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAfter \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mattempt_num\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m attempts still no results are given. \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 45\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mIf you think this is an error in the module raise an issue at \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 46\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhttps://github.com/reyemb/AISExplorer \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 47\u001b[0m )\n\u001b[1;32m---> 48\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m NoResultsError(error_message)\n",
"\u001b[1;31mNoResultsError\u001b[0m: After 10 attempts still no results are given. If you think this is an error in the module raise an issue at https://github.com/reyemb/AISExplorer "
]
}
],
"source": [
Expand All @@ -158,7 +79,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": null,
"id": "84191eff-f2db-441a-a734-ad886ec0e2ea",
"metadata": {
"pycharm": {
Expand All @@ -172,7 +93,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": null,
"id": "1c23210f-c346-442f-9401-1b08eeba19f7",
"metadata": {
"pycharm": {
Expand Down Expand Up @@ -573,7 +494,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": null,
"metadata": {
"collapsed": false,
"pycharm": {
Expand Down Expand Up @@ -613,7 +534,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": null,
"metadata": {
"collapsed": false,
"pycharm": {
Expand Down Expand Up @@ -654,7 +575,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {
"collapsed": false,
"pycharm": {
Expand Down Expand Up @@ -698,7 +619,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": null,
"metadata": {
"collapsed": false,
"pycharm": {
Expand Down Expand Up @@ -1120,7 +1041,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
"version": "3.12.1"
},
"vscode": {
"interpreter": {
Expand Down
Loading

0 comments on commit 89296f7

Please sign in to comment.