From 1dd12c894a51d7a964ec463e78156d118ac2d894 Mon Sep 17 00:00:00 2001 From: simplypower-bbj Date: Sun, 18 Dec 2022 11:04:19 +0100 Subject: [PATCH] added functino to get content from database --- code/database.ipynb | 44 ++++++++++++++++++++++++++++++++++++++++++++ code/database.py | 8 +++++++- 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/code/database.ipynb b/code/database.ipynb index ee2be67..9260035 100644 --- a/code/database.ipynb +++ b/code/database.ipynb @@ -37,6 +37,50 @@ " dt.insert(val_dict)" ] }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "0 Odense Universitets Hospital søger #Afdelingsc...\n", + "1 \"Odense Dänemark, Seaside\" Fotografie als Post...\n", + "2 Danimarka’nın Odense takımı bu yaz müthiş bir ...\n", + "3 Highlights: SønderjyskE – Odense https://t.co/...\n", + "4 “Meta Platforms Inc has halted construction of...\n", + " ... \n", + "1810 Kunne du tænke dig at være med til at begejstr...\n", + "1811 UDEBANEAFSNITTET UDVIDES TIL 1800 PLADSER! \\n\\...\n", + "1812 Der er lagt op til fynsk fodboldfest på søndag...\n", + "1813 Jeg har i stigende omfang den oplevelse, at @A...\n", + "1814 PhD position podning in Odense, Denmark: Impro...\n", + "Name: content, Length: 1815, dtype: object" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from database import get_content\n", + "\n", + "df = get_content()\n", + "\n", + "df" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "df.to_csv('~/Desktop/content.csv')" + ] + }, { "cell_type": "code", "execution_count": null, diff --git a/code/database.py b/code/database.py index d09901b..07695da 100644 --- a/code/database.py +++ b/code/database.py @@ -169,4 +169,10 @@ def insert_list(username_list, timestamp_list, content_list): } dt.insert(val_dict) except Exception as e: - logging.warning(e) \ No newline at end of file + logging.warning(e) + +def get_content(): + with Data_table() as dt: + query = f'SELECT * FROM {dt._name} ORDER BY time DESC ' + df = pd.read_sql_query(query, dt.con) + return df['content'] \ No newline at end of file