pull/1248/head
dgtlmoon 2 years ago
parent 7a1d2d924e
commit dc96a5ff69

@ -755,8 +755,11 @@ def changedetection_app(config=None, datastore_o=None):
@login_required @login_required
def import_page(): def import_page():
remaining_urls = [] remaining_urls = []
from changedetectionio import forms
form = forms.importForm(request.form)
if request.method == 'POST': if request.method == 'POST':
from .importer import import_url_list, import_distill_io_json from .importer import import_url_list, import_distill_io_json, import_changedetection_io_zip
# URL List import # URL List import
if request.values.get('urls') and len(request.values.get('urls').strip()): if request.values.get('urls') and len(request.values.get('urls').strip()):
@ -779,10 +782,20 @@ def changedetection_app(config=None, datastore_o=None):
for uuid in d_importer.new_uuids: for uuid in d_importer.new_uuids:
update_q.put(queuedWatchMetaData.PrioritizedItem(priority=1, item={'uuid': uuid, 'skip_when_checksum_same': True})) update_q.put(queuedWatchMetaData.PrioritizedItem(priority=1, item={'uuid': uuid, 'skip_when_checksum_same': True}))
if request.files.get("backup_zip_file"):
if not form.validate():
flash("An error occurred, please see below.", "error")
else:
d_importer = import_changedetection_io_zip()
d_importer.run(data=None, flash=flash, datastore=datastore)
for uuid in d_importer.new_uuids:
# Queue without priority, we will examine their own rule to find out if it should be checked
update_q.put(queuedWatchMetaData.PrioritizedItem(item={'uuid': uuid, 'skip_when_checksum_same': True}))
# Could be some remaining, or we could be on GET # Could be some remaining, or we could be on GET
output = render_template("import.html", output = render_template("import.html",
form=form,
import_url_list_remaining="\n".join(remaining_urls), import_url_list_remaining="\n".join(remaining_urls),
original_distill_json='' original_distill_json=''
) )

@ -3,6 +3,7 @@ import re
from wtforms import ( from wtforms import (
BooleanField, BooleanField,
FileField,
Form, Form,
IntegerField, IntegerField,
RadioField, RadioField,
@ -425,6 +426,14 @@ class watchForm(commonSettingsForm):
result = False result = False
return result return result
# datastore.data['settings']['requests']..
class importForm(Form):
#backup_zip_file = FileField("File", validators=[validators.regexp('\.zip$', flags=re.IGNORECASE)])
backup_zip_file = FileField("File")
def validate_backup_zip_file(form, field):
if field.data:
x=1
# datastore.data['settings']['requests'].. # datastore.data['settings']['requests']..
class globalSettingsRequestForm(Form): class globalSettingsRequestForm(Form):

@ -1,4 +1,5 @@
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from flask import request, url_for, current_app
import time import time
import validators import validators
@ -20,6 +21,26 @@ class Importer():
datastore): datastore):
pass pass
class import_changedetection_io_zip(Importer):
def run(self,
data,
flash,
datastore,
):
# `data` should be none, we will hit up request directly
import zipfile
import io
with zipfile.ZipFile(io.BytesIO(request.files["backup_zip_file"].read()), 'r') as zf:
p =zf.namelist()
for file in zf.namelist():
x=1
class import_url_list(Importer): class import_url_list(Importer):
""" """

@ -1,5 +1,6 @@
{% extends 'base.html' %} {% extends 'base.html' %}
{% block content %} {% block content %}
{% from '_helpers.jinja' import render_field %}
<script type="text/javascript" src="{{url_for('static_content', group='js', filename='tabs.js')}}" defer></script> <script type="text/javascript" src="{{url_for('static_content', group='js', filename='tabs.js')}}" defer></script>
<div class="edit-form monospaced-textarea"> <div class="edit-form monospaced-textarea">
@ -7,11 +8,12 @@
<ul> <ul>
<li class="tab" id=""><a href="#url-list">URL List</a></li> <li class="tab" id=""><a href="#url-list">URL List</a></li>
<li class="tab"><a href="#distill-io">Distill.io</a></li> <li class="tab"><a href="#distill-io">Distill.io</a></li>
<li class="tab"><a href="#changedetection-io">Changedetection.io</a></li>
</ul> </ul>
</div> </div>
<div class="box-wrap inner"> <div class="box-wrap inner">
<form class="pure-form pure-form-aligned" action="{{url_for('import_page')}}" method="POST"> <form class="pure-form pure-form-aligned" action="{{url_for('import_page')}}" method="POST" enctype="multipart/form-data">
<input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/> <input type="hidden" name="csrf_token" value="{{ csrf_token() }}"/>
<div class="tab-pane-inner" id="url-list"> <div class="tab-pane-inner" id="url-list">
<fieldset class="pure-group"> <fieldset class="pure-group">
@ -77,6 +79,12 @@
" rows="25">{{ original_distill_json }}</textarea> " rows="25">{{ original_distill_json }}</textarea>
</fieldset> </fieldset>
</div> </div>
<div class="tab-pane-inner" id="changedetection-io">
Upload your changedetection.io backup ZIP here</br>
<fieldset class="pure-group">
{{ render_field(form.backup_zip_file) }}
</fieldset>
</div>
<button type="submit" class="pure-button pure-input-1-2 pure-button-primary">Import</button> <button type="submit" class="pure-button pure-input-1-2 pure-button-primary">Import</button>
</form> </form>

Loading…
Cancel
Save