Skip to main content

Tool to index and serve HTML files. Powered by Datasette.

Project description

htmls-to-datasette

Htmls-to-datasette is a tool to index HTML files into a Sqlite database so they can be searched and visualized at a later time. This can be useful for web archival/web clipping purposes.

The database created is designed to be served on Datasette and to allow to read the indexed files through it.

This tool was created to serve my own work flow that is:

  1. Have a browser with SingleFile extension installed.
  2. When there is an interesting blog post or article save a full web page into one HTML using SingleFile.
  3. The created .html file on the downloads folder is moved to a common repository (via cron job).
  4. This common repository is synched to my main server (I use Syncthing for this).
  5. On my personal server all the new HTML files are moved to the serving folder and this indexer is called to populate the search database.
  6. Datasette with an specific configuration will allow searching on these files and reading them online.

The indexing tool can insert the HTML contents on the database itself, to be served from there, or not. In this second case the files will be served from the location they were indexed from.

Setup

Standard install

pip install htmls-to-datasette

And you can start running the command, use --help to see specific commands help.

htmls-to-datasette --help
htmls-to-datasette index --help

Development install

This project uses Poetry to make it easier to setup the appropriate dependencies to run.

Installation steps for Poetry can be checked on their website but for most of the cases this command line would work:

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python -

Note that you should exercise caution when running something directly from Internet.

Install dependencies:

poetry install

Run

You can use poetry run in front of htmls-to-datassette so it is using the virtual environment that you just created before.

poetry run htmls-to-datassette [options]

Build an installable package

poetry build # The resoult will be in dist directory

I use pipx for installing packages on isolated environments. You can install this package from the dist/ directory in whichever way you prefer or you can install pipx.

The installation with pipx would be similar to:

pipx install dist/htmls-to-datasette-0.1.2.tar.gz

Usage

htmls-to-datasette index [OPTIONS] [INPUT_DIRS]... will create a database named `htmlstore.db' (by default).

Example

Get into the server directory:

cd server

Because this example requires Datasette to run you would have to get them using poetry:

poetry init

Now index the example file using htmls-to-datasette:

htmls-to-datasette index input

All files contained in input (.html and .html) will be indexed and a full text search index created. Whenever there are new files to be indexed this command can be run in the same way.

And now run the Datasette server:

poetry run datasette serve htmlstore.db -m metadata-files.json --plugins-dir=plugins

You'll see the address to send your browser to on the screen. There is also a shortcut to make it easier to perform a full text search. Should be reachable at http://127.0.0.1:8001/htmlstore/search just fill the query on the 'q' parameter and you will search over the indexed HTMLs. Click on the HTML file name will load its contents.

For this to work the server will require the files to be on their location (relative in this case). So if the input folder is moved away or not accesible the files would be searchable but the contents will not be available.

There is an additional example that stores these files onto the Sqlite database itself. This has its advantages as everything needed for serving and searching the content will be contained in one file.

# You should be on the server directory
rm htmlstore.db   # Remove the previous example's database
htmls-to-datasette index input --store-binary  # Index files and store its contents

# Now run Datasette, note that now we need to use a different metadata as the contents needed to be served
# in a different way (from the DB itself). 
poetry run datasette serve htmlstore.db -m metadata-binary.json --plugins-dir=plugins

TODO

  • Clear content when extracting files.
  • Better documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

htmls-to-datasette-0.1.2.tar.gz (10.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

htmls_to_datasette-0.1.2-py3-none-any.whl (14.6 kB view details)

Uploaded Python 3

File details

Details for the file htmls-to-datasette-0.1.2.tar.gz.

File metadata

  • Download URL: htmls-to-datasette-0.1.2.tar.gz
  • Upload date:
  • Size: 10.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.8 CPython/3.9.7 Linux/5.10.46-4rodete4-amd64

File hashes

Hashes for htmls-to-datasette-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0648f01427e8176045d0c57a15c7d369a3289217d17432c2b960c6a642fab3ac
MD5 a31b6346aa56a36833df0e6f7d249612
BLAKE2b-256 53128063aabcc4a5e7f70fb39ee563745c9fef0680912e8244f394c5feb64dcc

See more details on using hashes here.

File details

Details for the file htmls_to_datasette-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: htmls_to_datasette-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 14.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.8 CPython/3.9.7 Linux/5.10.46-4rodete4-amd64

File hashes

Hashes for htmls_to_datasette-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b5cde1eaa4be3fb00d693f9b773e51a3715850378641701c4085d5eeb6e551ca
MD5 68ea9add8f3ee81d2a70527975fa0b69
BLAKE2b-256 c507fee5869ff1e1655d7adaf79cebbad10de1863b3e1ac0ca68bd93e70f9b27

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page