MOHAN KRISHNA

0 %
Mohan Krishna
Multimedia Professional
Ai & ML Researcher & Enthusiast
  • Residence:
    India
  • City:
    Vijayawada
  • Age:
    46
AI/ML Enthusiast. New Media Trainer, VFX Artist, Non Linear Video Editor, Graphic Designer, Sound Editor and iOS App Designer.
Telugu
English
Hindi
Tamil
Proficiency:
Graphic Design
Web Design
Video & VFX
Machine Learning
Artificial Intelligence
Digital Marketing
Areas of Interest:
Take a look at some of the things I love working on.
  • Non Linear Video Editing
  • Graphic Design
  • Web Design
  • Audio Editing
  • Content Management Systems
  • Python
  • Deep Learning
  • OpenCV
  • Image Classification

Currency Exchange Rates

September 26, 2022
from bs4 import BeautifulSoup
import requests as req
# http://www.pillalamarri.in/python/currency-exchange-rates/
currencies = []

page = req.get('https://www.x-rates.com/').text

soup = BeautifulSoup(page, 'html.parser')

options = soup.find_all('option')[:-11]

for option in options:
    currency_short = option.text[:(option.text.find(" "))]
    currency_name = option.text[(option.text.find(" ") + 3):]
    current_element = {'name': currency_name, 'short': currency_short}
    currencies.append(current_element)
    print('{}. {} ({})'.format(len(currencies), current_element['name'],
                               current_element['short']))

currency_index = int(input('Enter your currency\'s position number: ')) - 1
currency = currencies[currency_index]
amount = input(
    '\033cEnter amount of {}s (if amount isn\'t integer, then write it with a dot, not comma): '
    .format(currency['name'].lower()))

currencies_table_url = 'https://www.x-rates.com/table/?from={}&amount={}'.format(
    currency['short'], amount)

currencies_table_page = req.get(currencies_table_url).text

soup = BeautifulSoup(currencies_table_page, 'html.parser')

table_rows = soup.findChild('table', attrs={
    'class': 'tablesorter'
}).findChildren('tr')[1:]

print('\033cFor {} {}s you\'ll get:'.format(amount, currency['name'].lower()))

for table_row in table_rows:
    row_data = table_row.findChildren('td')
    exchange_rate = {
        'currency': row_data[0].text,
        'amount': float(row_data[1].text)
    }
    print('{:.3f} {}s'.format(exchange_rate['amount'],
                              exchange_rate['currency']))
# http://www.pillalamarri.in/python/currency-exchange-rates/
Posted in PythonTags: