Home crawling-task-5
Post
Cancel

crawling-task-5

환전 금액 알아보기

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import os
import requests
from bs4 import BeautifulSoup

os.system("clear")

"""
Use the 'format_currency' function to format the output of the conversion
format_currency(AMOUNT, CURRENCY_CODE, locale="ko_KR" (no need to change this one))
"""

url = "https://www.iban.com/currency-codes"

res = requests.get(url)
tbody = BeautifulSoup(res.text, "html.parser").find("tbody").find_all("td")
num = 0
db = []
matchdb = {}

def match():
  url = 'https://justforex.com/ko/education/currencies'
  res = requests.get(url)
  form = BeautifulSoup(res.text, "html.parser").find_all("td")[0::5]
  symbol = BeautifulSoup(res.text, "html.parser").find_all("td")[1::5]
  for i in range(len(form)):
    matchdb[form[i].get_text()] = symbol[i].get_text()

print('Welcome to CurrencyConvert PRO 2000\n')
for i in range(0,len(tbody),4):
  if tbody[i+2].get_text() != '':
    country = tbody[i].get_text().capitalize()
    code = tbody[i+2].get_text()
    item = [ 
      country,
      code
    ]
    print(f'#{num} {country}')
    num += 1
    db.append(item)
print()

def dialogue():
  match()
  try:
    print('Where are you from? Choose a country by number.\n')
    original = int(input('#: '))
    if original <= len(db) -1:
      print(f'{db[original][0]}\n')
    else:
      print('Choose a number from the list.\n')
      dialogue()

    print('Choose the country by number where you want to exchange money.\n')
    after = int(input('#: '))
    if after <= len(db) -1:
      print(f'{db[after][0]}\n')
    else:
      print('Choose a number from the list.\n')
      dialogue()

    print(f'How many {db[original][1]} do you want to covert to {db[after][1]}?')
    amount = float(input())
    print()

    url2 = f'https://wise.com/gb/currency-converter/{db[original][1].lower()}-to-{db[after][1].lower()}-rate?amount=50'
    res2 = requests.get(url2)
    rate = float(BeautifulSoup(res2.text, "html.parser").find('span',{'class': 'text-success'}).get_text())
    oriamt = format(amount,',')
    amt = format(rate * amount,',')

    print(f'{db[original][1]} {oriamt} is {matchdb[db[after][1]]}{amt}')
  except:
    print('That wasn`t number.\n')
    dialogue()

dialogue()

메모

  • 4번 작업의 결과인 국가별 리스트 인덱스에 추가 작업
  • 기준국 환전국 입력 및 금액 입력
    • 환전된 금액 표시
This post is licensed under CC BY 4.0 by the author.