Skip to content

Commit

Permalink
Merge pull request #15 from fabfab1/develop
Browse files Browse the repository at this point in the history
Docs update
  • Loading branch information
Forni B authored Apr 15, 2018
2 parents 13ec91b + bbc996d commit 325bdec
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 16 deletions.
8 changes: 8 additions & 0 deletions EnCAB/EnCAB.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@
import sys
import os # files
import re # regex
import datetime
import xml.etree.ElementTree as ET # XML file reading
from bs4 import BeautifulSoup # HTML tag parsing
import jinja2 # HTML template
import zipfile
# from pyuca import Collator # UTF sorting

from config import * # File "config.py" stores program settings
Expand Down Expand Up @@ -76,12 +78,18 @@ def files_index(website_dir):

def get_algo_data(algo_dir, index, author_index):

# Archive the data
zip_name = 'EnCAB_input_' + datetime.date.today().strftime('%Y%m%d') + '.zip'
zip_file = zipfile.ZipFile(os.path.join(algo_dir, 'archives', zip_name), mode='w', compression=zipfile.ZIP_DEFLATED)

algo_data = []
for file in os.listdir(algo_dir):
filename = os.path.join(algo_dir, file)
if os.path.isfile(filename) and filename.endswith(('.xml', '.txt')):
algo_data += [(parse(filename, index, author_index), os.path.basename(filename))]
zip_file.write(filename, arcname=os.path.basename(filename))

zip_file.close()
return algo_data


Expand Down
50 changes: 39 additions & 11 deletions EnCAB/README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
# EnCAB

Python program to update static HTML website with algorithms and index imported from XML data.
Python program to update HTML website with algorithms calculation (with indexes) imported from XML data.


## How It Works

Upon launch, EnCAB.py does the following things:
1. Makes a list of all file names in the website directory
2. Parses XML data contained in the algoritms directory and checks for errors
3. Reads HTML files and extract `<section>` attributes
4. Generates HTML from templates with the data and attributes
5. Updates the content of `<section>` with the new generated HTML


## Getting started

Required Python 3.
Required at least Python 3.6
To install the program in the EnCAB directory:
```shell
git clone https://github.com/fabfab1/EnCAB.git
Expand All @@ -24,32 +34,50 @@ Press ENTER to confirm configuration and update HTML files.

### Built With

Python 3, with Jinja2 (for templating), ElementTree (for parsing XML) and BeautifulSoup (for parsing HTML).
* [Python 3](https://www.python.org/download/releases/3.0/) - The web framework used
* [Jinja2](http://jinja.pocoo.org/) - Templating engine
* [ElementTree](https://docs.python.org/3/library/xml.etree.elementtree.html) - Used to parse XML
* [BeautifulSoup](https://www.crummy.com/software/BeautifulSoup/bs4/doc/) - Used to parse HTML


## Configuration

Edit config file "config.py" to change directories and other preferences.

The program will read the HTML files and the algorithms data.
It will write the HTML data in *.html files inside ```<section block="algorithm/index" sort="(name)"></section>```.
The program will access in read mode the HTML files and the algorithms data.
It will access in read-write mode the HTML files containing ```<section block="algorithm/index" sort="(name)"></section>``` and write the data inside it, keeping the formatting of the file.

```block="algorithm" sort="(name)"``` write algorithms data, insert in (name) a SORT_STRINGS (from "config.py") or XML XPath of desired item to sort
```block="algorithm" sort="(name)"```
write algorithms data, insert in `(name)` a SORT_STRINGS (from `config.py`) or XML XPath of desired item to sort.

```block="index" sort="(name)"``` write files index, insert in (name) the folder name of desired files to use for the sorted index
```block="index" sort="(name)"```
write files index, insert in `(name)` the folder name of desired files to use for the sorted index.

### Data

Each algorithms must have its own XML file stored in ALGORITHMS_DIR with .xml or .txt extension.
See "- algorithms codes format" for mandatory format of the codes.
Each algorithms must have its own XML file stored in ALGORITHMS_DIR with `.xml` or `.txt` extensions.
See file `- algorithms codes format` for mandatory format of the codes.

### HTML Templates

Templates are written in Jinja2 templating language. The XML ElementTree is passed as argument.
Templates are written in Jinja2 templating language.
The XML ElementTree is passed as argument for the algorithms.
The index of files is passed as argument fot the indexes.


### Dinamic calculations

Dinamic algorithms calculation on the HTML page can be made with javascript, as in `script.js`.


### Errors

The log with the errors found are stored in the file "log.txt".
The log with the errors found are stored in the file `log.txt`.


## Authors

* **Bernardo Forni** - [fornib](https://github.com/fornib)


## Licensing
Expand Down
11 changes: 6 additions & 5 deletions EnCAB/to-do programming.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ List of things still to do in EnCAB Program:
--------------------------------------------


write programming page
? where to put programming page or link to README.rd

write Bernardo bio page
? favicon.ico

favicon.ico ?
? everything in *_index.html files

? calc() function circular
? python check js <op>

CSV data dump from all the input files used (also the ones with errors) with the XML tags as headers. Filename should be "EnCAB_input_xyz.csv" where xyz is the date (year month day format) and time.
the separator should be a tab character (the error trapping should give an error if there is a tab used in the input, and should replace that character with 4 spaces when sending to the CSV file)
? ZIP file in archives/ instead of CSV (more accessible)
Binary file not shown.

0 comments on commit 325bdec

Please sign in to comment.