added functino to get content from database

This commit is contained in:
simplypower-bbj
2022-12-18 11:04:19 +01:00
parent 7f2268605a
commit 1dd12c894a
2 changed files with 51 additions and 1 deletions
+44
View File
@@ -37,6 +37,50 @@
" dt.insert(val_dict)" " 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 Danimarkanı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", "cell_type": "code",
"execution_count": null, "execution_count": null,
+6
View File
@@ -170,3 +170,9 @@ def insert_list(username_list, timestamp_list, content_list):
dt.insert(val_dict) dt.insert(val_dict)
except Exception as e: except Exception as e:
logging.warning(e) 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']