delete files
This commit is contained in:
@@ -1,66 +0,0 @@
|
||||
from src.backend.database import Database
|
||||
from src.logic.webrequest import BibTextTransformer, WebRequest
|
||||
import sqlite3
|
||||
|
||||
class BookGrabber:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
mode: str = None,
|
||||
data: list = None,
|
||||
app_id: int = None,
|
||||
prof_id: int = None,
|
||||
):
|
||||
self.app_id = app_id
|
||||
self.prof_id = prof_id
|
||||
self.mode = mode
|
||||
self.data = data
|
||||
self.book_id = None
|
||||
|
||||
def run(self):
|
||||
self.db = Database()
|
||||
item = 0
|
||||
for entry in self.data:
|
||||
signature = str(entry)
|
||||
self.logger.log_info("Processing entry: " + signature)
|
||||
|
||||
webdata = WebRequest().get_ppn(entry).get_data()
|
||||
if webdata == "error":
|
||||
continue
|
||||
bd = BibTextTransformer(self.mode).get_data(webdata).return_data()
|
||||
transformer = BibTextTransformer("RDS")
|
||||
rds = transformer.get_data(webdata).return_data("rds_availability")
|
||||
bd.signature = entry
|
||||
# confirm lock is acquired
|
||||
print("lock acquired, adding book to database")
|
||||
self.db.addBookToDatabase(bd, self.app_id, self.prof_id)
|
||||
# get latest book id
|
||||
self.book_id = self.db.getLastBookId()
|
||||
self.logger.log_info("Added book to database")
|
||||
state = 0
|
||||
for rds_item in rds.items:
|
||||
sign = rds_item.superlocation
|
||||
loc = rds_item.location
|
||||
# print(item.location)
|
||||
if self.app_id in sign or self.app_id in loc:
|
||||
state = 1
|
||||
book_id = None
|
||||
# for book in self.books:
|
||||
# if book["bookdata"].signature == entry:
|
||||
# book_id = book["id"]
|
||||
# break
|
||||
self.logger.log_info(f"State of {signature}: {state}")
|
||||
print(
|
||||
"lock acquired, updating availability of "
|
||||
+ str(book_id)
|
||||
+ " to "
|
||||
+ str(state)
|
||||
)
|
||||
try:
|
||||
self.db.setAvailability(self.book_id, state)
|
||||
except sqlite3.OperationalError as e:
|
||||
self.logger.log_error(f"Failed to update availability: {e}")
|
||||
break
|
||||
|
||||
# time.sleep(5)
|
||||
item += 1
|
||||
@@ -1,17 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from src.backend.database import Database
|
||||
|
||||
|
||||
def test_prof():
|
||||
assert Database().getProfNameById(1, add_title=True) == "Karoß Sabine"
|
||||
assert Database().getProfNameById(1, add_title=False) == "Karoß Sabine"
|
||||
assert Database().getProfId("Karoß Sabine") == 1
|
||||
|
||||
|
||||
def test_apparat():
|
||||
assert Database().getApparatName(3, 1) == "Theorie und Praxis Gymnastik"
|
||||
|
||||
|
||||
def test_admin():
|
||||
assert len(Database().getUser()) >= 1 and "admin" in Database().getUser()
|
||||
@@ -1,10 +0,0 @@
|
||||
from test.webrequest_test import test_webdata_bibtexttransform
|
||||
|
||||
|
||||
def many_test_webdata():
|
||||
test_webdata_bibtexttransform("RIS")
|
||||
test_webdata_bibtexttransform("BibTeX")
|
||||
test_webdata_bibtexttransform("COinS")
|
||||
test_webdata_bibtexttransform("ARRAY")
|
||||
test_webdata_bibtexttransform("RDS")
|
||||
assert True is True
|
||||
103
test/rds_test.py
103
test/rds_test.py
@@ -1,103 +0,0 @@
|
||||
def contact_prof(self):
|
||||
dialog = QtWidgets.QDialog()
|
||||
mail_prev = Mail_Dialog()
|
||||
mail_prev.setupUi(dialog)
|
||||
mail_prevs = os.listdir("mail_vorlagen")
|
||||
if self.app_name.text() == "":
|
||||
mail_prevs.remove("Information zum Semesterapparat.eml")
|
||||
mail_prev.comboBox.addItems(mail_prevs)
|
||||
active_apparat_id = self.tableWidget_apparate.item(
|
||||
self.tableWidget_apparate.currentRow(), 0
|
||||
).text()
|
||||
general_data = {
|
||||
"Appname": self.app_name.text(),
|
||||
"AppSubject": self.app_fach.currentText(),
|
||||
"appnr": self.active_apparat,
|
||||
}
|
||||
print(active_apparat_id)
|
||||
mail_prev.appid = active_apparat_id
|
||||
base_data = self.db.getProfData(id=active_apparat_id)
|
||||
profname = self.db.getProfNameById(base_data["id"])
|
||||
profname = profname.split(" ")
|
||||
profname = f"{profname[1]} {profname[0]}"
|
||||
pass_data = {
|
||||
"prof_name": profname,
|
||||
"mail_name": base_data["prof_mail"],
|
||||
"general": general_data,
|
||||
}
|
||||
|
||||
mail_prev.set_data(pass_data)
|
||||
mail_prev.set_mail()
|
||||
dialog.exec()
|
||||
|
||||
|
||||
import subprocess
|
||||
import tempfile
|
||||
|
||||
from PyQt6 import QtCore, QtGui, QtWidgets
|
||||
|
||||
from src.ui.dialogs.mail_preview import Ui_Dialog
|
||||
|
||||
|
||||
class Mail_Dialog(QtWidgets.QDialog, Ui_Dialog):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setupUi(self)
|
||||
self.appid = ""
|
||||
self.mail_data = ""
|
||||
self.data = None
|
||||
self.buttonBox.accepted.connect(self.save_mail)
|
||||
|
||||
def set_data(self, data: dict):
|
||||
print(data)
|
||||
self.prof_name.setText(data["prof_name"])
|
||||
self.mail_name.setText(data["mail_name"])
|
||||
# assign data["general"] to self.data
|
||||
self.data = data["general"]
|
||||
|
||||
def set_mail(self):
|
||||
email_template = self.comboBox.currentText()
|
||||
with open(f"mail_vorlagen/{email_template}", "r", encoding="utf-8") as f:
|
||||
mail_template = f.read()
|
||||
email_header = email_template.split(".eml")[0]
|
||||
if "{AppNr}" in email_template:
|
||||
email_header = email_template.split(".eml")[0].format(AppNr=self.appid)
|
||||
self.mail_header.setText(email_header)
|
||||
self.mail_data = mail_template.split("<html>")[0]
|
||||
mail_html = mail_template.split("<html>")[1]
|
||||
mail_html = "<html>" + mail_html
|
||||
print(self.data)
|
||||
Appname = self.data["Appname"]
|
||||
mail_html = mail_html.format(
|
||||
Profname=self.prof_name.text().split(" ")[-1], Appname=Appname
|
||||
)
|
||||
|
||||
self.mail_body.setHtml(mail_html)
|
||||
|
||||
def save_mail(self):
|
||||
# create a temporary file
|
||||
mail_header = self.mail_header.text()
|
||||
mail_body = self.mail_body.toHtml()
|
||||
mail = self.mail_data + mail_body
|
||||
mail = mail.replace("Subject:", f"Subject: {mail_header}")
|
||||
with tempfile.NamedTemporaryFile(
|
||||
mode="w", delete=False, suffix=".eml", encoding="utf-8", dir="mails"
|
||||
) as f:
|
||||
f.write(mail)
|
||||
self.mail_path = f.name
|
||||
print(self.mail_path)
|
||||
# open the file using thunderbird
|
||||
subprocess.Popen(["thunderbird", f"{self.mail_path}"])
|
||||
# delete the file
|
||||
# os.remove(self.mail_path)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import sys
|
||||
|
||||
app = QtWidgets.QApplication(sys.argv)
|
||||
Dialog = QtWidgets.QDialog()
|
||||
ui = Mail_Dialog()
|
||||
ui.setupUi(Dialog)
|
||||
Dialog.show()
|
||||
sys.exit(app.exec())
|
||||
@@ -1,7 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from src.backend.semester import generateSemesterByDate
|
||||
|
||||
|
||||
def test_generateSemesterByDate():
|
||||
assert generateSemesterByDate() == "WiSe 23/24"
|
||||
@@ -1,4 +0,0 @@
|
||||
from src.backend.database import Database
|
||||
|
||||
db = Database("semap.db")
|
||||
# print(db.query_db("SELECT * FROM subjects WHERE id=1"))
|
||||
@@ -1,18 +0,0 @@
|
||||
import pytest
|
||||
|
||||
from src.logic.dataclass import BookData
|
||||
from src.logic.webrequest import BibTextTransformer, WebRequest
|
||||
|
||||
|
||||
def test_webdata_bibtexttransform(source_data: str = "RIS"):
|
||||
request = WebRequest().get_ppn("ST 250 U42 (15) ").get_data()
|
||||
assert isinstance(request, list) is True
|
||||
assert len(request) > 0
|
||||
model: BookData = BibTextTransformer(source_data).get_data(request).return_data()
|
||||
assert model is not None
|
||||
assert model.signature == "ST 250 U42 (15)"
|
||||
assert model.ppn == "1693321114"
|
||||
assert model.author == "Ullenboom, Christian"
|
||||
assert model.link == "https://rds.ibs-bw.de/phfreiburg/link?kid=1693321114"
|
||||
assert model.pages == "1246"
|
||||
assert model.publisher == "Rheinwerk Computing"
|
||||
Reference in New Issue
Block a user