# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'proje.1.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again.  Do not edit this file unless you know what you are doing.

import time

import requests
from bs4 import BeautifulSoup

from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtWidgets import QWidget, QApplication, QTextEdit, QLabel, QPushButton, QVBoxLayout, QFileDialog, QHBoxLayout
from PyQt5.QtWidgets import QAction, qApp, QMainWindow



class Ui_MainWindow(object):
    def setupUi(self, MainWindow):

        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(783, 767)

        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")

        self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
        self.verticalLayoutWidget.setGeometry(QtCore.QRect(0, 0, 771, 711))
        self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
        self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
        self.verticalLayout.setContentsMargins(0, 0, 0, 0)
        self.verticalLayout.setObjectName("verticalLayout")

        self.title = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setPointSize(20)
        font.setBold(True)
        font.setWeight(75)
        self.title.setFont(font)
        self.title.setObjectName("title")

        self.verticalLayout.addWidget(self.title)

        self.dollar_tl = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Segoe MDL2 Assets")
        font.setPointSize(14)
        font.setBold(True)
        font.setWeight(75)
        self.dollar_tl.setFont(font)
        self.dollar_tl.setObjectName("dollar_tl")

        self.verticalLayout.addWidget(self.dollar_tl)

        self.h_box_dollar_tl = QtWidgets.QHBoxLayout()
        self.h_box_dollar_tl.setObjectName("h_box_dollar_tl")

        self.dollar_tl2 = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Myanmar Text")
        font.setPointSize(10)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.dollar_tl2.setFont(font)
        self.dollar_tl2.setObjectName("dollar_tl2")

        self.h_box_dollar_tl.addWidget(self.dollar_tl2)

        self.dollar_tl_input = QtWidgets.QTextEdit(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.dollar_tl_input.setFont(font)
        self.dollar_tl_input.setObjectName("dollar_tl_input")

        self.dollar_tl_input.setFixedSize(300, 30)

        self.h_box_dollar_tl.addWidget(self.dollar_tl_input)

        self.dollar_tl_translate = QtWidgets.QPushButton(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Myanmar Text")
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.dollar_tl_translate.setFont(font)
        self.dollar_tl_translate.setObjectName("dollar_tl_translate")

        self.h_box_dollar_tl.addWidget(self.dollar_tl_translate)

        self.dollar_tl_result = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Myanmar Text")
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.dollar_tl_result.setFont(font)
        self.dollar_tl_result.setObjectName("dollar_tl_result")

        self.h_box_dollar_tl.addWidget(self.dollar_tl_result)

        self.verticalLayout.addLayout(self.h_box_dollar_tl)

        self.dollar_tl_translate.clicked.connect(self.f_dollar_tl)

        self.tl_dollar = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Segoe MDL2 Assets")
        font.setPointSize(14)
        font.setBold(True)
        font.setWeight(75)
        self.tl_dollar.setFont(font)
        self.tl_dollar.setObjectName("tl_dollar")

        self.verticalLayout.addWidget(self.tl_dollar)

        self.h_box_tl_dollar = QtWidgets.QHBoxLayout()
        self.h_box_tl_dollar.setObjectName("h_box_tl_dollar")

        self.tl_dollar2 = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Myanmar Text")
        font.setPointSize(10)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.tl_dollar2.setFont(font)
        self.tl_dollar2.setObjectName("tl_dollar2")

        self.h_box_tl_dollar.addWidget(self.tl_dollar2)

        self.tl_dollar_input = QtWidgets.QTextEdit(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.tl_dollar_input.setFont(font)
        self.tl_dollar_input.setObjectName("tl_dollar_input")

        self.tl_dollar_input.setFixedSize(300, 30)

        self.h_box_tl_dollar.addWidget(self.tl_dollar_input)

        self.tl_dollar_translate = QtWidgets.QPushButton(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Myanmar Text")
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.tl_dollar_translate.setFont(font)
        self.tl_dollar_translate.setObjectName("tl_dollar_translate")

        self.h_box_tl_dollar.addWidget(self.tl_dollar_translate)

        self.tl_dollar_result = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Myanmar Text")
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.tl_dollar_result.setFont(font)
        self.tl_dollar_result.setObjectName("tl_dollar_result")

        self.h_box_tl_dollar.addWidget(self.tl_dollar_result)

        self.verticalLayout.addLayout(self.h_box_tl_dollar)

        self.tl_dollar_translate.clicked.connect(self.f_tl_dollar)

        self.euro_tl = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Segoe MDL2 Assets")
        font.setPointSize(14)
        font.setBold(True)
        font.setWeight(75)
        self.euro_tl.setFont(font)
        self.euro_tl.setObjectName("euro_tl")

        self.verticalLayout.addWidget(self.euro_tl)

        self.h_box_euro_tl = QtWidgets.QHBoxLayout()
        self.h_box_euro_tl.setObjectName("h_box_euro_tl")

        self.euro_tl2 = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Myanmar Text")
        font.setPointSize(10)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.euro_tl2.setFont(font)
        self.euro_tl2.setObjectName("euro_tl2")

        self.h_box_euro_tl.addWidget(self.euro_tl2)

        self.euro_tl_input = QtWidgets.QTextEdit(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.euro_tl_input.setFont(font)
        self.euro_tl_input.setObjectName("euro_tl_input")

        self.euro_tl_input.setFixedSize(300, 30)

        self.h_box_euro_tl.addWidget(self.euro_tl_input)

        self.euro_tl_translate = QtWidgets.QPushButton(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Myanmar Text")
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.euro_tl_translate.setFont(font)
        self.euro_tl_translate.setObjectName("euro_tl_translate")

        self.h_box_euro_tl.addWidget(self.euro_tl_translate)

        self.euro_tl_result = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Myanmar Text")
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.euro_tl_result.setFont(font)
        self.euro_tl_result.setObjectName("euro_tl_result")

        self.h_box_euro_tl.addWidget(self.euro_tl_result)

        self.verticalLayout.addLayout(self.h_box_euro_tl)

        self.euro_tl_translate.clicked.connect(self.f_euro_tl)

        self.tl_euro = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Segoe MDL2 Assets")
        font.setPointSize(14)
        font.setBold(True)
        font.setWeight(75)
        self.tl_euro.setFont(font)
        self.tl_euro.setObjectName("tl_euro")

        self.verticalLayout.addWidget(self.tl_euro)

        self.h_box_tl_euro = QtWidgets.QHBoxLayout()
        self.h_box_tl_euro.setObjectName("h_box_tl_euro")

        self.tl_euro2 = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Myanmar Text")
        font.setPointSize(10)
        font.setBold(True)
        font.setItalic(True)
        font.setWeight(75)
        self.tl_euro2.setFont(font)
        self.tl_euro2.setObjectName("tl_euro2")

        self.h_box_tl_euro.addWidget(self.tl_euro2)

        self.tl_euro_input = QtWidgets.QTextEdit(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.tl_euro_input.setFont(font)
        self.tl_euro_input.setObjectName("tl_euro_input")

        self.tl_euro_input.setFixedSize(300, 30)

        self.h_box_tl_euro.addWidget(self.tl_euro_input)

        self.tl_euro_translate = QtWidgets.QPushButton(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Myanmar Text")
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.tl_euro_translate.setFont(font)
        self.tl_euro_translate.setObjectName("tl_euro_translate")

        self.h_box_tl_euro.addWidget(self.tl_euro_translate)

        self.tl_euro_result = QtWidgets.QLabel(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Myanmar Text")
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.tl_euro_result.setFont(font)
        self.tl_euro_result.setObjectName("tl_euro_result")

        self.h_box_tl_euro.addWidget(self.tl_euro_result)

        self.verticalLayout.addLayout(self.h_box_tl_euro)

        self.tl_euro_translate.clicked.connect(self.f_tl_euro)

        self.doviz = QtWidgets.QTextEdit(self.verticalLayoutWidget)
        font = QtGui.QFont()
        font.setFamily("Myanmar Text")
        font.setPointSize(10)
        font.setBold(True)
        font.setWeight(75)
        self.doviz.setFont(font)
        self.doviz.setObjectName("doviz")

        self.verticalLayout.addWidget(self.doviz)

        MainWindow.setCentralWidget(self.centralwidget)

        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 783, 21))
        self.menubar.setObjectName("menubar")

        MainWindow.setMenuBar(self.menubar)

        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")

        MainWindow.setStatusBar(self.statusbar)

        self.retranslateUi(MainWindow)

        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate

        MainWindow.setWindowTitle(_translate("MainWindow", "DÖVİZ PROGRAMI"))

        self.title.setText(_translate("MainWindow", "                                DÖVİZ PROGRAMI"))

        self.dollar_tl.setText(_translate("MainWindow", "                                                     DOLAR  -->  TL"))
        self.dollar_tl2.setText(_translate("MainWindow", " DOLAR MİKTARI GİRİNİZ   ->  "))
        self.dollar_tl_translate.setText(_translate("MainWindow", "$>TL ÇEVİR"))
        self.dollar_tl_result.setText(_translate("MainWindow", "                       "))

        self.tl_dollar.setText(_translate("MainWindow", "                                                     TL  -->  DOLAR"))
        self.tl_dollar2.setText(_translate("MainWindow", " TL MİKTARI GİRİNİZ   ->  "))
        self.tl_dollar_translate.setText(_translate("MainWindow", "TL>$ ÇEVİR"))
        self.tl_dollar_result.setText(_translate("MainWindow", "                       "))

        self.euro_tl.setText(_translate("MainWindow", "                                                     EURO  -->  TL"))
        self.euro_tl2.setText(_translate("MainWindow", " EURO MİKTARI GİRİNİZ   ->  "))
        self.euro_tl_translate.setText(_translate("MainWindow", "EU>TL ÇEVİR"))
        self.euro_tl_result.setText(_translate("MainWindow", "                       "))

        self.tl_euro.setText(_translate("MainWindow", "                                                     TL  -->  EURO"))
        self.tl_euro2.setText(_translate("MainWindow", " TL MİKTARI GİRİNİZ   ->  "))
        self.tl_euro_translate.setText(_translate("MainWindow", "TL>EU ÇEVİR"))
        self.tl_euro_result.setText(_translate("MainWindow", "                       "))
        
        self.dovizs()

    def dovizs(self):
        url = "https://kur.doviz.com"
        response = requests.get(url)
        html_icerik = response.content
        soup = BeautifulSoup(html_icerik, "html.parser")

        unit = soup.find_all("span", {"class": "name"})
        price = soup.find_all("span", {"class": "value"})

        list_doviz = []
        for i, j in zip(unit,price):
            list_doviz.append(f"{i.text} : {j.text}")

        self.list_unit = []
        self.list_price = []
        for i, j in zip(unit, price):
            self.list_unit.append(i.text)
            self.list_price.append((j.text).replace(",","."))

        # all_list = []
        # for i, j in zip(self.list_unit, self.list_price):
        #     all_list.append(f"{i} - {j}")

        # for i in enumerate(all_list):
        #     print(i)

        with open("dovizs.txt", "w", encoding="utf-8")as file:

            for i in list_doviz:
                file.write(f"{i}\n")

        with open("dovizs.txt", "r", encoding="utf-8")as file:
            self.doviz.setPlainText(file.read())

    def f_dollar_tl(self):
        with open("f_dollar_tl.txt", "w", encoding="utf-8")as file:
            file.write(str(self.dollar_tl_input.toPlainText()))

        f_dollar_tl = 0
        with open("f_dollar_tl.txt", "r+", encoding="utf-8")as file:
            for i in file:
                f_dollar_tl += float(i)

        f_dollar_tl_result = float(f_dollar_tl) * float(self.list_price[1])

        self.dollar_tl_result.setText(str(f_dollar_tl_result))

    def f_tl_dollar(self):
        with open("f_tl_dollar.txt", "w", encoding="utf-8")as file:
            file.write(str(self.tl_dollar_input.toPlainText()))

        f_tl_dollar = 0
        with open("f_tl_dollar.txt", "r+", encoding="utf-8")as file:
            for i in file:
                f_tl_dollar += float(i)

        f_tl_dollar_result = float(f_tl_dollar) / float(self.list_price[1])

        self.tl_dollar_result.setText(str(f_tl_dollar_result))

    def f_euro_tl(self):
        with open("f_euro_tl.txt", "w", encoding="utf-8")as file:
            file.write(str(self.euro_tl_input.toPlainText()))

        f_euro_tl = 0
        with open("f_euro_tl.txt", "r+", encoding="utf-8")as file:
            for i in file:
                f_euro_tl += float(i)

        f_euro_tl_result = float(f_euro_tl) * float(self.list_price[2])

        self.euro_tl_result.setText(str(f_euro_tl_result))

    def f_tl_euro(self):
        with open("f_tl_euro.txt", "w", encoding="utf-8")as file:
            file.write(str(self.tl_euro_input.toPlainText()))

        f_tl_euro = 0
        with open("f_tl_euro.txt", "r+", encoding="utf-8")as file:
            for i in file:
                f_tl_euro += float(i)

        f_tl_euro_result = float(f_tl_euro) / float(self.list_price[2])

        self.tl_euro_result.setText(str(f_tl_euro_result))


if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())