-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsunset.py
More file actions
56 lines (45 loc) · 1.58 KB
/
Copy pathsunset.py
File metadata and controls
56 lines (45 loc) · 1.58 KB
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
# Bitte vorher installieren:
# $ pip install requests
import re
import requests
import time
from datetime import datetime
class SunSet:
@staticmethod
def get_api():
print()
@staticmethod
def get_sunrise():
regex = r"\"sunrise\":(\d+),"
answer = requests.get(
'https://api.openweathermap.org/data/2.5/weather?id=6557397&APPID=d3bb270e740c32655f9f0441805047f5')
test_str = answer.text
matches = re.search(regex, test_str)
return int(matches.groups(0)[0])
@staticmethod
def get_sunset():
regex = r"\"sunset\":(\d+)}"
answer = requests.get(
'https://api.openweathermap.org/data/2.5/weather?id=6557397&APPID=d3bb270e740c32655f9f0441805047f5')
input_str = answer.text
matches = re.search(regex, input_str)
return int(matches.groups(0)[0])
@staticmethod
def is_day(time):
bol=False
#print("R:"+str(SunSet.get_sunrise()))
#print("S:"+str(SunSet.get_sunset()))
#print("N:"+str(time))
sunriseFake=datetime.fromtimestamp(SunSet.get_sunrise()).replace(hour=7, minute=0).timestamp()
sunsetFake=datetime.fromtimestamp(SunSet.get_sunset()).replace(hour=21,minute=0).timestamp()
#print("FR:"+str(sunriseFake))
#print("FS:"+str(sunsetFake))
if SunSet.get_sunrise() > time:
bol= False
if SunSet.get_sunrise() <= time < SunSet.get_sunset():
bol= True
if time < sunriseFake:
bol= False
if time > sunsetFake:
bol= False
return bol