Spaces:
Configuration error
Configuration error
Create database.py
Browse files- database.py +55 -0
database.py
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pymongo import MongoClient
|
| 2 |
+
import requests
|
| 3 |
+
|
| 4 |
+
import os
|
| 5 |
+
from pymongo import MongoClient
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
MONGO_URI = os.getenv('MONGO_URI', 'mongodb://localhost:27017')
|
| 9 |
+
REFERENCE_DB = os.getenv('REFERENCE_DB', 'EgitimDatabase')
|
| 10 |
+
INPUT_DB = os.getenv('INPUT_DB', 'InputDatabase')
|
| 11 |
+
|
| 12 |
+
def connect_to_mongodb():
|
| 13 |
+
"""MongoDB'ye bağlan."""
|
| 14 |
+
client = MongoClient(MONGO_URI)
|
| 15 |
+
return client
|
| 16 |
+
|
| 17 |
+
def get_reference_data():
|
| 18 |
+
"""Reference database'den verileri al."""
|
| 19 |
+
client = connect_to_mongodb()
|
| 20 |
+
db = client[REFERENCE_DB]
|
| 21 |
+
collection = db['test'] # Kendi koleksiyon isminizi buraya yazın
|
| 22 |
+
data = collection.find()
|
| 23 |
+
return list(data)
|
| 24 |
+
|
| 25 |
+
def insert_data_into_input_db(data):
|
| 26 |
+
"""Input database'e veri ekle."""
|
| 27 |
+
client = connect_to_mongodb()
|
| 28 |
+
db = client[INPUT_DB]
|
| 29 |
+
collection = db['input'] # Kendi koleksiyon isminizi buraya yazın
|
| 30 |
+
collection.insert_many(data)
|
| 31 |
+
|
| 32 |
+
def get_user_input():
|
| 33 |
+
"""Kullanıcıdan veri al."""
|
| 34 |
+
#yöntemi eklemem gerek
|
| 35 |
+
user_input = [
|
| 36 |
+
{"title": "Sample Title", "keywords": ["keyword1", "keyword2","keyword3","keyword4","keyword5"], "text": "Sample text."}
|
| 37 |
+
|
| 38 |
+
]
|
| 39 |
+
return user_input
|
| 40 |
+
|
| 41 |
+
def main():
|
| 42 |
+
"""Ana fonksiyon."""
|
| 43 |
+
client = connect_to_mongodb()
|
| 44 |
+
|
| 45 |
+
reference_data = get_reference_data()
|
| 46 |
+
user_data = get_user_input()
|
| 47 |
+
|
| 48 |
+
insert_data_into_input_db(user_data)
|
| 49 |
+
|
| 50 |
+
client.close()
|
| 51 |
+
|
| 52 |
+
if __name__ == "__main__":
|
| 53 |
+
main()
|
| 54 |
+
|
| 55 |
+
|