trying Events and hitting issues
parent
96f40cb3a4
commit
0aa1d95dda
235
Playground.ipynb
235
Playground.ipynb
|
@ -13,16 +13,14 @@
|
|||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "51b8b66e",
|
||||
"metadata": {
|
||||
"jp-MarkdownHeadingCollapsed": true
|
||||
},
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Adjust Log Level"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 8,
|
||||
"execution_count": 6,
|
||||
"id": "06d91db2",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
@ -42,7 +40,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"execution_count": 7,
|
||||
"id": "1394471a",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
@ -52,7 +50,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 10,
|
||||
"execution_count": 8,
|
||||
"id": "486a2537",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
|
@ -63,16 +61,14 @@
|
|||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "0311109c-869c-4190-97c1-a6e717a8eeba",
|
||||
"metadata": {
|
||||
"jp-MarkdownHeadingCollapsed": true
|
||||
},
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Who am I and what is my access_token"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 20,
|
||||
"execution_count": 9,
|
||||
"id": "e14e2be5-a5f9-4b8c-ae60-76c61cb61b8b",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
|
@ -82,7 +78,7 @@
|
|||
"'Mark Cotton - mcotton@mcottondesign.com'"
|
||||
]
|
||||
},
|
||||
"execution_count": 20,
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
|
@ -93,14 +89,9 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 21,
|
||||
"execution_count": 10,
|
||||
"id": "4ef47ae2-a010-4b7e-87f6-3dbf0a047e16",
|
||||
"metadata": {
|
||||
"collapsed": true,
|
||||
"jupyter": {
|
||||
"outputs_hidden": true
|
||||
}
|
||||
},
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
|
@ -108,7 +99,7 @@
|
|||
"'eyJraWQiOiI2ODYxYjBjYS0wZjI2LTExZWQtODYxZC0wMjQyYWMxMjAwMDIiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJjYWZlZGVmMiIsImF1ZCI6InZtcy5hcGkiLCJpc3MiOiJ2bXMuYXV0aC52MSIsInZtc19hY2NvdW50IjoiMDAwMjgyMDEiLCJleHAiOjE2ODYwMTQ0NjUsImlhdCI6MTY4NTQwOTY2NiwianRpIjoiNDBkMThmZTA0YTZlNWE5NDI0OWE4NmVjNmE5NDA0YzYiLCJjbGllbnRfaWQiOiJQUkVWSUVXLU1BUkstV0VCIiwidm1zX2NsdXN0ZXIiOiJjMDEyIn0.RAVxuQtnb9WSv4jp4hNqEyPaVzlpK6GqodFAUybzrnGiPR9tHE5OIanCZf2aX5IGAyOk9Kn5UYD4h96iIt8cpCXIyrFPKGE3WtspAxYNBwczjAWTuZQ6lOxH2eIeo3QjoTeOZaL8JEfCmc5-NyK4xaTrnb0nuhUnWzB4Vo9xtqzn2mupYUEyOvkgM0nOaTxPlrJLRNjNKDWKwMtuE2wo94HbjeOi8lSvQcMPvm07qvS1nFEaTjzpHCdwENcK6ghEUv5wzbUsDm5FYZFi29MyGLLiwv6csGD8lY0C3FFsG5EbMFzNAqS-v-CriPgA-3X9rpgLiWNIjSFG8vj7ZzCtsg'"
|
||||
]
|
||||
},
|
||||
"execution_count": 21,
|
||||
"execution_count": 10,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
|
@ -137,7 +128,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 14,
|
||||
"execution_count": 12,
|
||||
"id": "c43f1db1",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
|
@ -150,7 +141,7 @@
|
|||
" ✅ [1002584c] - Safe]"
|
||||
]
|
||||
},
|
||||
"execution_count": 14,
|
||||
"execution_count": 12,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
|
@ -161,7 +152,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 23,
|
||||
"execution_count": 13,
|
||||
"id": "ad33bf2a-ea36-4ec1-8335-8a44089f5f7e",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
|
@ -169,13 +160,13 @@
|
|||
"data": {
|
||||
"text/plain": [
|
||||
"[? [10090759] - Benny Camera,\n",
|
||||
" ? [1003e10b] - Driveway,\n",
|
||||
" ? [100ba388] - Front Door,\n",
|
||||
" ❌ [1003e10b] - Driveway,\n",
|
||||
" ❌ [100ba388] - Front Door,\n",
|
||||
" ? [100b7b3b] - Max Camera,\n",
|
||||
" ? [1009ae55] - Office]"
|
||||
" ❌ [1009ae55] - Office]"
|
||||
]
|
||||
},
|
||||
"execution_count": 23,
|
||||
"execution_count": 13,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
|
@ -186,7 +177,7 @@
|
|||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"execution_count": 14,
|
||||
"id": "f4c6fe67",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
|
@ -194,13 +185,13 @@
|
|||
"data": {
|
||||
"text/plain": [
|
||||
"[? [10090759] - Benny Camera,\n",
|
||||
" ? [1003e10b] - Driveway,\n",
|
||||
" ? [100ba388] - Front Door,\n",
|
||||
" ❌ [1003e10b] - Driveway,\n",
|
||||
" ❌ [100ba388] - Front Door,\n",
|
||||
" ? [100b7b3b] - Max Camera,\n",
|
||||
" ? [1009ae55] - Office]"
|
||||
" ❌ [1009ae55] - Office]"
|
||||
]
|
||||
},
|
||||
"execution_count": 15,
|
||||
"execution_count": 14,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
|
@ -216,6 +207,188 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "295b9ef8-df88-447e-b787-0098b4778f6a",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## User timezone fun"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 15,
|
||||
"id": "ef1ea137-d9fb-4f6f-b241-fb019c8e3230",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from datetime import datetime, timedelta\n",
|
||||
"from pytz import timezone"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 16,
|
||||
"id": "0841aef0-89c1-45ac-b501-a9196f481d49",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"tz = timezone(een.current_user['timeZone']['timeZone'])\n",
|
||||
"now = datetime.now(tz=tz)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 17,
|
||||
"id": "ae53f810-cb77-48e3-b148-72ef7038bb89",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'2023-05-30T21:39:54.210-05:00'"
|
||||
]
|
||||
},
|
||||
"execution_count": 17,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"now.isoformat(timespec='milliseconds')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 18,
|
||||
"id": "4d708ccb-80b1-4d88-aa2e-d93a71cbdc04",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"'2023-05-30T15:39:55.646-05:00'"
|
||||
]
|
||||
},
|
||||
"execution_count": 18,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"(datetime.now(tz=tz) - timedelta(hours=6)).isoformat(timespec='milliseconds')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f4d8c154-400a-4af9-b677-29190b588408",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Event Subscription"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 29,
|
||||
"id": "a9d81b0d-72e6-4404-b30e-3a341a9e6639",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"{\"id\":\"e572b7c7-f5de-4994-b4e5-f301af23213c\",\"subscriptionConfig\":{\"lifeCycle\":\"temporary\",\"timeToLiveSeconds\":900},\"deliveryConfig\":{\"type\":\"serverSentEvents.v1\",\"sseUrl\":\"https://api.c012.eagleeyenetworks.com/api/v3.0/sse/eventSubscriptions/e572b7c7-f5de-4994-b4e5-f301af23213c\"}}\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"import requests\n",
|
||||
"\n",
|
||||
"url = \"https://api.c012.eagleeyenetworks.com/api/v3.0/eventSubscriptions\"\n",
|
||||
"\n",
|
||||
"payload = {\n",
|
||||
" \"deliveryConfig\": {\"type\": \"serverSentEvents.v1\"},\n",
|
||||
" \"filters\": [\n",
|
||||
" {\n",
|
||||
" \"actors\": [\"camera:1001423e\", \"camera:100d8666\"],\n",
|
||||
" \"types\": [{\"id\": \"een.motionDetectionEvent.v1\"}]\n",
|
||||
" }\n",
|
||||
" ]\n",
|
||||
"}\n",
|
||||
"headers = {\n",
|
||||
" \"accept\": \"application/json\",\n",
|
||||
" \"content-type\": \"application/json\",\n",
|
||||
" \"authorization\": \"Bearer eyJraWQiOiI2ODYxYjBjYS0wZjI2LTExZWQtODYxZC0wMjQyYWMxMjAwMDIiLCJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJjYWZlZGVmMiIsImF1ZCI6InZtcy5hcGkiLCJpc3MiOiJ2bXMuYXV0aC52MSIsInZtc19hY2NvdW50IjoiMDAwMjgyMDEiLCJleHAiOjE2ODU5OTY0NTksImlhdCI6MTY4NTM5MTY1OSwianRpIjoiM2NjZjcyNDEwMjNjYWVlNjZkMjFlODRlODE2MTU4MDciLCJjbGllbnRfaWQiOiJQUkVWSUVXLU1BUkstV0VCIiwidm1zX2NsdXN0ZXIiOiJjMDEyIn0.hgNkbGkzG0C-CG9lxgpOX_c__uI9s4BextwKIWgCwHyFhin7jftW7gVvb_xyisjD7YxxZyvBRRJ8cQ6enH37RaS5orLjKUj81qUi7RrlhApHLOSV_lyFSSkyXd-QzV9iDI2_0DRN1VviIZrC0t783Cdyz1deKG3kvDhWIUGLUvmJNLmpgIkYmmQkGgWvo80Snqm11TKMORNG779pDvA7C5l__fZDEbCjYh5yhkEmOcQAekYCBichO70w4frNiYP_hOLuBGUs3yvtglNo5QAp5fdhYfgjv-zmzyE1fjZcLo22rNPb3_I8SGpEJWEe0JLtxCrEf-YaCQccD4YBh_RE9Q\"\n",
|
||||
"}\n",
|
||||
"\n",
|
||||
"response = requests.post(url, json=payload, headers=headers)\n",
|
||||
"\n",
|
||||
"print(response.text)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 30,
|
||||
"id": "53d3bff7-848f-4669-ab66-57597313fa0d",
|
||||
"metadata": {
|
||||
"scrolled": true
|
||||
},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"#pip install sseclient\n",
|
||||
"from sseclient import SSEClient\n",
|
||||
"\n",
|
||||
"messages = SSEClient(response.json()['deliveryConfig']['sseUrl'], headers=headers)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 33,
|
||||
"id": "91cfe32d-db80-40fb-8ea9-d60f8a647b0d",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"<Response [200]>"
|
||||
]
|
||||
},
|
||||
"execution_count": 33,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"messages.resp"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "2016a9cf-9ce8-48af-8e3f-c058024c544e",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stdout",
|
||||
"output_type": "stream",
|
||||
"text": [
|
||||
"\n"
|
||||
]
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"for msg in messages:\n",
|
||||
" print(msg)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": null,
|
||||
"id": "bf23672e-f808-442f-8393-3c0e1f84c984",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": []
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
|
|
Loading…
Reference in New Issue