■ ■ ■ ■ ■ ■
changedetectionio/fetch_processor/__init__.py
| skipped 2 lines |
3 | 3 | | class fetch_processor(): |
4 | 4 | | contents = b'' |
5 | 5 | | screenshot = None |
| 6 | + | datastore = None |
6 | 7 | | |
7 | 8 | | """ |
8 | 9 | | base class for all fetch processors |
9 | 10 | | - json_html_plaintext |
10 | 11 | | - image (future) |
11 | 12 | | """ |
12 | | - | def __init__(self, *args, datastore, **kwargs): |
13 | | - | super().__init__(*args, **kwargs) |
14 | | - | self.datastore = datastore |
15 | | - | |
16 | | - | # If there was a proxy list enabled, figure out what proxy_args/which proxy to use |
17 | | - | # if watch.proxy use that |
18 | | - | # fetcher.proxy_override = watch.proxy or main config proxy |
19 | | - | # Allows override the proxy on a per-request basis |
20 | | - | # ALWAYS use the first one is nothing selected |
21 | | - | |
22 | | - | def set_proxy_from_list(self, watch): |
23 | | - | proxy_args = None |
24 | | - | if self.datastore.proxy_list is None: |
25 | | - | return None |
26 | | - | |
27 | | - | # If its a valid one |
28 | | - | if any([watch['proxy'] in p for p in self.datastore.proxy_list]): |
29 | | - | proxy_args = watch['proxy'] |
30 | | - | |
31 | | - | # not valid (including None), try the system one |
32 | | - | else: |
33 | | - | system_proxy = self.datastore.data['settings']['requests']['proxy'] |
34 | | - | # Is not None and exists |
35 | | - | if any([system_proxy in p for p in self.datastore.proxy_list]): |
36 | | - | proxy_args = system_proxy |
37 | | - | |
38 | | - | # Fallback - Did not resolve anything, use the first available |
39 | | - | if proxy_args is None: |
40 | | - | proxy_args = self.datastore.proxy_list[0][0] |
41 | | - | |
42 | | - | return proxy_args |
43 | 13 | | |