🤬
  • ■ ■ ■ ■ ■
    changedetectionio/content_fetcher.py
    skipped 20 lines
    21 21   self.page_text = html_tools.html_to_text(page_html)
    22 22   return
    23 23   
    24  - 
    25 24  class JSActionExceptions(Exception):
    26 25   def __init__(self, status_code, url, screenshot, message=''):
    27 26   self.status_code = status_code
    skipped 175 lines
    203 202   
    204 203   # Will be needed in the future by the VisualSelector, always get this where possible.
    205 204   screenshot = False
     205 + element_screenshot = None
    206 206   system_http_proxy = os.getenv('HTTP_PROXY')
    207 207   system_https_proxy = os.getenv('HTTPS_PROXY')
    208 208   
    skipped 102 lines
    311 311   request_body,
    312 312   request_method,
    313 313   ignore_status_codes=False,
    314  - current_css_filter=None):
     314 + current_css_filter=None
     315 + ):
    315 316   
    316 317   from playwright.sync_api import sync_playwright
    317 318   import playwright._impl._api_types
    skipped 87 lines
    405 406   self.status_code = response.status
    406 407   self.headers = response.all_headers()
    407 408   
    408  - if current_css_filter is not None:
     409 + if current_css_filter is not None and len(current_css_filter):
    409 410   page.evaluate("var css_filter={}".format(json.dumps(current_css_filter)))
     411 + 
     412 + el = page.locator(current_css_filter)
     413 + if el:
     414 + el.scroll_into_view_if_needed()
     415 + self.element_screenshot = el.screenshot()
    410 416   else:
    411 417   page.evaluate("var css_filter=''")
    412 418   
    skipped 209 lines
  • ■ ■ ■ ■ ■
    changedetectionio/fetch_processor/image.py
    skipped 76 lines
    77 77   proxy_args = self.set_proxy_from_list(watch)
    78 78   fetcher = klass(proxy_override=proxy_args)
    79 79   
    80  - fetcher.run(url, timeout, request_headers, request_body, request_method, ignore_status_codes)
     80 + fetcher.run(
     81 + ignore_status_codes=ignore_status_codes,
     82 + request_body=request_body,
     83 + request_headers=request_headers,
     84 + request_method=request_method,
     85 + current_css_filter=watch.get('css_filter'),
     86 + timeout=timeout,
     87 + url=url
     88 + )
     89 + 
    81 90   fetcher.quit()
    82 91   
    83 92   # if not image/foobar in mimetype
    skipped 5 lines
    89 98   if 'image' in fetcher.headers['content-type']:
    90 99   self.contents = fetcher.raw_content
    91 100   else:
    92  - # should be element if the filter is set, no?
    93  - self.contents = fetcher.screenshot
     101 + self.contents = fetcher.element_screenshot if fetcher.element_screenshot else fetcher.screenshot
    94 102   
    95 103   # Used for visual-selector
    96 104   self.xpath_data = fetcher.xpath_data
    97 105   self.screenshot = fetcher.screenshot
    98 106   
     107 + now = time.time()
    99 108   image = Image.open(io.BytesIO(self.contents))
    100 109   
    101 110   # @todo different choice?
    102 111   # https://github.com/JohannesBuchner/imagehash#references
    103 112   fetched_hash = str(imagehash.average_hash(image))
     113 + print(uuid, "Time to image hash", time.time() - now)
    104 114   
    105 115   # The main thing that all this at the moment comes down to :)
    106 116   if watch['previous_md5'] != fetched_hash:
    skipped 11 lines
  • ■ ■ ■ ■ ■ ■
    changedetectionio/image_diff.py
    skipped 5 lines
    6 6  # From https://www.pyimagesearch.com/2017/06/19/image-difference-with-opencv-and-python/
    7 7  def render_diff(fpath_imageA, fpath_imageB):
    8 8   
     9 + import time
     10 + now = time.time()
     11 + 
    9 12   imageA = cv2.imread(fpath_imageA)
    10 13   imageB = cv2.imread(fpath_imageB)
    11 14   
    skipped 25 lines
    37 40   cv2.rectangle(imageB, (x, y), (x + w, y + h), (0, 0, 255), 1)
    38 41   
    39 42   #return cv2.imencode('.jpg', imageB)[1].tobytes()
     43 + print ("Image comparison processing time", time.time()-now)
    40 44   return cv2.imencode('.jpg', imageA)[1].tobytes()
    41 45   
  • ■ ■ ■ ■ ■ ■
    changedetectionio/templates/watch-overview.html
    skipped 94 lines
    95 95   <a class="state-{{'on' if watch.notification_muted}}" href="{{url_for('index', op='mute', uuid=watch.uuid, tag=active_tag)}}"><img src="{{url_for('static_content', group='images', filename='bell-off.svg')}}" alt="Mute notifications" title="Mute notifications"/></a>
    96 96   </td>
    97 97   <td class="title-col inline">{{watch.title if watch.title is not none and watch.title|length > 0 else watch.url}}
    98  - <a class="external" target="_blank" rel="noopener" href="{{ watch.url.replace('source:','') }}"></a>
    99  - <a href="{{url_for('form_share_put_watch', uuid=watch.uuid)}}"><img style="height: 1em;display:inline-block;" src="{{url_for('static_content', group='images', filename='spread.svg')}}" /></a>
     98 + <a class="external" title="Open in new window" target="_blank" rel="noopener" href="{{ watch.url.replace('source:','') }}"></a>
     99 + <a href="{{url_for('form_share_put_watch', uuid=watch.uuid)}}"><img style="height: 1em;display:inline-block;" src="{{url_for('static_content', group='images', filename='spread.svg')}}" alt="Share" title="Share"/></a>
    100 100   
    101  - {%if watch.fetch_backend == "html_webdriver" %}<img style="height: 1em; display:inline-block;" src="{{url_for('static_content', group='images', filename='Google-Chrome-icon.png')}}" />{% endif %}
    102  - {%if watch.fetch_processor == "image" %}<img style="height: 1em; display:inline-block;" src="{{url_for('static_content', group='images', filename='picture-frame.svg')}}" />{% endif %}
     101 + {%if watch.fetch_backend == "html_webdriver" %}<img style="height: 1em; display:inline-block;" src="{{url_for('static_content', group='images', filename='Google-Chrome-icon.png')}}" alt="Fetching with Chrome" title="Fetching with Chrome"/>{% endif %}
     102 + {%if watch.fetch_processor == "image" %}<img style="height: 1em; display:inline-block;" src="{{url_for('static_content', group='images', filename='picture-frame.svg')}}" alt="Comparing graphically" title="Comparing graphically"/>{% endif %}
    103 103   {% if watch.last_error is defined and watch.last_error != False %}
    104 104   <div class="fetch-error">{{ watch.last_error }}</div>
    105 105   {% endif %}
    skipped 63 lines
Please wait...
Page is in error, reload to recover