Herorahim
Cracker/Developer
Member
Python 3.0 için Test Edilmişdir
bunlar da döviz verisini internetten alıp yazdırmak için kodlar
Code:
print("Döviz Uygulaması")
print("""
1 = Azn -> Try
2 = Try -> Azn
3 = Try -> Usd
""")
islem = input(" Kullanıcağınız İşlevi Seçin ")
if islem == "1":
azn1 = int(input("Kaç Azn: "))
azns = top1 * 3,49
print("Sonuç = ",azns)
elif islem == "2":
try1 = int(input("Kaç Try: "))
trys = cik1 * 0.29
print("Sonuç = ",trys)
elif islem == "3":
usd1 = int(input("Kaç Try: "))
usds = usd1 * 0.17
print("Sonuç = ",usds)
bunlar da döviz verisini internetten alıp yazdırmak için kodlar
Code:
import configparser
import json
import ssl # ssl hatasını handle'lamak için (yoksayarak :))
from urllib.request import urlopen
from urllib.error import URLError
from os.path import realpath, dirname
def main ():
config = configparser.ConfigParser ()
config.read (realpath (dirname (__file__)) + "/doviz.conf") # her zaman yanımızda olmalı.
apiKey = config["API"]["Key"]
apiLoc = config["API"]["Loc"]
apiMode = config["API"]["Mode"].split (',') # çoklu birim dönüştürmeyi de destekliyor.
apiTimeout = int (config["API"]["Timeout"])
fullApiUrl = "{}?q={}&apiKey={}"
for mode in apiMode:
try:
with urlopen (fullApiUrl.format (apiLoc, mode, apiKey), timeout=apiTimeout) as request:
response = request.read ().decode ("utf-8")
except URLError:
print ("Bir hata oluştu. Veri alınamadı.")
exit ()
result = json.loads (response)
res = result["results"][mode]
print ("{} = {} {}".format (res["fr"], res["val"], res["to"]))
if __name__ == "__main__":
ssl._create_default_https_context = ssl._create_unverified_context
main ()