-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTutor.py
188 lines (113 loc) · 5.83 KB
/
Tutor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'Alexa_Dialog.ui'
#
# Created by: PyQt5 UI code generator 5.10.1
#
# WARNING! All changes made in this file will be lost!
import requests
import json
import re
import time
from bs4 import BeautifulSoup
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import smtplib
from update_student import update_student
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName("Dialog")
Dialog.resize(1026, 842)
self.textEdit = QtWidgets.QTextEdit(Dialog)
self.textEdit.setGeometry(QtCore.QRect(10, 10, 1001, 731))
self.textEdit.setObjectName("textEdit")
self.pushButton = QtWidgets.QPushButton(Dialog)
self.pushButton.setGeometry(QtCore.QRect(60, 760, 96, 27))
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(Dialog)
self.label.setGeometry(QtCore.QRect(230, 760, 151, 20))
self.label.setObjectName("label")
self.lineEdit = QtWidgets.QLineEdit(Dialog)
self.lineEdit.setGeometry(QtCore.QRect(390, 760, 621, 26))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit.textChanged.connect(self.search_text)
self.lineEdit.textChanged.connect(self.search_text)
self.pushButton.clicked.connect(self.update_info)
self.pushButton_2 = QtWidgets.QPushButton(Dialog)
self.pushButton_2.setGeometry(QtCore.QRect(140, 800, 241, 27))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_2.clicked.connect(self.send_transcript_to_self)
self.pushButton_3 = QtWidgets.QPushButton(Dialog)
self.pushButton_3.setGeometry(QtCore.QRect(520, 800, 361, 27))
self.pushButton_3.setObjectName("pushButton_3")
self.pushButton_3.clicked.connect(self.send_transcript_to_self)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
self.update_info()
try:
self.server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
self.server.ehlo()
self.server.login('[email protected]', 'alokjoaopm')
except:
print('No E-mail Connection')
def update_info(self):
update_student() # from update_student library
with open("all.txt") as f:
lines = f.readlines()
lines = [line.strip() for line in lines]
lines = [line for line in lines if len(line) != 0]
self.set_text(lines)
self.lineEdit.clear()
def send_transcript_to_self(self):
try:
subject = 'Alexa Tutor Transcript'
message = 'Subject: {}\n\n{}'.format(subject, self.raw_text)
self.server.sendmail('[email protected]', '[email protected]', message)
except:
pass
def set_text(self, lines):
self.text_str = ''
self.raw_text = ''
for line in lines:
self.text_str = self.text_str + line + '<br />'
self.raw_text = self.raw_text + line + '\n'
self.text_str0 = self.text_str[:]
_translate = QtCore.QCoreApplication.translate
self.textEdit.setHtml(_translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Ubuntu\'; font-size:11pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" + self.text_str + "</p></body></html>"))
def update_search_text(self):
_translate = QtCore.QCoreApplication.translate
self.textEdit.setHtml(_translate("Dialog", "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0//EN\" \"http://www.w3.org/TR/REC-html40/strict.dtd\">\n"
"<html><head><meta name=\"qrichtext\" content=\"1\" /><style type=\"text/css\">\n"
"p, li { white-space: pre-wrap; }\n"
"</style></head><body style=\" font-family:\'Ubuntu\'; font-size:11pt; font-weight:400; font-style:normal;\">\n"
"<p style=\" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;\">" + self.text_str + "</p></body></html>"))
def search_text(self):
ttt = self.lineEdit.text()
if len(ttt) == 0:
self.text_str = self.text_str0[:]
self.update_search_text()
return
self.text_str = self.text_str0[:]
self.text_str = re.sub(ttt, r'<font color=blue><b>' + ttt + '</b></font>', self.text_str, flags = re.IGNORECASE)
self.update_search_text()
def retranslateUi(self, Dialog):
_translate = QtCore.QCoreApplication.translate
Dialog.setWindowTitle(_translate("Dialog", "Alexa Tutor"))
self.pushButton.setText(_translate("Dialog", "Update"))
self.label.setText(_translate("Dialog", "Search Transcript"))
self.pushButton_2.setText(_translate("Dialog", "Email Transcript to Self"))
self.pushButton_3.setText(_translate("Dialog", "Email Query to Instructor"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
Dialog = QtWidgets.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.setWindowIcon(QtGui.QIcon('Tutor.jpg'))
Dialog.show()
sys.exit(app.exec_())