summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Metzger2020-07-21 13:37:37 +0200
committerLukas Metzger2020-07-21 13:37:37 +0200
commit6a39d8afef42b1c1e9575fc7207134c5d7889a7a (patch)
treed4c465a68ca01cda0cd4f764904a8f7808dc2646
parentAdded names for sattelites (diff)
downloadbwlp-statistics-6a39d8afef42b1c1e9575fc7207134c5d7889a7a.tar.gz
bwlp-statistics-6a39d8afef42b1c1e9575fc7207134c5d7889a7a.tar.xz
bwlp-statistics-6a39d8afef42b1c1e9575fc7207134c5d7889a7a.zip
Add sample import script, fix readme
-rw-r--r--README.md8
-rw-r--r--import/import-batch.sh13
2 files changed, 18 insertions, 3 deletions
diff --git a/README.md b/README.md
index c3e8038..dba7fdb 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,7 @@ $ pip3 install -r requirements.txt
This software requires an empty MySQL Database. When this is created import the database structure from `db_structure.sql`.
### Configuration
-Create a config file for the database importer in `import/configuration.ini` as follows
+Create a config file for the database importer in `import/config.ini` as follows
```ini
[db]
host=mysqlhost
@@ -31,7 +31,7 @@ password=mysqlpassword
name=mysqldbname
```
-Do the same for the dashboard in `dash/configuration.ini`, the config file has the exact same structure.
+Do the same for the dashboard in `dash/config.ini`, the config file has the exact same structure.
---
**Note**: For improved security, the importer should have a db user with full privileges whereas the dashboard only requires read access.
@@ -43,7 +43,7 @@ However, if both of them are on the same machine and running with the same user
## Usage
### Importer
-The import script can import one statistic file at once. It is called as follows:
+The import script can import one statistic file at once. It must be run with its folder as working directory. It is called as follows:
```bash
$ python3 import.py report_file.json
```
@@ -51,6 +51,8 @@ Be sure to either activate the venv before running this command as seen above or
In a real world application one would write a shell script which calls the importer for every file in a directory. The importer will know if a report was previously imported and not import it again. Therefore, the script could run every week on all reports from the current year and the last year, but more advanced logic here would be possible.
+There is also a sample script `import-batch.sh` which can be run with one folder as argument. The working diretory must also be the directory of the script.
+
### Dashboard
The dashboard can be run using systemd with the following unit file:
```ini
diff --git a/import/import-batch.sh b/import/import-batch.sh
new file mode 100644
index 0000000..d15060f
--- /dev/null
+++ b/import/import-batch.sh
@@ -0,0 +1,13 @@
+#!/bin/bash
+
+if [ "$#" -lt 1 ]
+then
+ echo "You need to supply a folder for import!"
+ exit 1
+fi
+
+find $1 -name "*.json" -type f | while read line
+do
+ echo "Processing $line"
+ ../../bin/python3 import.py "$line"
+done