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")
def sendCaseEmail(case): global CASE, STOP caseinfo = case.information + '\n \n' + case.url + \ '\n Time Found: \n' + case.time print("DECIDED") headerCase = "Decision Made for {} Made".format(case.decision) logging.info(headerCase) logging.info(caseinfo) sendEmail(headerCase, caseinfo) if case == "Trump v. Hawaii": STOP = True
def checkStatus(): global DECIDED, SENT, LASTDECIDED, STOP, t, CASE 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?')) ] print(len(caseDecisions)) DECIDEDINX = next((index for index, dictItem in enumerate(caseDecisions) if LASTDECIDED == dictItem.decision), -1) LASTDECIDED = caseDecisions[0].decision decidedList = [] # os.system('clear') if DECIDEDINX > 1: decidedList = caseDecisions[0:DECIDEDINX] if CASE != LASTDECIDED: if not decidedList: sendCaseEmail(caseDecisions[0]) else: [sendCaseEmail(case) for case in decidedList] LASTDECIDED, CASE = caseDecisions[0].decision, caseDecisions[ 0].decision except Exception as e: print(e) time.sleep(45) logging.warn(e) sendEmail("Exception Raised on Check Other url track Court", e) pass t = threading.Timer(45, checkStatus) t.start() if STOP: print("stop search") logging.warn("Stop search") t.cancel()
def on_data(self, data): global Collected fname = "statuesStream.txt" if os.path.isfile(fname): with open("statuesStream.txt", "a") as myfile: myfile.write(data + "\n") Collected += 1 if Collected % 1000 == 0: msg = "Collected {} tweets so far".format(Collected) print(msg) sendEmail(msg, msg) else: with open("statuesStream.txt", "w") as myfile: myfile.write(data + "\n") sendEmail("Twitter Stream Started", "Started") print("start") Collected += 1 return True def on_disconnect(self, notice): sendEmail("Error with Twitter Disconnect", notice) print(notice) return def on_warning(self, notice): sendEmail("Warning Triggered", notice) print(notice) return def on_error(self, status_code): sendEmail("Error with Twitter Stream", status_code) print(status_code) if status_code == 420: return False def on_exception(self, exception): sendEmail("Error with Twitter Exception Thrown", exception) print(exception) return
SENT = True STOP = True elif SENT: print("Decided") pass else: logging.info("Last logged Case: {}".format(LASTDECIDED)) print("\nNot Decided yet, As of: ") print(str(datetime.now()), "\n") print("Last Decided Case was: ", LASTDECIDED) pass except Exception as e: print(e) time.sleep(3) sendEmail("Exception Raised on url track Court", e) logging.warn(e) pass t = threading.Timer(45, checkStatus) t.start() if STOP: print("stop search") t.cancel() twitterStream.startStream() t = threading.Timer(45, checkStatus) t.start()
def on_exception(self, exception): sendEmail("Error with Twitter Exception Thrown", exception) print(exception) return
def on_error(self, status_code): sendEmail("Error with Twitter Stream", status_code) print(status_code) if status_code == 420: return False
def on_warning(self, notice): sendEmail("Warning Triggered", notice) print(notice) return
def on_disconnect(self, notice): sendEmail("Error with Twitter Disconnect", notice) print(notice) return