Skip to content

Commit

Permalink
delete key
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-hsieh committed Nov 9, 2023
1 parent 65d203f commit 8d92079
Show file tree
Hide file tree
Showing 2 changed files with 155 additions and 20 deletions.
174 changes: 155 additions & 19 deletions db.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -16,61 +16,121 @@
"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": [
"<firebase_admin.App at 0x28feac8f100>"
]
},
"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/\"})"
]
},
{
"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": [
"<firebase_admin.App at 0x28feac8f100>"
]
},
"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": [
"<firebase_admin.db.Reference at 0x28feacfdc10>"
]
},
"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"
}
Expand All @@ -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",
")"
]
}
],
Expand Down
1 change: 0 additions & 1 deletion key.json

This file was deleted.

0 comments on commit 8d92079

Please sign in to comment.