Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Import changedetection.io backup zip #1248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion changedetectionio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,8 +755,11 @@ def settings_page():
@login_required
def import_page():
remaining_urls = []
from changedetectionio import forms
form = forms.importForm(request.form)

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
if request.values.get('urls') and len(request.values.get('urls').strip()):
Expand All @@ -779,10 +782,20 @@ def import_page():
for uuid in d_importer.new_uuids:
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
output = render_template("import.html",
form=form,
import_url_list_remaining="\n".join(remaining_urls),
original_distill_json=''
)
Expand Down
9 changes: 9 additions & 0 deletions changedetectionio/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from wtforms import (
BooleanField,
FileField,
Form,
IntegerField,
RadioField,
Expand Down Expand Up @@ -425,6 +426,14 @@ def validate(self, **kwargs):
result = False
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']..
class globalSettingsRequestForm(Form):
Expand Down
21 changes: 21 additions & 0 deletions changedetectionio/importer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from abc import ABC, abstractmethod
from flask import request, url_for, current_app
import time
import validators

Expand All @@ -20,6 +21,26 @@ def run(self,
datastore):
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):
"""
Expand Down
10 changes: 9 additions & 1 deletion changedetectionio/templates/import.html
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
{% extends 'base.html' %}
{% block content %}
{% from '_helpers.jinja' import render_field %}
<script type="text/javascript" src="{{url_for('static_content', group='js', filename='tabs.js')}}" defer></script>
<div class="edit-form monospaced-textarea">

<div class="tabs collapsable">
<ul>
<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="#changedetection-io">Changedetection.io</a></li>
</ul>
</div>

<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() }}"/>
<div class="tab-pane-inner" id="url-list">
<fieldset class="pure-group">
Expand Down Expand Up @@ -77,6 +79,12 @@
" rows="25">{{ original_distill_json }}</textarea>
</fieldset>
</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>
</form>

Expand Down