import re,winsound,random,sys
import threading,time,base64
import urllib.request as req
from bs4 import BeautifulSoup
from colorama import Fore, Back, Style,init

ctbl=[Fore.BLACK,Fore.LIGHTRED_EX,Fore.LIGHTGREEN_EX,Fore.LIGHTYELLOW_EX,\
Fore.LIGHTBLUE_EX,Fore.LIGHTMAGENTA_EX,Fore.LIGHTCYAN_EX,Fore.WHITE]
gtbl=[Back.BLACK,Back.LIGHTRED_EX,Back.LIGHTGREEN_EX,Back.LIGHTYELLOW_EX,\
Back.LIGHTBLUE_EX,Back.LIGHTMAGENTA_EX,Fore.LIGHTCYAN_EX,Back.WHITE]
    
def cls():
    print('\x1b[2J')
def display(x, y, text):   
    sys.stdout.write("\x1b[%d;%df%s" % (y, x, text))
    sys.stdout.flush()

def color(c):
    b=c>>4
    f=c&15
    print(ctbl[f])
    print(gtbl[b])

def beep(f):
    winsound.Beep(frequency=f,duration=1000 )

def play(fn)
    winsound.PlaySound(fn, winsound.SND_FILENAME)
        
c=b'aHR0cHM6Ly9maW5hbmNlLm5hdmVyLmNvbS8vbWFya2\
    V0aW5kZXgvZXhjaGFuZ2VEZWdyZWVDb3VudFF1b3Rl\
    Lm5hdmVyP21hcmtldGluZGV4Q2Q9RlhfVVNES1JX'

x=b'aHR0cHM6Ly9maW5hbmNlLm5hdmVyLmNvbS9tYXJrZX\
    RpbmRleC93b3JsZEV4Y2hhbmdlRGV0YWlsLm5hdmV\
    yP21hcmtldGluZGV4Q2Q9RlhfVVNEWA=='

u1=base64.b64decode(c).decode("utf8")
u2=u1+"_SHB"
usdx=base64.b64decode(x).decode("utf8")

def bank(sel):
    global url
    url=sel+"&page="+"1"

def dxy():
    res = req.urlopen(usdx)
    soup = BeautifulSoup(res, "html.parser")
    slist=soup.select_one(".no_down").get_text()
    slist =slist.replace("\n", "")
    val=float(slist)
    return val
   
def read_fx():
    res = req.urlopen(url)
    soup = BeautifulSoup(res, "html.parser")
    slist=soup.find("tbody").find_all("tr")
    td=[]
    for a in slist:
        td.append(a.text)
    table = str.maketrans('\t', ' ') 
    fx=td[0].split("\n");
    val=float(fx[2].replace(",",""))
    return val
  
def read_sim(base,range):
    r=random.randrange(-range,range);
    fx=base+r;
    return fx
init()    
bank(u1)
class 환:
    율=0
환.율=read_fx()
def th():
    while (True):
        환.율=read_fx()
        time.sleep(120)
 
t1 = threading.Thread(target=th,args=()) 
t1.daemon = True 
t1.start()




    