Coupon, v1.0
Posted on

Utility for a getting and a formatting of coupons from the admitad service.
Major release.
Features
- log in an admitad account;
- getting of a coupon list for a specific website;
- filter a coupon list by a script in the microlanguage (see below for details);
- output a coupon list:
- format an output:
- format an output with an Jinja2 template;
- Jinja2 template extensions:
- format a timestamp;
- flatten a text (replace line breaks with a specific string);
- extract a cut (first sentence) with a specific cut mark;
- split a text to paragraphs with a specific paragraph format (optionally skip a specific cut mark);
- output target may be:
- separate files;
- stdout.
- format an output:
Installation
Clone this repository:
$ git clone https://github.com/thewizardplusplus/coupon.git
$ cd coupon
Then install the utility with pip tool:
$ sudo -H python3.5 -m pip install .
sudo command is required to install coupon console script. If it's not required, sudo command can be omitted:
$ python3.5 -m pip install .
But then the utility should be started as python3.5 -m coupon.
Usage
$ coupon
Environment variables:
COUPON_ADMITAD_ID— ID of the Admitad app;COUPON_ADMITAD_SECRET— secret of the Admitad app;COUPON_SITE_ID— ID of the site;COUPON_OUTPUT_PATH— path for output coupons (default:./coupons/);COUPON_TEMPLATE— path to the coupon template (default:./docs/rich_coupon_template.example.html);COUPON_LOCALE— locale for timestamp formatting (default:ru_RU);COUPON_SCRIPT— path to the filter script (default:./docs/coupon_script.example.coupon);COUPON_OUTPUT_MODE— mode of output coupons (default:FILES|STDOUT).
Environment variables can be specified in a .env config in the format:
NAME_1=value_1
NAME_2=value_2
...
See details about the format: https://github.com/motdotla/dotenv#rules.
A .env config will never modify any environment variables that have already been set.
Microlanguage of a Filter Script
Grammar in an EBNF:
script = or expression;
or expression = and expression, {"||", and expression};
and expression = not expression, {"&&", not expression};
not expression = ["!"], atom;
atom = filter | ("(", script, ")");
filter = identifier, "=~", REGULAR EXPRESSION;
identifier = IDENTIFIER, {".", IDENTIFIER};
IDENTIFIER = ? /\w+/ ?;
REGULAR EXPRESSION = ? /\/(?:\\.|[^\/])+\// ?;
SINGLE-LINE COMMENT = ? /\#.*/ ?.
Example: types.0.name =~ /Бесплатная доставка/ && !(description =~ /\d{4}/).
Repository
Link: https://github.com/thewizardplusplus/coupon/tree/v1.0.
Content: code.
License: MIT.
Screenshots
Output the coupon to an HTML file

Output coupons to stdout
