mongodb wrapper for managing News objects

This commit is contained in:
TrisNol
2023-06-16 18:50:19 +02:00
parent 5b96bb7e3e
commit 6e31bc62bd
7 changed files with 189 additions and 0 deletions

View File

@ -678,6 +678,99 @@
"custom_search_data = tagesschau.custom_search(\"Haltern am See\")\n",
"custom_search_data"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from utils.mongodb.mongo import MongoConnector\n",
"\n",
"connector = MongoConnector(\n",
" hostname=\"localhost\",\n",
" database=\"transparenzregister\",\n",
" username=\"root\",\n",
" password=\"pR0R0v2e2\",\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[News(id='id', title='title', date='date', text='text'),\n",
" News(id='abc', title='Hallo Welt', date='heute', text='what does the fox say')]"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from utils.mongodb.mongo import MongoNewsService\n",
"\n",
"service = MongoNewsService(connector)\n",
"service.get_all()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"{'id': 'abc', 'title': 'Hallo Welt', 'date': 'heute', 'text': 'what does the fox say'}\n"
]
},
{
"data": {
"text/plain": [
"<pymongo.results.InsertOneResult at 0x1bfd0773be0>"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from models.News import News\n",
"\n",
"service.insert(\n",
" News(\n",
" \"abc\", \"Hallo Welt\", \"heute\", \"what does the fox say\", \"https://localhost:8080\"\n",
" )\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"News(id='abc', title='Hallo Welt', date='heute', text='what does the fox say')"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"service.get_by_id(\"abc\")"
]
}
],
"metadata": {