Spaces:
Runtime error
Runtime error
Commit ·
13772a2
1
Parent(s): c23bcbe
Update space
Browse files- .gitignore +8 -0
- history.py +26 -0
- mongo_client.py +15 -0
.gitignore
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
backup1.txt
|
| 3 |
+
backup2.txt
|
| 4 |
+
backup3.txt
|
| 5 |
+
backup4.txt
|
| 6 |
+
backup5.txt
|
| 7 |
+
backup6.txt
|
| 8 |
+
backup7.txt
|
history.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from mongo_client import get_client, get_collection
|
| 2 |
+
|
| 3 |
+
client=get_client()
|
| 4 |
+
collection=get_collection("history",client)
|
| 5 |
+
|
| 6 |
+
def get_history(group_name:str):
|
| 7 |
+
history= collection.find_one({"group_name":group_name})
|
| 8 |
+
|
| 9 |
+
value=[]
|
| 10 |
+
|
| 11 |
+
if history and 'value' in history:
|
| 12 |
+
value=history['value']
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
return value
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def update_history(group_name:str,value):
|
| 19 |
+
query_filter = {"group_name":group_name}
|
| 20 |
+
|
| 21 |
+
update_operation = { "$set" :{ "value" : value }}
|
| 22 |
+
|
| 23 |
+
collection.update_one(query_filter, update_operation, upsert=True)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
return True
|
mongo_client.py
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pymongo import MongoClient, server_api
|
| 2 |
+
|
| 3 |
+
from os import getenv
|
| 4 |
+
|
| 5 |
+
database_name=getenv("DATABASE_NAME")
|
| 6 |
+
|
| 7 |
+
def get_client():
|
| 8 |
+
client = MongoClient(getenv("MONGODB_CONNECTION_STRING"), server_api=server_api.ServerApi(
|
| 9 |
+
version="1", strict=True, deprecation_errors=True))
|
| 10 |
+
|
| 11 |
+
return client
|
| 12 |
+
|
| 13 |
+
def get_collection(collection_name:str,client:MongoClient):
|
| 14 |
+
database=client[database_name]
|
| 15 |
+
return database[collection_name]
|