diff --git a/db.ipynb b/db.ipynb index e9ec329..7fca144 100644 --- a/db.ipynb +++ b/db.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 15, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -16,14 +16,38 @@ "metadata": {}, "outputs": [], "source": [ - "firebase_admin.delete_app(firebase_admin.get_app())" + "#firebase_admin.delete_app(firebase_admin.get_app())" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, "outputs": [], + "source": [ + "from dotenv import load_dotenv\n", + "import os\n", + "load_dotenv()\n", + "DATABASE_URL = os.getenv('DATABASE_URL')\n", + "CREDS = os.getenv('CREDS')" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "cred = credentials.Certificate(\"key.json\")\n", "firebase_admin.initialize_app(cred, {\"databaseURL\": \"https://fantasy-contests-default-rtdb.firebaseio.com/\"})" @@ -31,46 +55,82 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 54, "metadata": {}, "outputs": [], "source": [ + "\n", "if not firebase_admin._apps:\n", + " cred = credentials.Certificate(CREDS)\n", " firebase_admin.initialize_app(cred, {\n", - " 'databaseURL': 'https://fantasy-contests-default-rtdb.firebaseio.com/'\n", + " 'databaseURL': DATABASE_URL\n", " })" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "firebase_admin.get_app()" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [] + }, { "cell_type": "code", - "execution_count": 33, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "ref = db.reference(\"/\")" + "ref.push(\"2023\")" ] }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 52, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "{'name': 'JJ'}" + "{'-Nijq-obWPuF13Udi6zl': {'Week_7': {'contest': 'vnake;jrhngf',\n", + " 'contest_results': [{'players': [{'game_played': 100,\n", + " 'name': 'Roquan Smith',\n", + " 'score': 7.4},\n", + " {'game_played': 100, 'name': \"Ja'Whaun Bentley\", 'score': 31.3}],\n", + " 'rank': 1,\n", + " 'team': 'Lets Get Weird 🐸',\n", + " 'total_score': 6999}]}}}" ] }, - "execution_count": 35, + "execution_count": 52, "metadata": {}, "output_type": "execute_result" } @@ -81,31 +141,107 @@ }, { "cell_type": "code", - "execution_count": 34, + "execution_count": 36, + "metadata": {}, + "outputs": [], + "source": [ + "ref = db.reference(\"/2022\")" + ] + }, + { + "cell_type": "code", + "execution_count": 38, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "'JJ'" + "{'-Nijq-obWPuF13Udi6zl': {'Week_7': {'contest': 'fdsafsd',\n", + " 'contest_results': [{'players': [{'game_played': 100,\n", + " 'name': 'Foyesade Oluokun',\n", + " 'score': 39.1},\n", + " {'game_played': 100, 'name': 'Ernest Jones', 'score': 6.7}],\n", + " 'rank': 1,\n", + " 'team': 'Lets Get Weird 🐸',\n", + " 'total_score': 45.800000000000004}]}}}" ] }, - "execution_count": 34, + "execution_count": 38, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "db.reference(\"/name\").get()" + "db.reference(\"/2022\").get()" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "ref.update({\n", + " \"Week_7\":\n", + " {\n", + " \"contest\": \"vnake;jrhngf\",\n", + " \"contest_results\": [\n", + " {\n", + " \"players\": [\n", + " {\n", + " \"game_played\": 100,\n", + " \"name\": \"Roquan Smith\",\n", + " \"score\": 7.4\n", + " },\n", + " {\n", + " \"game_played\": 100,\n", + " \"name\": \"Ja'Whaun Bentley\",\n", + " \"score\": 31.3\n", + " }\n", + " ],\n", + " \"rank\": 1,\n", + " \"team\": \"Lets Get Weird \\ud83d\\udc38\",\n", + " \"total_score\": 45.800000000000004\n", + " }\n", + " ]\n", + "}\n", + "})" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 51, "metadata": {}, "outputs": [], "source": [ - "db.reference(\"/name\").set('Justy')" + "\n", + "for key, value in ref.get().items():\n", + " if (value[\"Week_7\"]):\n", + "\n", + " ref.child(key).child(\"Week_7\").update(\n", + " {\n", + " \"contest\": \"vnake;jrhngf\",\n", + " \"contest_results\": [\n", + " {\n", + " \"players\": [\n", + " {\n", + " \"game_played\": 100,\n", + " \"name\": \"Roquan Smith\",\n", + " \"score\": 7.4\n", + " },\n", + " {\n", + " \"game_played\": 100,\n", + " \"name\": \"Ja'Whaun Bentley\",\n", + " \"score\": 31.3\n", + " }\n", + " ],\n", + " \"rank\": 1,\n", + " \"team\": \"Lets Get Weird \\ud83d\\udc38\",\n", + " \"total_score\": 6999\n", + " }\n", + " ]\n", + "}\n", + ")" ] } ], diff --git a/key.json b/key.json deleted file mode 100644 index 8b13789..0000000 --- a/key.json +++ /dev/null @@ -1 +0,0 @@ -