-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckResults.py
80 lines (69 loc) · 2.9 KB
/
checkResults.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
from datetime import datetime, date
import requests
import json
import os
def checkResults(YOUR_POSTCODE):
# This is needed if executing file from outside of project root directory
dir = os.path.dirname(__file__)
response = requests.get('https://pickmypostcode.com/api/index.php/entry/').json()
drawResults = response['data']['drawResults']
mainDraw = drawResults['main']['result']
surveyDraw = drawResults['survey']['result']
videoDraw = drawResults['video']['result']
stackpotDraw = drawResults['stackpot']['result']
bonusDrawFive = drawResults['bonus']['five']['result']
bonusDrawTen = drawResults['bonus']['ten']['result']
bonusDrawTwenty = drawResults['bonus']['twenty']['result']
miniDraw = drawResults['mini']['result']
hasWon = any([mainDraw == YOUR_POSTCODE, surveyDraw == YOUR_POSTCODE, videoDraw == YOUR_POSTCODE, YOUR_POSTCODE in stackpotDraw, bonusDrawFive == YOUR_POSTCODE, bonusDrawTen == YOUR_POSTCODE, bonusDrawTwenty == YOUR_POSTCODE, miniDraw == YOUR_POSTCODE])
results = {
'hasWon': hasWon,
'drawResults': {
'mainDraw': {
'hasWon': mainDraw == YOUR_POSTCODE,
'winningPostcode': mainDraw
},
'surveyDraw': {
'hasWon': surveyDraw == YOUR_POSTCODE,
'winningPostcode': surveyDraw
},
'videoDraw': {
'hasWon': videoDraw == YOUR_POSTCODE,
'winningPostcode': videoDraw
},
'stackpotDraw': {
'hasWon': YOUR_POSTCODE in stackpotDraw,
'winningPostcode': stackpotDraw
},
'bonusDrawFive': {
'hasWon': bonusDrawFive == YOUR_POSTCODE,
'winningPostcode': bonusDrawFive
},
'bonusDrawTen': {
'hasWon': bonusDrawTen == YOUR_POSTCODE,
'winningPostcode': bonusDrawTen
},
'bonusDrawTwenty': {
'hasWon': bonusDrawTwenty == YOUR_POSTCODE,
'winningPostcode': bonusDrawTwenty
},
'miniDraw': {
'hasWon': miniDraw == YOUR_POSTCODE,
'winningPostcode': miniDraw
}
}
}
# Update database with current results & remove data older than 10 days
with open(f'{dir}/logs/pastData.json') as f:
pastData = json.load(f)
pastData[str(date.today())] = results
dataToDelete = []
for index, dateStr in enumerate(pastData.keys()):
if index != 0:
if (date.today() - datetime.strptime(dateStr, '%Y-%m-%d').date()).days >= 10:
dataToDelete.append(dateStr)
for key in dataToDelete:
del pastData[key]
with open(f'{dir}/logs/pastData.json', 'w') as f:
json.dump(pastData, f, indent=2)
return results