def testWatchNotOdinEnv(self): r = random.randint(100000, 999999) test_desc = 'test_desc' + str(r) o = odin.Odin(config="job.yml", pathType="relative") o.watch(test_desc, True) result = self.collection.find_one({"desc": test_desc}) self.assertEqual(None, result)
def testWatch(self): r = random.randint(100000, 999999) test_desc = 'test_desc' + str(r) # test True sets odin exc env to true and in turn enables logging everything to the DB o = odin.Odin(test=True, config="job.yml", pathType="relative") o.watch(test_desc, True) result = self.collection.find_one({"desc": test_desc}) self.assertEqual(test_desc, result['desc'])
def test_watch_not_odin_env(self): """ Run watch operation outside of Odin Env """ random_int = random.randint(100000, 999999) test_desc = 'test_desc' + str(random_int) odin_test = odin.Odin(config="job.yml", path_type="relative") odin_test.watch(test_desc, True) result = self.collection.find_one({"description": test_desc}) self.assertEqual(None, result)
def test_watch(self): """ Run watch operation inside Odin Env """ random_int = random.randint(100000, 999999) test_desc = 'test_desc' + str(random_int) # test True sets odin exc env to true and in turn enables logging everything to the DB odin_test = odin.Odin(test=True, config="job.yml", path_type="relative") odin_test.watch(test_desc, True) result = self.collection.find_one({"description": test_desc}) self.assertEqual(test_desc, result['description'])
def main(): odin = pyodin.Odin(config="wiki.yml") fromMail = "odin@localhost" toMail = "*****@*****.**" odin.watch("Sender", fromMail) odin.watch("Receiver", toMail) msg = getURL(odin) msg['Subject'] = "Your Daily Wikipedia Article" msg['From'] = fromMail msg['To'] = toMail sendMail(msg, fromMail, toMail)
import requests from bs4 import BeautifulSoup as bs import pyodin odin = pyodin.Odin(config="amzn_stock.yml") r = requests.get('https://finance.yahoo.com/quote/AMZN?p=AMZN') if odin.condition("check request status", r.status_code == 200): soup = bs(r.content, 'lxml') for stock in soup.find_all( 'span', class_='Trsdu(0.3s) Trsdu(0.3s) Fw(b) Fz(36px) Mb(-4px) D(b)'): odin.watch("current price", stock.text) odin.result("success", "200") else: odin.result("failure", "500")
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0", "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8", "Accept-Language": "en-US,en;q=0.5", "Accept-Encoding": "gzip, deflate, br", "Upgrade-Insecure-Requests": "0", "Connection": "keep-alive" } # item url we want to monitor url = "http://www.currys.ie/ieen/computing-accessories/computer-accessories/headsets-and-microphones/advent-adm16-desktop-microphone-black-10140862-pdt.html" url2 = "http://www.currys.ie/ieen/computing-accessories/computer-accessories/headsets-and-microphones/blue-snowball-ice-microphone-white-11553760-pdt.html" if __name__ == "__main__": # setup odin o = odin.Odin(config="price_check.yml") try: # get html page contents pageBytes = requests.get(url2, headers=headers) pageContents = str(pageBytes.content) # parse with beautifulsoup soup = BeautifulSoup(pageContents, features="lxml") title = soup.find("meta", property="og:title")["content"] price = soup.find("meta", property="og:price:amount")["content"] o.watch('product price', price) o.watch('product title', title) o.condition('is in stock', ("Sorry this item is out of stock" in pageContents)) o.result("success", "200")
return pc1_sdist def main(): args = parse_args() try: usf_file = pyusf.Usf(args.ifile_name) except IOError, e: print_and_exit(str(e)) burst_list, pc1_rdist = usf_read(usf_file) rdist_sdist = comp_sdist(burst_list) pc1_sdist = comp_pc1_sdist(rdist_sdist, pc1_rdist) try: odin_file = pyodin.Odin() odin_file.create(args.ofile_name) except IOError, e: print_and_exit(str(e)) odin_write(odin_file, pc1_sdist) usf_file.close() odin_file.close() if __name__ == "__main__": main()
import requests import bs4 import pyodin odin = pyodin.Odin(config="scrape.yml") f = open("/home/odin/stats.txt", "a+") html = requests.get("http://dcufm.redbrick.dcu.ie").text data = bs4.BeautifulSoup(html, "lxml") table_row = data.find('body').find_all("tr")[2] listeners = table_row.find_all("td")[1].text odin.watch("current listeners", listeners) f.write( __import__("datetime").datetime.now().strftime('%Y-%m-%d (%H:%M:%S:%f) - ') + listeners + "\n") f.close()