diff --git a/#Neuro-Tech Software 2022 - 2023.py b/#Neuro-Tech Software 2022 - 2023.py new file mode 100644 index 0000000..ab1bb12 --- /dev/null +++ b/#Neuro-Tech Software 2022 - 2023.py @@ -0,0 +1,32 @@ +#Neuro-Tech Software 2022 - 2023 +import pymongo +import csv + +#Connecting to the MongoDB +client = pymongo.MongoClient('mongodb://localhost:27017/') + +db = client['mydatabase'] +collection = db['mycollection'] +documents = collection.find() + +with open('mycollection.csv', 'w', newline='') as f: + writer = csv.writer(f) + writer.writerow(['_id', 'field1', 'field2']) + # I need to replace 'field1', 'field2' with the names of the fields in the documents from the data + for document in documents: + writer.writerow([document['_id'], document['field1'], document['field2']]) + # Again I need to replace 'field1', 'field2' with the names of the fields in the documents from the data + + + + + + + + + + + + + + diff --git a/export.py b/export.py new file mode 100644 index 0000000..1090875 --- /dev/null +++ b/export.py @@ -0,0 +1,53 @@ +from collections.abc import Callable, Iterable, Mapping +import tkinter as tk +import threading +import pymongo +import csv + +class SubvocalPhonemeGUI(threading.Thread): + def __init__(self, threadID): + threading.Thread.__init__(self) + self.threadID = threadID + + #Creating the main window of the application + self.root = tk.Tk() + + #Setting up GUI elements + self.label = tk.Label(self.root, text="Hello, World!", font=('Arial', 18)) + self.label.pack() + + self.button = tk.Button(self.root, text="Click", command=lambda: self.export_data()) + self.button.pack() + + self.button = tk.Button(self.root, text="Export Data", command=self.export_data) + self.button.pack() + + #Connecting to the MongoDB + self.client = pymongo.MongoClient("mongodb://localhost:27017/") + self.db = self.client["subvocal_database"] + self.collection = self.db["subvocal_collection"] + + def export_data(self): + self.status_label.config(text="Exporting Data...") + + #Query the data from the MongoDB + #Limiting the data amount 50 lines + data = self.collection.find({}).limit(50) + + #Write the data to a CSV file + with open('data_export.csv', 'w') as f: + csvwriter = csv.writer(f, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) + #write each row of data + for item in data: + csvwriter.writerow([item['name'], item['_id']]) + #return send_file('data.csv', as_attachment=True) + + self.status_label.config(text="Data Exported Successfully") + + def run(self): + self.root.mainloop() + +if __name__ == '__main__': + gui = SubvocalPhonemeGUI(1) + gui.start() + gui.join() diff --git a/frontend/src/data.csv b/frontend/src/data.csv new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/main.py b/frontend/src/main.py index b852013..56c1166 100644 --- a/frontend/src/main.py +++ b/frontend/src/main.py @@ -2,19 +2,41 @@ import requests import pymongo from pymongo import MongoClient +from io import BytesIO +from flask import Flask, send_file +#import requests +#import pymongo +#from pymongo import MongoClient +import csv app = Flask(__name__) client = MongoClient('mongodb://root:example@mongo:27017') +db = client['mydatabase'] +collection = db['mycollection'] @app.route('/') def hello_world(): return 'Hello Flafdsdk!!d' +@app.route('/export') +def export_data(): + # Grabbing the data from MongoDB + data = collection.find({}) + #Writing to a CSV File + with open("data.csv", "w") as f: + csvwriter = csv.writer(f, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) + for item in data: + print(item) + csvwriter.writerow([item['name'], item['_id']]) + #Close CSV file to user + return send_file('data.csv', as_attachment=True) + + if __name__ == '__main__': print(client.list_database_names()) print("\n\n\n") - db = client["testdb"] - coll = db["testcoll"] + db = client["mydatabase"] + coll = db["mycollection"] post1 = {"name": "hello"} coll.insert_one(post1) results = coll.find({})