kopia lustrzana https://github.com/dgtlmoon/changedetection.io
				
				
				
			Add basic settings page (so far just recheck time in minutes)
							rodzic
							
								
									5b8252c171
								
							
						
					
					
						commit
						d0ee49e465
					
				| 
						 | 
				
			
			@ -121,6 +121,30 @@ def edit_page():
 | 
			
		|||
    output = render_template("edit.html", uuid=uuid, watch=datastore.data['watching'][uuid], messages=messages)
 | 
			
		||||
    return output
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@app.route("/settings", methods=['GET', "POST"])
 | 
			
		||||
def settings_page():
 | 
			
		||||
    global messages
 | 
			
		||||
    if request.method == 'POST':
 | 
			
		||||
        try:
 | 
			
		||||
            minutes = int(request.values.get('minutes').strip())
 | 
			
		||||
        except ValueError:
 | 
			
		||||
            messages.append({'class': 'error', 'message': "Invalid value given, use an integer."})
 | 
			
		||||
 | 
			
		||||
        else:
 | 
			
		||||
            if minutes >= 5 and minutes <= 600:
 | 
			
		||||
                datastore.data['settings']['requests']['minutes_between_check'] = minutes
 | 
			
		||||
                datastore.needs_write = True
 | 
			
		||||
 | 
			
		||||
                messages.append({'class': 'ok', 'message': "Updated"})
 | 
			
		||||
            else:
 | 
			
		||||
                messages.append({'class': 'error', 'message': "Must be equal to or greater than 5 and less than 600 minutes"})
 | 
			
		||||
 | 
			
		||||
    output = render_template("settings.html", messages=messages, minutes=datastore.data['settings']['requests']['minutes_between_check'])
 | 
			
		||||
    messages =[]
 | 
			
		||||
 | 
			
		||||
    return output
 | 
			
		||||
 | 
			
		||||
@app.route("/import", methods=['GET', "POST"])
 | 
			
		||||
def import_page():
 | 
			
		||||
    import validators
 | 
			
		||||
| 
						 | 
				
			
			@ -275,8 +299,12 @@ def launch_checks():
 | 
			
		|||
    import fetch_site_status
 | 
			
		||||
    global running_update_threads
 | 
			
		||||
 | 
			
		||||
    for uuid,watch in datastore.data['watching'].items():
 | 
			
		||||
        if watch['last_checked'] <= time.time() - 3 * 60 * 60:
 | 
			
		||||
 | 
			
		||||
    minutes = datastore.data['settings']['requests']['minutes_between_check']
 | 
			
		||||
    for uuid, watch in datastore.data['watching'].items():
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        if watch['last_checked'] <= time.time() - (minutes * 60):
 | 
			
		||||
            running_update_threads[watch['uuid']] = fetch_site_status.perform_site_check(uuid=uuid,
 | 
			
		||||
                                                                                         datastore=datastore)
 | 
			
		||||
            running_update_threads[watch['uuid']].start()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,7 +23,7 @@ class ChangeDetectionStore:
 | 
			
		|||
                },
 | 
			
		||||
                'requests': {
 | 
			
		||||
                    'timeout': 15, # Default 15 seconds
 | 
			
		||||
                    'max_seconds_from_last_check': 3 * 60 * 60 # Default 3 hours
 | 
			
		||||
                    'minutes_between_check': 3 * 60 # Default 3 hours
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
| 
						 | 
				
			
			@ -47,7 +47,18 @@ class ChangeDetectionStore:
 | 
			
		|||
            with open('/datastore/url-watches.json') as json_file:
 | 
			
		||||
                from_disk = json.load(json_file)
 | 
			
		||||
 | 
			
		||||
                self.__data.update(from_disk)
 | 
			
		||||
                # @todo isnt there a way todo this dict.update recursively?
 | 
			
		||||
                # Problem here is if the one on the disk is missing a sub-struct, it wont be present anymore.
 | 
			
		||||
                if 'watching' in from_disk:
 | 
			
		||||
                    self.__data['watching'].update(from_disk['watching'])
 | 
			
		||||
 | 
			
		||||
                if 'settings' in from_disk:
 | 
			
		||||
                    if 'headers' in from_disk['settings']:
 | 
			
		||||
                        self.__data['settings']['headers'].update(from_disk['settings']['headers'])
 | 
			
		||||
 | 
			
		||||
                    if 'requests' in from_disk['settings']:
 | 
			
		||||
                        self.__data['settings']['requests'].update(from_disk['settings']['requests'])
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
                # Reinitialise each `watching` with our generic_definition in the case that we add a new var in the future.
 | 
			
		||||
                # @todo pretty sure theres a python we todo this with an abstracted(?) object!
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -4,34 +4,16 @@
 | 
			
		|||
<div class="edit-form">
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    <form class="pure-form pure-form-stacked" action="/api/update?uuid={{uuid}}" method="POST">
 | 
			
		||||
    <form class="pure-form pure-form-stacked" action="/settings" method="POST">
 | 
			
		||||
        <fieldset>
 | 
			
		||||
            <div class="pure-control-group">
 | 
			
		||||
                <label for="url">URL</label>
 | 
			
		||||
                <input type="url" id="url" required="" placeholder="https://..." name="url" value="{{ watch.url}}"
 | 
			
		||||
                       size="50"/>
 | 
			
		||||
                <label for="minutes">Minutes between recheck</label>
 | 
			
		||||
                <input type="text" id="minutes" required="" name="minutes" value="{{minutes}}"
 | 
			
		||||
                       size="5"/>
 | 
			
		||||
                <span class="pure-form-message-inline">This is a required field.</span>
 | 
			
		||||
            </div>
 | 
			
		||||
            <div class="pure-control-group">
 | 
			
		||||
                <label for="tag">Tag</label>
 | 
			
		||||
                <input type="text" placeholder="tag" size="10" id="tag" name="tag" value="{{ watch.tag}}"/>
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
            <fieldset class="pure-group">
 | 
			
		||||
                <label for="headers">Extra request headers</label>
 | 
			
		||||
 | 
			
		||||
                <textarea id=headers name="headers" class="pure-input-1-2" placeholder="Example
 | 
			
		||||
Cookie: foobar
 | 
			
		||||
User-Agent: wonderbra 1.0"
 | 
			
		||||
                          style="width: 100%;
 | 
			
		||||
                            font-family:monospace;
 | 
			
		||||
                            white-space: pre;
 | 
			
		||||
                            overflow-wrap: normal;
 | 
			
		||||
                            overflow-x: scroll;" rows="5">{% for key, value in watch.headers.items() %}{{ key }}: {{ value }}
 | 
			
		||||
{% endfor %}</textarea>
 | 
			
		||||
                <br/>
 | 
			
		||||
 | 
			
		||||
            </fieldset>
 | 
			
		||||
            <div class="pure-control-group">
 | 
			
		||||
                <button type="submit" class="pure-button pure-button-primary">Save</button>
 | 
			
		||||
            </div>
 | 
			
		||||
| 
						 | 
				
			
			@ -39,9 +21,6 @@ User-Agent: wonderbra 1.0"
 | 
			
		|||
 | 
			
		||||
            <div class="pure-control-group">
 | 
			
		||||
                <a href="/" class="pure-button button-small button-cancel">Cancel</a>
 | 
			
		||||
                <a href="/api/delete?uuid={{uuid}}"
 | 
			
		||||
                   class="pure-button button-small button-error ">Delete</a>
 | 
			
		||||
 | 
			
		||||
            </div>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue