Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions #Neuro-Tech Software 2022 - 2023.py
Original file line number Diff line number Diff line change
@@ -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














53 changes: 53 additions & 0 deletions export.py
Original file line number Diff line number Diff line change
@@ -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()
Empty file added frontend/src/data.csv
Empty file.
26 changes: 24 additions & 2 deletions frontend/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({})
Expand Down