Advertisement
c0d3dsk1lls

Currency converter CodedSkills.net

Aug 6th, 2022 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 10.07 KB | None | 0 0
  1. ##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++##
  2. ##===========================================================================================================================================================================================##
  3. ##---CODEDSKILLS.NET-------------------------------------------------------------------------------------------------------------------------------------------------------------------------##
  4. #--CURRENCY CONVERTER ------------------------------#----------------------------------------------------------------------------+---------------------------+
  5. from PyQt5.QtGui import *   #-----------------------#----------------------------------------------------------+------+------------------+
  6. from PyQt5.QtCore import *   #----------------------#--------------+-----------+
  7. from PyQt5.QtWidgets import *   #-------------------#--------+---------------------------------+
  8. from PyQt5 import QtWidgets, uic   #----------------#----+
  9. from PyQt5.QtCore import *   #----------------------#-----+----------------------------+-------------------------------+------------------------------------+-----------------------------------------------------+
  10. import requests   #---------------------------------#--------------------+---------+------------+----------------------------------------+-------------+--------------------------------+
  11. from bs4 import BeautifulSoup   #-------------------#----------+
  12. from requests.models import ContentDecodingError    #------+
  13. #---------------------------------------------------#
  14. #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  15. #-----------------------------------------------------------------------------------------------------------------------------------+----------------+-----------------------------+
  16. #---------------------------#
  17. def getVal(cont1, cont2):   #-------#------+--------------+
  18.     cont1val = cont1.split("-")[1]  #--+------------+
  19.     cont2val = cont2.split("-")[1]  #-----------------------------------------------------------------------------------------#
  20.     url = f"https://free.currconv.com/api/v7/convert?q={cont1val}_{cont2val}&compact=ultra&apiKey=b43a653672c4a94c4c26"   #---#---------------------------+
  21.     r = requests.get(url) #-----------------------------------------------------------------------------------------------#
  22.     htmlContent = r.content #---------------------------------------------------------------------------------------------#---------+------+
  23.     soup = BeautifulSoup(htmlContent, "html.parser") #--------------------------------------#
  24.     try:  #---------------------------------------------------------------------------------#
  25.         valCurr = float(soup.get_text().split(":")[1].removesuffix("}"))  # {USD:70.00}     #
  26.     except Exception: #---------------------------------------------------------------------#---------+------------+----------------------------------+0110000000101101+---------------------+
  27.         print("Server down.")    #
  28.         exit()          #--------#-------+
  29.     return valCurr      #
  30. #-----------------------#
  31. #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  32. #-----------------------------------------------------------------------------------------------------------------------------------+----------------+-----------------------------+
  33. app = QtWidgets.QApplication([])     #----------------------------------#--------------------------------------+----------------------------------------------------------------------------------------------+
  34. window = uic.loadUi("gui.ui")    #--------------------------------------#
  35. f = open("country.txt", "r") #------------------------------------------#----------------------------------------------+---------------------+
  36. window = uic.loadUi("A:\Python Projects\Currency-converter\gui.ui")     # BE SURE TO MODIFY THIS LINE TO YOUR DIRECTORY
  37. f = open("A:\Python Projects\Currency-converter\country.txt", "r")      # BE SURE TO MODIFY THIS LINE TO YOUR DIRECTORY
  38. window.dropDown1.addItem("Select")    #---------------------------------#------+-------------+------+---------+
  39. window.dropDown2.addItem("Select")    #
  40. for i in f.readlines(): #-------------#
  41.     window.dropDown1.addItem(i)  #
  42.     window.dropDown2.addItem(i)  #
  43. intOnly = QDoubleValidator() #-----------------#---------------+--------+
  44. window.lineEdit.setValidator(intOnly)          #-----------+------------------------------+
  45. def main():      #-----------------------------#
  46. #----------------#-----------------------------#-----#---------------+
  47.     window.pushButton.clicked.connect(changeBtn)     #--+
  48. def changeBtn(): #---------------#-------------------#-------+
  49.     val = window.lineEdit.text() #---------#
  50.     cont1 = window.dropDown1.currentText() #
  51.     cont2 = window.dropDown2.currentText() #-----------#
  52.     valCurr = getVal(cont1.rstrip(), cont2.rstrip())   #
  53.     window.lcdpanel.display(float(val) * valCurr)      #----------+--------------------------------------------------+01001010001+-----------------------+
  54. main()           #-------------------------------------#---------------------------+-------------+
  55. window.show()    #
  56. app.exec()       #
  57. #----------------#
  58. ##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++##
  59. ##=================================================================================================================================================##
  60. ##-------------------------------------------------------------------------------------------------------------------------------------------------##
  61. ##                                                                                                                                                 ##
  62. ##                                                                                        ##   //                                                  ##
  63. ##----+-#########\   ########  -+#######\\-- +##########   #######\\        /#######\\    ##  //     ######---+-##      ##       /#######\\        ##
  64. ##      ##-          ##|--|##    ##-     ##   ##           ##-     ##      ||-----        ## //        ##       ##----+-##      ||-----         +--##
  65. ##      ##           ##|  |##  -+##    +--##  #######      ##       ##  -- \\#######\\    ## \\        ##       ##      ##------\\#######\\-------+##
  66. ##      ##-        +-##|--|##    ##-     ##   ##           ##-     ##         ------||    ##  \\       ##       ##      ##         ------||--------##
  67. ##      #########/   ########  -#######//-  -+##########   #######//       \\######//     ##   \\    ######---+-#####   #####   \\######//------+--##
  68. ##                                                                                                                                                 ##
  69. ##                                                          https://CodedSkills.net                                                                ##
  70. ##-------------------------------------------------------------------------------------------------------------------------------------------------##
  71. ##=================================================================================================================================================##
  72. ##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++##
  73.  
  74.  
  75. ##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++##
  76. ##=======================================================================================================================================================================================##
  77. ##---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------##
  78. ##                                                                                                                                                                                       ##
  79. ##           ###       #######\    #######\       #######       ########     ##  ##     ########     ########       #######     ########       ####        ##         /#######\\         ##
  80. ##          #-##            //          //        \   //    =      ##        ##  ##        ##        ##|--|##       ##  //         ##         //  \\       ##        ||-                 ##
  81. ##            ##          ##\\        ##\\           //            ##        ##  ##        ##        ##|  |##       ###\\          ##        //====\\      ##        \\#######\\         ##
  82. ##            ##            //          //          //             ##        ##  ##        ##        ##|--|##       ##  \\         ##       //      \\     ##                 ||         ##
  83. ##       ##########   ########--  ########--       //       =      ##         ####         ##        ########       ##   \\     ########   //        \\    #######   \\######//          ##
  84. ##                                                                                                                                                                                       ##
  85. ##                                                                         https://1337tutorials.net                                                                                     ##
  86. ##---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------##
  87. ##=======================================================================================================================================================================================##
  88. ##+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++##
  89.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement