-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEsemeyenSinif.py
58 lines (54 loc) · 2.34 KB
/
EsemeyenSinif.py
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
import logging
import json
import requests
def connected_to_internet(url='http://www.google.com/', timeout=5):
try:
_ = requests.get(url, timeout=timeout)
return True
except requests.ConnectionError:
print("No internet connection available.")
input("try again?")
connected_to_internet()
return False
connected_to_internet()
FORMAT='[%(asctime)s] [%(levelname)s] [%(message)s]'
logging.basicConfig(filename="logs.log", format=FORMAT, level=logging.INFO)
class Havalar():
sehir = None
def init(self):
pass
def get_info(self,sehir):
self.sehir = sehir
try:
data = json.loads(requests.get("http://api.openweathermap.org/data/2.5/weather?q={id}&appid=fe76c224322cdde0049342cb45d26b04".format(id=sehir)).content.decode('utf-8'))
if data.get("cod")==200:
return data
else:
print("Invalid city name!!")
logging.warning("Api Olumlu cevap vermedi. Cevap: {}".format(data))
return None
except:
logging.Error("Hava Durumu API hiç çalışmadı..")
print("Error: Can not reach ")
def auto_get(self):
try:
logging.info("1. API (ipapi) deneniyor..")
data = json.loads(requests.get("https://ipapi.co/json").content.decode('utf-8')).get("city")
logging.info("Gelen Veri: {}".format(data))
if data == None:
logging.warning("1. API (ipapi) Data vermedi..")
logging.info("2. API (ip-api) deneniyor..")
data = json.loads(requests.get("http://ip-api.com/json").content.decode('utf-8')).get("city")
logging.info("Gelen Veri: {}".format(data))
if data == None:
logging.warning("2. API (ip-api) Data vermedi..")
logging.info("3. API (extreme-ip-lookup) deneniyor..")
data = json.loads(requests.get("http://extreme-ip-lookup.com/json/").content.decode('utf-8')).get("city")
logging.info("Gelen Veri: {}".format(data))
self.sehir = data
return data
except:
logging.Error("Konum API hiç çalışmadı.")
print("İnternet Bağlatınızı Kontrol Edin.")
logging.info("Uygulama Kapatılıyor")
exit()