webcheck-strings 1.601__tar.gz → 1.604__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: webcheck_strings
3
- Version: 1.601
3
+ Version: 1.604
4
4
  Summary: Monitor text strings on websites
5
5
  Home-page: http://ssb22.user.srcf.net/setup/webcheck.html
6
6
  Author: Silas S. Brown
@@ -1,4 +1,4 @@
1
- from setuptools import setup, find_packages;setup(name='webcheck_strings',version='1.601',entry_points={'console_scripts':['webcheck=webcheck.__init__:main']},license='Apache 2',platforms='any',url='http://ssb22.user.srcf.net/setup/webcheck.html',author='Silas S. Brown',author_email='ssb22@cam.ac.uk',description='Monitor text strings on websites',long_description=r'''WebCheck
1
+ from setuptools import setup, find_packages;setup(name='webcheck_strings',version='1.604',entry_points={'console_scripts':['webcheck=webcheck.__init__:main']},license='Apache 2',platforms='any',url='http://ssb22.user.srcf.net/setup/webcheck.html',author='Silas S. Brown',author_email='ssb22@cam.ac.uk',description='Monitor text strings on websites',long_description=r'''WebCheck
2
2
  ========
3
3
 
4
4
  From http://ssb22.user.srcf.net/setup/webcheck.html
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env python
2
2
  # (compatible with both Python 2 and Python 3)
3
3
 
4
- # webcheck.py v1.601 (c) 2014-24 Silas S. Brown.
4
+ """webcheck.py v1.604 (c) 2014-25 Silas S. Brown.
5
+ License: Apache 2""" # (see below)
5
6
  # See webcheck.html for description and usage instructions
6
7
 
7
8
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -103,6 +104,7 @@ def read_input():
103
104
  days = 0 ; extraHeaders = []
104
105
  url = mainDomain = None
105
106
  lines = read_input_file()
107
+ if not lines: print ("No input found")
106
108
  lastList = None # refs a list within ret, of [(days,text,elseLogic)]
107
109
  while lines:
108
110
  line = line_withComment = " ".join(lines.pop().split())
@@ -271,7 +273,7 @@ class Delayer:
271
273
  def __init__(self,mainDomain):
272
274
  self.last_fetch_finished = 0
273
275
  if mainDomain=="stackoverflow.com":
274
- # (or other Stack Exchange sites)
276
+ # (or other Stack Exchange sites as normalised to stackoverflow.com above) (although in 2024-12 I was able to confirm that Stack Exchange's own email notifications of others' edits to your answers _did_ work, so it might not be necessary to monitor for vandalism all your Stack Exchange answers from webcheck)
275
277
  self.delay = 80 # seconds between fetches to these sites
276
278
  else: self.delay = 3 # (want small if checking many pages and the server doesn't mind, but still non-0)
277
279
  def wait(self):
@@ -403,9 +405,9 @@ def doJob(opener,delayer,url,checklist,extraHeaders):
403
405
  textContent = None
404
406
  delayer.done()
405
407
  if content==None: return # not modified (so nothing to report), or problem retrieving (which will have been reported by tryRead0: TODO: return failRet in these circumstances so elseLogic can proceed?)
406
- if B(content).startswith(B("<!DOCTYPE html>")):
408
+ if B(content).startswith(B("<!DOCTYPE html>")) or B(content).startswith(B('<html lang=')): # check for CloudFlare backoff
407
409
  textContent,errmsg=htmlStrings(content)
408
- if B(textContent)==B("Just a moment... Enable JavaScript and cookies to continue"): raise CDNBackoff() # might not be able to check the rest of this domain today (at least not without starting a webdriver, but for things like 'checking if my StackExchange answers have been vandalised' the site probably doesn't want too many automated fetches; would be easier if they provided an RSS feed for each user)
410
+ if B(textContent).startswith(B("Just a moment...")) and B("Enable JavaScript and cookies to continue") in B(textContent): raise CDNBackoff() # might not be able to check the rest of this domain today
409
411
  if u:
410
412
  lm = u.info().get("Last-Modified",None)
411
413
  if lm: previous_timestamps[(url,'lastMod')] = lm
@@ -466,6 +468,8 @@ def run_webdriver(ua,actionList,reportErrors):
466
468
  return B(""), True
467
469
  r = "" ; wasError = False
468
470
  try: r = run_webdriver_inner(actionList,browser)
471
+ except CDNBackoff:
472
+ browser.quit() ; raise
469
473
  except NoTracebackException as e:
470
474
  if reportErrors: print (e.message)
471
475
  else: wasError = True
@@ -503,16 +507,20 @@ def run_webdriver_inner(actionList,browser):
503
507
  return f(browser).encode('utf-8')
504
508
  snippets = []
505
509
  for a in actionList:
506
- if a.startswith('http'): browser.get(a)
510
+ if a.startswith('http'):
511
+ try: browser.get(a)
512
+ except: raise NoTracebackException("webdriver low-level timeout or error fetching "+a) # e.g. selenium.common.exceptions.TimeoutException
507
513
  elif a.startswith('"') and a.endswith('"'):
508
514
  # wait for "string" to appear in the source
509
515
  tries = 30
510
516
  while tries and not myFind(a[1:-1],getSrc()):
511
517
  time.sleep(2) ; tries -= 1
512
518
  if not tries:
519
+ src = getSrc() ; h=B(htmlStrings(src)[0])
520
+ if h.startswith(B("Just a moment...")) and B("Enable JavaScript and cookies to continue") in h: raise CDNBackoff() # 2024-07: can occur even in webdriver, even though that has JS + cookies
513
521
  try: current_url = browser.current_url
514
522
  except: current_url = "(unable to obtain)"
515
- raise NoTracebackException("webdriver timeout while waiting for %s, current URL is %s content \"%s\"\n" % (repr(a[1:-1]),current_url,repr(getSrc()))) # don't quote current URL: if the resulting email is viewed in (at least some versions of) MHonArc, a bug can result in &quot being added to the href
523
+ raise NoTracebackException("webdriver timeout while waiting for %s, current URL is %s content \"%s\"\n" % (repr(a[1:-1]),current_url,repr(src))) # don't quote current URL: if the resulting email is viewed in (at least some versions of) MHonArc, a bug can result in &quot being added to the href
516
524
  elif a.startswith('[') and a.endswith(']'): # click
517
525
  findElem(a[1:-1]).click()
518
526
  elif a.startswith('/') and '/' in a[1:]: # click through items in a list to reveal each one (assume w/out Back)
@@ -545,7 +553,7 @@ def run_webdriver_inner(actionList,browser):
545
553
  if sys.stderr.isatty(): sys.stderr.write('*'),sys.stderr.flush()
546
554
  except:
547
555
  if sys.stderr.isatty(): sys.stderr.write('?'),sys.stderr.flush()
548
- if propagate_errors: raise NoTracebackException(a+" failed to open instance "+str(curNo))
556
+ if propagate_errors: raise NoTracebackException(a+" failed to open instance "+str(curNo)+" (error because ! is set)")
549
557
  else: continue
550
558
  time.sleep(delayAfter)
551
559
  snippets.append(getSrc())
@@ -569,7 +577,7 @@ def run_webdriver_inner(actionList,browser):
569
577
  if sys.stderr.isatty(): sys.stderr.write('*'),sys.stderr.flush() # webdriver's '.' for click-multiple
570
578
  except:
571
579
  if sys.stderr.isatty(): sys.stderr.write('?'),sys.stderr.flush()
572
- if propagate_errors: raise NoTracebackException(a+" failed to open instance "+str(curNo))
580
+ if propagate_errors: raise NoTracebackException(a+" failed to open instance "+str(curNo)+" (error because ! is set)")
573
581
  else: continue
574
582
  time.sleep(delayAfter)
575
583
  snippets.append(getSrc())
@@ -843,4 +851,7 @@ def normalisePunc(t):
843
851
  ]: t=t.replace(s,r)
844
852
  return re.sub(B(r"(\s)\s+"),B(r"\1"),t).lower()
845
853
 
846
- if __name__=="__main__": main()
854
+ if __name__=="__main__":
855
+ if "--version" in sys.argv: print(__doc__)
856
+ elif "--help" in sys.argv: print("python webcheck.py [--single-thread] [--test-all] [--show-seen-rss] | --help | --version")
857
+ else: main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: webcheck-strings
3
- Version: 1.601
3
+ Version: 1.604
4
4
  Summary: Monitor text strings on websites
5
5
  Home-page: http://ssb22.user.srcf.net/setup/webcheck.html
6
6
  Author: Silas S. Brown