Exemple #1
0
def index():
    user = UserSession()

    if request.method == "POST":
        form = request.form
        country = form.get("country_select", "CA")
        source = form.get("source", "")

        user.template.country = country
        user.template.source = source

        job = Job(False, input_type="qt")

        obj = job.process_email(user.template.html,
                                source_code=source,
                                country=country)
        user.template.html = obj.get_content()
        user.template.result_images = str(obj.get_images())
        user.template.result_links = str(obj.get_links())
        user.template.result_source = str(obj.get_source_codes())
        user.template.result_notes = str(obj.notifications)
        db.session.add(user.template)
        db.session.commit()

        return render_template("index.html",
                               result=True,
                               country=user.template.country)

    return render_template("index.html", country=user.template.country)
Exemple #2
0
 def __init__(self):
     print("Running __init__")
     self.filename = ""
     self.outfile = "default.html"
     self.html = ""
     self.country = readConf("country")
     if not self.country:
         self.country = "CA"
     self.job = Job(False, input_type="qt")
     self.replace_items = self.getReplace("data/replace_{}.csv".format(
         self.country))
Exemple #3
0
class EmailsGUI(Ui_MainWindow):

    def __init__(self):
        print("Running __init__")
        self.filename = ""
        self.outfile = "default.html"
        self.html = ""
        self.job = Job(False, input_type="qt")

    def initGUI(self, MainWindow):
        print("Setting up EmailGUI")
        self.window = MainWindow
        self.pushButton.clicked.connect(self.runClicked)
        self.actionOpen.setShortcut("Ctrl+O")
        self.actionOpen.setStatusTip('Open File')
        self.actionOpen.triggered.connect(self.fileOpen)
        self.menuFile

    def runClicked(self):
        obj = self.job.html_email(self.filename)
        self.writeOutfile(obj)

        obj = self.job.run_results(self.outfile)
        self.writeResults(obj)

        self.HTMLEdit.appendPlainText(obj.get_content())
        self.webView.setUrl(QtCore.QUrl("file://" + os.getcwd() + "/" + self.outfile))
        self.webViewResult.setUrl(QtCore.QUrl("file://" + os.getcwd() + "/data/result.html"))


    def writeOutfile(self, obj):
        with open(self.outfile, 'w+') as o:
            data = obj.get_content()
            o.write(data)

    def writeResults(self, obj):
        html = self.job.html_result(obj)
        if html is not None:
            with open("data/result.html", 'w+') as o:
                o.write(html)


    def fileOpen(self):
        self.filename, _ = QtWidgets.QFileDialog.getOpenFileName(self.window, 'Open File', ".")
        if self.filename:
            with open(self.filename, 'r+') as f:
                self.html = f.read()
            self.HTMLEdit.appendPlainText(self.html)
            self.webView.setUrl(QtCore.QUrl("file://" + self.filename))
Exemple #4
0
def read_file(infile, outfile, url, article, verbose, result):
    job = Job(verbose)

    if not outfile:
        outfile = "default.html"

    if job.debug:
        print("+ Running with debugging output")

    if url is not None and infile is not None:
        print("Cannot use both -u and -f choose one")

    elif url is not None:
        if article:
            obj = job.url_article(url)
            print_outfile(outfile, obj)
        else:
            obj = job.url_email(url)
            print_outfile(outfile, obj)

    elif infile is not None:
        if result:
            obj = job.run_results(infile)
            print_results(obj, job)
        else:
            obj = job.html_email(infile, source_code=True)
            print_outfile(outfile, obj)

            obj = job.run_results(outfile)
            print_results(obj, job)

    print("Goodbye!")
Exemple #5
0
def read_file(infile, outfile, url, article, verbose, result):
    job = Job(verbose)

    if not outfile:
        outfile = "default.html"

    if job.debug:
        print("+ Running with debugging output")

    if url is not None and infile is not None:
        print("Cannot use both -u and -f choose one")

    elif url is not None:
        if article:
            obj = job.url_article(url)
            print_outfile(outfile, obj)
        else:
            obj = job.url_email(url)
            print_outfile(outfile, obj)

    elif infile is not None:
        if result:
            obj = job.run_results(infile)
            print_results(obj, job)
        else:
            obj = job.html_email(infile)
            print_outfile(outfile, obj)

            obj = job.run_results(outfile)
            print_results(obj, job)

    print("Goodbye!")
