-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckStatus.py
89 lines (63 loc) · 2.01 KB
/
checkStatus.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
81
82
83
84
85
86
87
88
89
import os
import bs4
import threading
import requests
import re
from emailDecision import sendEmail
from datetime import datetime
URL = "https://www.supremecourt.gov/opinions/slipopinion/17"
CASE = "Trump v. Hawaii"
t = None
SENT = False
DECIDED = False
LASTDECIDED = ""
class DecisionInfo:
def __init__(self, data):
caseInfo = {
"decision": "No Title",
"information": "No information",
"url": "No URL",
"time": str(datetime.now())
}
try:
caseInfo["decision"] = data.text
except:
pass
try:
caseInfo["url"] = "https://www.supremecourt.gov/" + data["href"]
except:
pass
try:
caseInfo["information"] = data["title"].encode('ascii', 'ignore').decode('ascii')
except:
pass
for key, value in caseInfo.items():
setattr(self, key, value)
def checkStatus():
global DECIDED, SENT, LASTDECIDED
try:
res = requests.get(URL)
caseSoup = bs4.BeautifulSoup(res.text,'html.parser')
caseDecisions = [DecisionInfo(a) for a in caseSoup.findAll('a', href=re.compile(r'^/opinions/17pdf?'))]
LASTDECIDED = caseDecisions[0].decision
os.system('clear')
if any(case.decision == CASE for case in caseDecisions) and not SENT:
case = [case for case in caseDecisions if case.decision == CASE][0]
caseinfo = case.information + '\n \n' + case.url + \
'\n Time Found: \n' + case.time
print("DECIDED")
DECIDED = True
sendEmail(CASE, caseinfo)
SENT = True
elif SENT:
print("Decided")
else:
print("\nNot Decided yet, As of: ")
print(str(datetime.now()), "\n")
print("Last Decided Case was: ", LASTDECIDED)
except Exception as e:
print(e)
pass
t = threading.Timer(30, checkStatus)
t.start()
checkStatus()