# import MySQLdb
import mysql.connector as mariadb

# db = MySQLdb.connect("localhost", "root", "toor", "banknote")
db = mariadb.connect(user = "vula", password = "mat.khau.cua.vula", database = "vudb")
cursor = db.cursor()

data = open('./rate/USD.txt', 'r').read()
data = data.split('\n')

banknote_country = {'DZD': 'http://128.199.160.37:8001/flags/DZA.png',
'NAD': 'http://128.199.160.37:8001/flags/NAM.png',
'GHS': 'http://128.199.160.37:8001/flags/GHA.png',
'EGP': 'http://128.199.160.37:8001/flags/EGY.png',
'BGN': 'http://128.199.160.37:8001/flags/BGR.png',
'PAB': 'http://128.199.160.37:8001/flags/PAN.png',
'BOB': 'http://128.199.160.37:8001/flags/BOL.png',
'DKK': 'http://128.199.160.37:8001/flags/DNK.png',
'BWP': 'http://128.199.160.37:8001/flags/BWA.png',
'LBP': 'http://128.199.160.37:8001/flags/LBN.png',
'TZS': 'http://128.199.160.37:8001/flags/TZA.png',
'VND': 'http://128.199.160.37:8001/flags/VNM.png',
'AOA': 'http://128.199.160.37:8001/flags/AGO.png',
'KHR': 'http://128.199.160.37:8001/flags/KHM.png',
'MYR': 'http://128.199.160.37:8001/flags/MYS.png',
'KYD': 'http://128.199.160.37:8001/flags/CYM.png',
'LYD': 'http://128.199.160.37:8001/flags/LBY.png',
'UAH': 'http://128.199.160.37:8001/flags/UKR.png',
'JOD': 'http://128.199.160.37:8001/flags/JOR.png',
'AWG': 'http://128.199.160.37:8001/flags/ABW.png',
'SAR': 'http://128.199.160.37:8001/flags/SAU.png',
'LTL': 'http://128.199.160.37:8001/flags/LTU.png',
'HKD': 'http://128.199.160.37:8001/flags/HKG.png',
'CHF': 'http://128.199.160.37:8001/flags/CHE.png',
'GIP': 'http://128.199.160.37:8001/flags/GIB.png',
'BYR': 'http://128.199.160.37:8001/flags/BLR.png',
'ALL': 'http://128.199.160.37:8001/flags/ALB.png',
'MRO': 'http://128.199.160.37:8001/flags/MRT.png',
'HRK': 'http://128.199.160.37:8001/flags/HRV.png',
'DJF': 'http://128.199.160.37:8001/flags/DJI.png',
'SZL': 'http://128.199.160.37:8001/flags/SWZ.png',
'THB': 'http://128.199.160.37:8001/flags/THA.png',
'BND': 'http://128.199.160.37:8001/flags/BRN.png',
'ISK': 'http://128.199.160.37:8001/flags/ISL.png',
'UYU': 'http://128.199.160.37:8001/flags/URY.png',
'NIO': 'http://128.199.160.37:8001/flags/NIC.png',
'LAK': 'http://128.199.160.37:8001/flags/LAO.png',
'SYP': 'http://128.199.160.37:8001/flags/SYR.png',
'MAD': 'http://128.199.160.37:8001/flags/MAR.png',
'MZN': 'http://128.199.160.37:8001/flags/MOZ.png',
'PHP': 'http://128.199.160.37:8001/flags/PHL.png',
'ZAR': 'http://128.199.160.37:8001/flags/ZAF.png',
'NPR': 'http://128.199.160.37:8001/flags/NPL.png',
'ZWL': 'http://128.199.160.37:8001/flags/ZWE.png',
'NGN': 'http://128.199.160.37:8001/flags/NGA.png',
'CRC': 'http://128.199.160.37:8001/flags/CRI.png',
'AED': 'http://128.199.160.37:8001/flags/ARE.png',
'MWK': 'http://128.199.160.37:8001/flags/MWI.png',
'LKR': 'http://128.199.160.37:8001/flags/LKA.png',
'PKR': 'http://128.199.160.37:8001/flags/PAK.png',
'HUF': 'http://128.199.160.37:8001/flags/HUN.png',
'BMD': 'http://128.199.160.37:8001/flags/BMU.png',
'LSL': 'http://128.199.160.37:8001/flags/LSO.png',
'MNT': 'http://128.199.160.37:8001/flags/MNG.png',
'AMD': 'http://128.199.160.37:8001/flags/ARM.png',
'UGX': 'http://128.199.160.37:8001/flags/UGA.png',
'QAR': 'http://128.199.160.37:8001/flags/QAT.png',
'JMD': 'http://128.199.160.37:8001/flags/JAM.png',
'GEL': 'http://128.199.160.37:8001/flags/GEO.png',
'SHP': 'http://128.199.160.37:8001/flags/SHN.png',
'AFN': 'http://128.199.160.37:8001/flags/AFG.png',
'SBD': 'http://128.199.160.37:8001/flags/SLB.png',
'KPW': 'http://128.199.160.37:8001/flags/PRK.png',
'TRY': 'http://128.199.160.37:8001/flags/TUR.png',
'BDT': 'http://128.199.160.37:8001/flags/BGD.png',
'YER': 'http://128.199.160.37:8001/flags/YEM.png',
'HTG': 'http://128.199.160.37:8001/flags/HTI.png',
'MGA': 'http://128.199.160.37:8001/flags/MDG.png',
'LRD': 'http://128.199.160.37:8001/flags/LBR.png',
'RWF': 'http://128.199.160.37:8001/flags/RWA.png',
'NOK': 'http://128.199.160.37:8001/flags/NOR.png',
'MOP': 'http://128.199.160.37:8001/flags/MAC.png',
'INR': 'http://128.199.160.37:8001/flags/IND.png',
'MXN': 'http://128.199.160.37:8001/flags/MEX.png',
'CZK': 'http://128.199.160.37:8001/flags/CZE.png',
'TJS': 'http://128.199.160.37:8001/flags/TJK.png',
'BTN': 'http://128.199.160.37:8001/flags/BTN.png',
'COP': 'http://128.199.160.37:8001/flags/COL.png',
'TMT': 'http://128.199.160.37:8001/flags/TKM.png',
'MUR': 'http://128.199.160.37:8001/flags/MUS.png',
'IDR': 'http://128.199.160.37:8001/flags/IDN.png',
'HNL': 'http://128.199.160.37:8001/flags/HND.png',
'FJD': 'http://128.199.160.37:8001/flags/FJI.png',
'ETB': 'http://128.199.160.37:8001/flags/ETH.png',
'PEN': 'http://128.199.160.37:8001/flags/PER.png',
'BZD': 'http://128.199.160.37:8001/flags/BLZ.png',
'ILS': 'http://128.199.160.37:8001/flags/ISR.png',
'DOP': 'http://128.199.160.37:8001/flags/DOM.png',
'GGP': 'http://128.199.160.37:8001/flags/GGY.png',
'MDL': 'http://128.199.160.37:8001/flags/MDA.png',
'BSD': 'http://128.199.160.37:8001/flags/BHS.png',
'SEK': 'http://128.199.160.37:8001/flags/SWE.png',
'AUD': 'http://128.199.160.37:8001/flags/AUS.png',
'SRD': 'http://128.199.160.37:8001/flags/SUR.png',
'CUP': 'http://128.199.160.37:8001/flags/CUB.png',
'BBD': 'http://128.199.160.37:8001/flags/BRB.png',
'KMF': 'http://128.199.160.37:8001/flags/COM.png',
'KRW': 'http://128.199.160.37:8001/flags/KOR.png',
'GMD': 'http://128.199.160.37:8001/flags/GMB.png',
'VEF': 'http://128.199.160.37:8001/flags/VEN.png',
'CLP': 'http://128.199.160.37:8001/flags/CHL.png',
'ZMW': 'http://128.199.160.37:8001/flags/ZMB.png',
'CDF': 'http://128.199.160.37:8001/flags/COD.png',
'KZT': 'http://128.199.160.37:8001/flags/KAZ.png',
'RUB': 'http://128.199.160.37:8001/flags/RUS.png',
'TTD': 'http://128.199.160.37:8001/flags/TTO.png',
'OMR': 'http://128.199.160.37:8001/flags/OMN.png',
'BRL': 'http://128.199.160.37:8001/flags/BRA.png',
'MMK': 'http://128.199.160.37:8001/flags/MMR.png',
'PLN': 'http://128.199.160.37:8001/flags/POL.png',
'PYG': 'http://128.199.160.37:8001/flags/PRY.png',
'KES': 'http://128.199.160.37:8001/flags/KEN.png',
'SVC': 'http://128.199.160.37:8001/flags/SLV.png',
'MKD': 'http://128.199.160.37:8001/flags/MKD.png',
'GBP': 'http://128.199.160.37:8001/flags/GBR.png',
'AZN': 'http://128.199.160.37:8001/flags/AZE.png',
'TOP': 'http://128.199.160.37:8001/flags/TON.png',
'MVR': 'http://128.199.160.37:8001/flags/MDV.png',
'VUV': 'http://128.199.160.37:8001/flags/VUT.png',
'GNF': 'http://128.199.160.37:8001/flags/GIN.png',
'WST': 'http://128.199.160.37:8001/flags/WSM.png',
'IQD': 'http://128.199.160.37:8001/flags/IRQ.png',
'ERN': 'http://128.199.160.37:8001/flags/ERI.png',
'BAM': 'http://128.199.160.37:8001/flags/BIH.png',
'SCR': 'http://128.199.160.37:8001/flags/SYC.png',
'CAD': 'http://128.199.160.37:8001/flags/CAN.png',
'CVE': 'http://128.199.160.37:8001/flags/CPV.png',
'KWD': 'http://128.199.160.37:8001/flags/KWT.png',
'BIF': 'http://128.199.160.37:8001/flags/BDI.png',
'PGK': 'http://128.199.160.37:8001/flags/PNG.png',
'SOS': 'http://128.199.160.37:8001/flags/SOM.png',
'TWD': 'http://128.199.160.37:8001/flags/TWN.png',
'SGD': 'http://128.199.160.37:8001/flags/SGP.png',
'UZS': 'http://128.199.160.37:8001/flags/UZB.png',
'STD': 'http://128.199.160.37:8001/flags/STP.png',
'IRR': 'http://128.199.160.37:8001/flags/IRN.png',
'CNY': 'http://128.199.160.37:8001/flags/CHN.png',
'SLL': 'http://128.199.160.37:8001/flags/SLE.png',
'TND': 'http://128.199.160.37:8001/flags/TUN.png',
'GYD': 'http://128.199.160.37:8001/flags/GUY.png',
'NZD': 'http://128.199.160.37:8001/flags/NZL.png',
'FKP': 'http://128.199.160.37:8001/flags/FLK.png',
'LVL': 'http://128.199.160.37:8001/flags/LVA.png',
'USD': 'http://128.199.160.37:8001/flags/USA.png',
'KGS': 'http://128.199.160.37:8001/flags/KGZ.png',
'ARS': 'http://128.199.160.37:8001/flags/ARG.png',
'RSD': 'http://128.199.160.37:8001/flags/SRB.png',
'BHD': 'http://128.199.160.37:8001/flags/BHR.png',
'JPY': 'http://128.199.160.37:8001/flags/JPN.png',
'SDG': 'http://128.199.160.37:8001/flags/SDN.png',
'XAF': '',
'EEK': '',
'XDR': '',
'XOF': '',
'ANG': '',
'BTC': '',
'XPF': '',
'ZMK': '',
'JEP': '',
'CLF': '',
'IMP': '',
'CUC': '',
'EUR': '',
'XCD': '',
'XAG': '',
'RON': '',
'GTQ': '',
'XAU': ''}

insertNewRate = "INSERT INTO exchange_rate (base_banknote_code, rate_banknote_code, image_link, rate) VALUES(%s, %s, %s, %s);"
for i in range(0,len(data),3):
	value = (data[i], data[i+1], banknote_country[data[i+1]], data[i+2])
	cursor.execute(insertNewRate, value)
db.commit()
db.close()