Compare commits
9 Commits
c1c2c45439
...
8097fcef60
Author | SHA1 | Date | |
---|---|---|---|
8097fcef60 | |||
6b619c747f | |||
333246e653 | |||
1afd622196 | |||
c3cd29430f | |||
748609919b | |||
|
2a7ec01dcd | ||
|
71f946b8b0 | ||
|
816510f4de |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,3 +1,4 @@
|
|||||||
.idea
|
.idea
|
||||||
__pycache__
|
__pycache__
|
||||||
*.code-workspace
|
*.code-workspace
|
||||||
|
.venv*
|
9
src/bstack.py
Normal file
9
src/bstack.py
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
from lib import *
|
||||||
|
|
||||||
|
|
||||||
|
def retrieve(id_num):
|
||||||
|
result = api.get_pages_read({"id": id_num})
|
||||||
|
print(result)
|
||||||
|
|
||||||
|
def insert(id_num, name, text):
|
||||||
|
pass
|
63
src/bstack_api_calls.json
Normal file
63
src/bstack_api_calls.json
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
{
|
||||||
|
'post_books_create',
|
||||||
|
'get_attachments_read',
|
||||||
|
'get_chapters_list',
|
||||||
|
'get_content_permissions_read',
|
||||||
|
'get_chapters_export_markdown',
|
||||||
|
'post_roles_create',
|
||||||
|
'put_recycle_bin_restore',
|
||||||
|
'put_image_gallery_update',
|
||||||
|
'put_books_update',
|
||||||
|
'post_shelves_create',
|
||||||
|
'get_books_read',
|
||||||
|
'get_attachments_list',
|
||||||
|
'put_content_permissions_update',
|
||||||
|
'get_recycle_bin_list',
|
||||||
|
'delete_users_delete',
|
||||||
|
'get_users_list',
|
||||||
|
'get_docs_json',
|
||||||
|
'get_books_export_html',
|
||||||
|
'put_chapters_update',
|
||||||
|
'get_chapters_export_pdf',
|
||||||
|
'get_pages_export_markdown',
|
||||||
|
'delete_pages_delete',
|
||||||
|
'post_attachments_create',
|
||||||
|
'put_attachments_update',
|
||||||
|
'get_roles_read',
|
||||||
|
'get_chapters_export_plain_text',
|
||||||
|
'get_users_read',
|
||||||
|
'delete_chapters_delete',
|
||||||
|
'put_pages_update',
|
||||||
|
'post_chapters_create',
|
||||||
|
'get_chapters_read',
|
||||||
|
'get_pages_list',
|
||||||
|
'get_pages_export_plain_text',
|
||||||
|
'get_roles_list',
|
||||||
|
'get_pages_export_html',
|
||||||
|
'get_image_gallery_read',
|
||||||
|
'delete_attachments_delete',
|
||||||
|
'post_users_create',
|
||||||
|
'get_audit_log_list',
|
||||||
|
'get_pages_export_pdf',
|
||||||
|
'delete_books_delete',
|
||||||
|
'get_shelves_read',
|
||||||
|
'delete_roles_delete',
|
||||||
|
'get_pages_read',
|
||||||
|
'put_shelves_update',
|
||||||
|
'get_books_export_plain_text',
|
||||||
|
'delete_shelves_delete',
|
||||||
|
'get_books_export_markdown',
|
||||||
|
'delete_image_gallery_delete',
|
||||||
|
'get_search_all',
|
||||||
|
'get_books_list',
|
||||||
|
'post_image_gallery_create',
|
||||||
|
'get_books_export_pdf',
|
||||||
|
'post_pages_create',
|
||||||
|
'get_shelves_list',
|
||||||
|
'get_docs_display',
|
||||||
|
'put_users_update',
|
||||||
|
'put_roles_update',
|
||||||
|
'delete_recycle_bin_destroy',
|
||||||
|
'get_chapters_export_html',
|
||||||
|
'get_image_gallery_list'
|
||||||
|
}
|
@ -1,20 +1,31 @@
|
|||||||
import lib
|
import lib
|
||||||
|
from lib import json_cursor, json_file
|
||||||
|
|
||||||
# import paperless database export
|
existing, inserted, duplicates = 0, 0, 0
|
||||||
raw_manifest = open("/mnt/user/media/paperless/media/backup/manifest.json")
|
|
||||||
manifest = lib.json.load(raw_manifest)
|
|
||||||
|
|
||||||
index_num = 1
|
|
||||||
|
|
||||||
existing, inserted, big, duplicates = 0, 0, 0, 0
|
|
||||||
|
|
||||||
def insert(r):
|
def insert(r):
|
||||||
lib.db.insert_one({"title": r["title"],
|
global inserted
|
||||||
"content": r["content"],
|
pk = r['pk']
|
||||||
"checksum": r["check"],
|
check = r['check']
|
||||||
"index": r["index"]})
|
content = r['content']
|
||||||
|
title = r['title']
|
||||||
|
|
||||||
def exists(r):
|
lib.db.insert_one({'title': title,"content": content,
|
||||||
|
"checksum": check,
|
||||||
|
"pk": pk})
|
||||||
|
inserted = inserted + 1
|
||||||
|
|
||||||
|
def update_pk(r):
|
||||||
|
lib.db.update_one(
|
||||||
|
{
|
||||||
|
"checksum": r["check"]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"$set": {"index": r["index"]}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
def rec_exists(r):
|
||||||
global existing, duplicates
|
global existing, duplicates
|
||||||
record = lib.db.find_one({"checksum": r["check"]})
|
record = lib.db.find_one({"checksum": r["check"]})
|
||||||
dupe = lib.db.find_one({"content": r["content"], "title": r["title"]})
|
dupe = lib.db.find_one({"content": r["content"], "title": r["title"]})
|
||||||
@ -28,25 +39,19 @@ def exists(r):
|
|||||||
else: return False
|
else: return False
|
||||||
|
|
||||||
def parse():
|
def parse():
|
||||||
global inserted, big, index_num
|
f = json_file()
|
||||||
print("Parsing manifest json...")
|
print("Parsing manifest json...")
|
||||||
|
r = {}
|
||||||
# for every document in the export
|
# for every document in the export
|
||||||
for document in manifest:
|
for doc in json_cursor(f):
|
||||||
#if the title and content tags aren't blank
|
fields = doc['fields']
|
||||||
try:
|
if 'title' in fields and 'content' in fields:
|
||||||
record = {"title": document["fields"]["title"],
|
r['pk'] = doc['pk']
|
||||||
"content": document["fields"]["content"],
|
r['title'] = fields['title']
|
||||||
"check": document["fields"]["checksum"],
|
r['content'] = fields['content']
|
||||||
"index": index_num}
|
r['check'] = fields['checksum']
|
||||||
|
if rec_exists(r):
|
||||||
if lib.sys.getsizeof(record["content"]) < 16777216:
|
|
||||||
if record["content"] != "" and record["title"] != "":
|
|
||||||
if not exists(record):
|
|
||||||
insert(record)
|
|
||||||
inserted = inserted + 1
|
|
||||||
index_num = index_num + 1
|
|
||||||
else: big = big + 1
|
|
||||||
except KeyError:
|
|
||||||
continue
|
continue
|
||||||
|
else:
|
||||||
|
insert(r)
|
||||||
|
f.close()
|
@ -1,2 +0,0 @@
|
|||||||
import lib
|
|
||||||
|
|
@ -1,6 +1,29 @@
|
|||||||
import pymongo
|
import pymongo
|
||||||
import os
|
import os
|
||||||
import json
|
import ijson
|
||||||
import sys
|
import sys
|
||||||
|
import bookstack
|
||||||
|
|
||||||
db = pymongo.MongoClient("localhost", 27017).paperless.content
|
|
||||||
|
def json_file():
|
||||||
|
return open("/mnt/tower/media/paperless/media/backup/test.json")
|
||||||
|
|
||||||
|
# import paperless database export
|
||||||
|
# manifest_path = "/mnt/user/media/paperless/media/manifest.json"
|
||||||
|
|
||||||
|
def json_cursor(f):
|
||||||
|
items = ijson.items(f, 'item')
|
||||||
|
docs = (doc for doc in items \
|
||||||
|
if doc['model'] == "documents.document" \
|
||||||
|
if sys.getsizeof(doc['fields']['content']) < 16777216)
|
||||||
|
return docs
|
||||||
|
|
||||||
|
db = pymongo.MongoClient("10.0.0.59", 27017).paperless.content
|
||||||
|
|
||||||
|
|
||||||
|
url = 'http://10.0.0.59:6875'
|
||||||
|
token = 'RVSO8xZXOjRYJntNYPRd3E9iT2qXm11C'
|
||||||
|
secret = 'qR5r2EyKT09ogz8VSolS12ispAV5QrT0'
|
||||||
|
|
||||||
|
api = bookstack.BookStack(url, token, secret)
|
||||||
|
methods = api.generate_api_methods()
|
@ -1,13 +1,12 @@
|
|||||||
import extract
|
import extract
|
||||||
import search
|
import search
|
||||||
import insert
|
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
extract.parse()
|
extract.parse()
|
||||||
print("Existing:", extract.existing)
|
print("Existing:", extract.existing)
|
||||||
print("Inserted:", extract.inserted)
|
print("Inserted:", extract.inserted)
|
||||||
print("To big:", extract.big)
|
|
||||||
print("Dupes:", extract.duplicates)
|
print("Dupes:", extract.duplicates)
|
||||||
|
extract.existing, extract.inserted, extract.duplicates = 0, 0, 0
|
||||||
|
|
||||||
menu()
|
menu()
|
||||||
|
|
||||||
@ -17,8 +16,7 @@ def prompt():
|
|||||||
def menu():
|
def menu():
|
||||||
value = prompt()
|
value = prompt()
|
||||||
if value == "reload":
|
if value == "reload":
|
||||||
extract.parse()
|
start()
|
||||||
value = prompt()
|
|
||||||
while value != "quit" and value != "reload":
|
while value != "quit" and value != "reload":
|
||||||
results = search.query(value)
|
results = search.query(value)
|
||||||
if type(results) == dict:
|
if type(results) == dict:
|
||||||
|
Loading…
Reference in New Issue
Block a user