killerbng icon

RU Info

killerbng | PRO | 03/05/15 02:49:09 PM UTC | 0 ⭐ | 534 👁️ | Never ⏰ | []
Python |

1.07 KB

|

None

|

0 👍

/

0 👎

import requests
import json
from datetime import datetime
from pytz import timezone
import pytz
 
def get_currency_convertion():
    url = "http://www.freecurrencyconverterapi.com/api/v3/convert?q=USD_RUB&compact=y"
    response = requests.get(url)
    data = response.content
    data = json.loads(data.decode())
    print("$1 USD -> " + str(data["USD_RUB"]['val']) + " RUB")
 
def check_hour(n):
    if n >= 24:
        if n == 24:
            n = "0"
        else:
            n = n - 24
    else:
        n = n
    return n
 
def check_minute(n):
    for i in range(0,10):
        if i == n:
            n = "0" + str(n)
    return n
 
def get_time():
    now = datetime.now()
    fmt = '%Y-%m-%d %H:%M:%S'
    eastern = timezone('US/Eastern')
    moscow = timezone('Europe/Moscow')
    loc_dt = eastern.localize(datetime(now.year, now.month, now.day, now.hour, now.minute, now.second))
    moscow_dt = loc_dt.astimezone(moscow)
    moscow_dt.strftime(fmt)
    print("Date - Time")
    print(moscow_dt)
 
 
get_time()
print("\n")
get_currency_convertion()

Comments