Exemple #6
0
 def __init__(self):
     print("Running __init__")
     self.filename = ""
     self.outfile = "default.html"
     self.html = ""
     self.job = Job(False, input_type="qt")
Exemple #7
0
class EmailsGUI(Ui_MainWindow):
    def __init__(self):
        print("Running __init__")
        self.filename = ""
        self.outfile = "default.html"
        self.html = ""
        self.country = readConf("country")
        if not self.country:
            self.country = "CA"
        self.job = Job(False, input_type="qt")
        self.replace_items = self.getReplace("data/replace_{}.csv".format(
            self.country))

    def initGUI(self, MainWindow):
        print("Setting up EmailGUI")
        self.window = MainWindow
        self.run_button.clicked.connect(self.runClicked)
        self.undo_button.clicked.connect(self.undoClicked)
        self.back_button.clicked.connect(self.webView.back)
        self.update_list_button.clicked.connect(self.updateClicked)
        self.actionOpen.setShortcut("Ctrl+O")
        self.actionOpen.setStatusTip('Open File')
        self.actionOpen.triggered.connect(self.fileOpen)
        self.webView.urlChanged.connect(self.updateAddress)
        self.address_bar.returnPressed.connect(self.updateUrl)

        self.replace_list.clear()
        with open("data/replace_{}.csv".format(self.country), 'r') as f:
            self.replace_list.appendPlainText(f.read())

        self.to_select.currentIndexChanged.connect(self.runCountry)

        countries = ["CA", "US", "GB"]

        for country in countries:
            self.to_select.addItem(country)

        self.menuFile

    def runCountry(self):
        self.country = self.to_select.currentText()
        self.replace_items = self.getReplace("data/replace_{}.csv".format(
            self.country))
        self.replace_list.clear()
        with open("data/replace_{}.csv".format(self.country), 'r') as f:
            self.replace_list.appendPlainText(f.read())

    def undoClicked(self):
        self.webView.setUrl(QtCore.QUrl("file://" + self.filename))

    def runClicked(self):
        source = self.source_text.text
        print(self.country)
        obj = self.job.html_email(self.filename, country=self.country)
        self.writeOutfile(obj)

        obj = self.job.run_results(self.outfile)
        self.writeResults(obj)

        self.HTMLEdit.clear()
        self.HTMLEdit.appendPlainText(obj.get_content())
        self.webView.setUrl(
            QtCore.QUrl("file://" + os.getcwd() + "/" + self.outfile))
        print("Saved to {}".format(self.outfile))
        self.webViewResult.setUrl(
            QtCore.QUrl("file://" + os.getcwd() + "/data/result.html"))
        self.updateAddress()

    def updateClicked(self):
        text = self.replace_list.toPlainText()
        with open("data/replace_{}.csv".format(self.country), 'w') as w:
            w.write(text)
        QtWidgets.QMessageBox.about(self.window, "Update complete",
                                    "Replace List saved")

    def updateAddress(self):
        url = self.webView.url().toString()
        self.address_bar.setText(url)

    def updateUrl(self):
        self.webView.setUrl(QtCore.QUrl(self.address_bar.text()))

    def getReplace(self, list):
        replace_items = []
        with open(list, "r") as f:
            replace_csv = csv.reader(f, delimiter='|')
            for row in replace_csv:
                replace_items.append(row)
        return replace_items

    def writeOutfile(self, obj):
        with open(self.outfile, 'w+') as o:
            data = obj.get_content()
            o.write(data)

    def writeResults(self, obj):
        html = self.job.html_result(obj)
        if html is not None:
            with open("data/result.html", 'w+') as o:
                o.write(html)

    def fileOpen(self):
        self.filename, _ = QtWidgets.QFileDialog.getOpenFileName(
            self.window, 'Open File', ".")
        if self.filename:
            with open(self.filename, 'r+') as f:
                self.html = f.read()
            self.HTMLEdit.clear()
            self.HTMLEdit.appendPlainText(self.html)
            self.webView.setUrl(QtCore.QUrl("file://" + self.filename))