Repository navigation
Expand file tree
/
Copy pathfunc.py
More file actions
71 lines (55 loc) · 1.86 KB
/
Copy pathfunc.py
File metadata and controls
71 lines (55 loc) · 1.86 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import json
import requests
import pytz, datetime
tz = pytz.timezone("Europe/London")
def jprint(obj):
# create a formatted string of the Python JSON object
text = json.dumps(obj, sort_keys=True, indent=4)
print(text)
def getGenerationMix(dict, wanted):
dataout = []
for d in dict["generationmix"]:
if d["fuel"] in wanted:
dataout.append(d)
return dataout
def getGenerationMixTotal(dataIn):
return sum(c["perc"] for c in dataIn)
def getGenerationMixTotalForSlot(slotData, wanted):
genMix = getGenerationMix(slotData, wanted)
genMixWanted = getGenerationMixTotal(genMix)
return genMixWanted
def shouldAdjustTimeForBST():
return (
True
if tz.utcoffset(datetime.datetime.now().now()).total_seconds() > 0
else False
)
def getStartAndEndDates():
startHour = 1 if shouldAdjustTimeForBST() else 0
dateNowUTC = datetime.datetime.now(datetime.timezone.utc).replace(
hour=startHour, minute=0, second=0, microsecond=0
)
dateEndUTC = dateNowUTC + datetime.timedelta(days=5)
return dateNowUTC, dateEndUTC
def getSlotName(datein):
adjust = shouldAdjustTimeForBST()
date = datetime.datetime.strptime(datein, "%Y-%m-%dT%H:%MZ")
if adjust:
if date.hour >= 0 and date.hour < 6:
return "night"
if date.hour >= 6 and date.hour < 12:
return "morning"
if date.hour >= 12 and date.hour < 18:
return "afternoon"
if date.hour >= 18 and date.hour <= 23:
return "evening"
else:
if date.hour >= 0 and date.hour < 5:
return "night"
if date.hour >= 5 and date.hour < 11:
return "morning"
if date.hour >= 11 and date.hour < 17:
return "afternoon"
if date.hour >= 17 and date.hour <= 23:
return "evening"
return False