diff --git a/playground.ipynb b/playground.ipynb index 7082da3..5693fef 100644 --- a/playground.ipynb +++ b/playground.ipynb @@ -16,6 +16,18 @@ "## Let's do some EagleEye setup" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "8f557a22-7ffe-4c0d-910d-9dee63b40832", + "metadata": {}, + "outputs": [], + "source": [ + "import logging\n", + "logger = logging.getLogger()\n", + "logger.setLevel('INFO')" + ] + }, { "cell_type": "code", "execution_count": null, @@ -37,6 +49,16 @@ "een = EagleEyev3(config)" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "23864933-181c-402e-b2f5-e47a9f1871c8", + "metadata": {}, + "outputs": [], + "source": [ + "een.__version__" + ] + }, { "cell_type": "markdown", "id": "2aaf14a9-f206-4909-a85f-fc736e964592", @@ -90,7 +112,9 @@ "metadata": {}, "outputs": [], "source": [ - "refresh_token = ''" + "if een.refresh_token == None or een.refresh_token == '':\n", + " # if you get out of sync you manually copy a refresh_token here to get the loop started\n", + " een.refresh_token = ''" ] }, { @@ -100,7 +124,27 @@ "metadata": {}, "outputs": [], "source": [ - "een.login_tokens(code=None, cascade=True, refresh_token=refresh_token)" + "een.login_tokens(code=None, cascade=True, refresh_token=een.refresh_token)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d1405ab3-81d9-4add-8876-d5396c81a3ac", + "metadata": {}, + "outputs": [], + "source": [ + "een.refresh_token" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "79badad1-2ad1-4029-adba-c0ab7abf4a3e", + "metadata": {}, + "outputs": [], + "source": [ + "een.get_base_url()" ] }, { @@ -110,16 +154,50 @@ "metadata": {}, "outputs": [], "source": [ - "een.get_list_of_cameras()" + "_ = een.get_list_of_cameras()" ] }, { "cell_type": "code", "execution_count": null, - "id": "10fbd562-919c-4946-bb63-a1531a919920", + "id": "e85f28ee-165d-442b-896e-05d74e29e644", "metadata": {}, "outputs": [], - "source": [] + "source": [ + "een.cameras" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "17806b22-5bad-497d-977d-b1c31ed48304", + "metadata": {}, + "outputs": [], + "source": [ + "r2d2 = een.cameras[3]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a6dc31ee-6041-44f7-8967-67856033a6a7", + "metadata": { + "scrolled": true + }, + "outputs": [], + "source": [ + "r2d2.get_list_of_videos(start_timestamp=een.time_before(hours=24*14), end_timestamp=een.time_now())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3395164b-307d-473e-a090-fd782d0c1dc1", + "metadata": {}, + "outputs": [], + "source": [ + "len(r2d2.videos)" + ] }, { "cell_type": "markdown", @@ -137,7 +215,7 @@ "outputs": [], "source": [ "for row in cur.execute('SELECT * FROM download WHERE camera_id = 53 limit 10'):\n", - " print( row[0] )" + " pass" ] }, { @@ -147,7 +225,7 @@ "metadata": {}, "outputs": [], "source": [ - "\"\"\"\n", + "sql = \"\"\"\n", "SELECT\n", "\tuser.email,\n", "\tcamera.name,\n", @@ -167,12 +245,113 @@ "\"\"\"" ] }, + { + "cell_type": "markdown", + "id": "e4a34474-3282-45cb-97fc-bedd0c0258f0", + "metadata": {}, + "source": [ + "## Try downloading a video ##" + ] + }, { "cell_type": "code", "execution_count": null, - "id": "4ae3e95f-845a-4e3e-b0f8-24a4edf56b95", + "id": "3f5c62fd-e21d-4b5e-afa1-d63741cc10a2", "metadata": {}, "outputs": [], + "source": [ + "r2d2.videos[9]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8c5160f0-52aa-4790-8b80-9e7edd528148", + "metadata": {}, + "outputs": [], + "source": [ + "import requests" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "f81a8dd8-9190-4709-8a94-276552cbdd5f", + "metadata": {}, + "outputs": [], + "source": [ + "#req = requests.get(url=benny.videos[9]['mp4Url'], headers={\"Authorization\": f\"Bearer {een.access_token}\"})" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "854e94f9-5341-4e09-adfe-c704014dd6a6", + "metadata": {}, + "outputs": [], + "source": [ + "#req.headers" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "aebe701f-2e83-497d-aa1e-ed2ba26ea4d4", + "metadata": {}, + "outputs": [], + "source": [ + "#benny.save_video_to_file(url=benny.videos[9]['mp4Url'], filename='benny9.mp4')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "74378ae5-0ade-4d8a-9636-2bd2800e59a3", + "metadata": {}, + "outputs": [], + "source": [ + "sql = '''SELECT\n", + "\tdownload.id,\n", + "\tdownload.url,\n", + " camera.device_id,\n", + "\tdownload.start_timestamp,\n", + " download.end_timestamp\n", + "FROM\n", + "\tcamera\n", + "\tJOIN download ON download.camera_id = camera.id\n", + "\tJOIN USER ON camera.user_id = user.id\n", + "WHERE\n", + "\tdownload.status == 'new' \n", + "\tand camera.id == 4;'''" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0aac543d-e9f0-4a10-b4c2-35466085f2c2", + "metadata": {}, + "outputs": [], + "source": [ + "from tqdm import tqdm\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8b61db76-e925-4ccb-bead-39239615daae", + "metadata": {}, + "outputs": [], + "source": [ + "for row in tqdm(cur.execute(sql)):\n", + " fname = f\"videos/{row[2]}/{row[2]}_{row[3]}-{row[4]}.mp4\"\n", + " #print(fname)\n", + " r2d2.save_video_to_file(url=row[1], filename=fname)" + ] + }, + { + "cell_type": "raw", + "id": "4f728219-12e2-4b60-b0af-0320efec95fb", + "metadata": {}, "source": [] } ],