■ ■ ■ ■ ■ ■
changedetectionio/fetch_site_status.py
| skipped 19 lines |
20 | 20 | | super().__init__(*args, **kwargs) |
21 | 21 | | self.datastore = datastore |
22 | 22 | | |
23 | | - | # If there was a proxy list enabled, figure out what proxy_args/which proxy to use |
24 | | - | # Returns the proxy as a URL |
25 | | - | # if watch.proxy use that |
26 | | - | # fetcher.proxy_override = watch.proxy or main config proxy |
27 | | - | # Allows override the proxy on a per-request basis |
28 | | - | # ALWAYS use the first one is nothing selected |
29 | | - | |
30 | | - | def set_proxy_from_list(self, watch): |
31 | | - | proxy_args = None |
32 | | - | if self.datastore.proxy_list is None: |
33 | | - | return None |
34 | | - | |
35 | | - | # If its a valid one |
36 | | - | if watch['proxy'] and watch['proxy'] in list(self.datastore.proxy_list.keys()): |
37 | | - | proxy_args = self.datastore.proxy_list.get(watch['proxy']).get('url') |
38 | | - | |
39 | | - | # not valid (including None), try the system one |
40 | | - | else: |
41 | | - | system_proxy = self.datastore.data['settings']['requests']['proxy'] |
42 | | - | # Is not None and exists |
43 | | - | if self.datastore.proxy_list.get(system_proxy): |
44 | | - | proxy_args = self.datastore.proxy_list.get(system_proxy).get('url') |
45 | | - | |
46 | | - | # Fallback - Did not resolve anything, use the first available |
47 | | - | if proxy_args is None: |
48 | | - | first_default = list(self.datastore.proxy_list)[0] |
49 | | - | proxy_args = self.datastore.proxy_list.get(first_default).get('url') |
50 | | - | |
51 | | - | return proxy_args |
52 | | - | |
53 | 23 | | # Doesn't look like python supports forward slash auto enclosure in re.findall |
54 | 24 | | # So convert it to inline flag "foobar(?i)" type configuration |
55 | 25 | | def forward_slash_enclosed_regex_to_options(self, regex): |
| skipped 58 lines |
114 | 84 | | # If the klass doesnt exist, just use a default |
115 | 85 | | klass = getattr(content_fetcher, "html_requests") |
116 | 86 | | |
117 | | - | proxy_url = self.set_proxy_from_list(watch) |
118 | | - | if proxy_url: |
| 87 | + | proxy_id = self.datastore.get_preferred_proxy_for_watch(uuid=uuid) |
| 88 | + | proxy_url = None |
| 89 | + | if proxy_id: |
| 90 | + | proxy_url = self.datastore.proxy_list.get(proxy_id).get('url') |
119 | 91 | | print ("UUID {} Using proxy {}".format(uuid, proxy_url)) |
| 92 | + | |
120 | 93 | | fetcher = klass(proxy_override=proxy_url) |
121 | 94 | | |
122 | 95 | | # Configurable per-watch or global extra delay before extracting text (for webDriver types) |
| skipped 202 lines |