Temporary(?) solution, added #13 and #12

This commit is contained in:
Frisk 2018-06-24 12:31:07 +02:00
parent 834197a9b5
commit 585cc36dfa
No known key found for this signature in database
GPG key ID: 0E9A7D3C0A01586C
3 changed files with 18 additions and 7 deletions

View file

@ -34,6 +34,8 @@ Explanation for settings:
`appearience` section with different types of actions and logs, and corresponding to them colors/icons. In here you can set custom icon or color!
`overview` bool value, sends a day overview to the channel if true.
`overview_time` **local machine time** at which the day overview will be sent.
`license_regex` if you have an unusual or translated template for applying licenses to images, you can modify this value with proper regex expression. The capturing group for license name should be named "license". **remember about double escaping the backslashes**
`license_regex_detect` a regex detecting a license, it differs from `license_regex` by the fact that it has to match only the beginning of license template. **remember about double escaping the backslashes**
### How to use ###
Make sure you have installed all of dependencies and **filled settings.json properly**. You can also use `pip install -r requirements.txt` to install dependencies automatically. If you are using Raspberry Pi you won't have newest Python version installed, you can use [this guide](https://gist.github.com/dschep/24aa61672a2092246eaca2824400d37f).

View file

@ -121,15 +121,22 @@ def webhook_formatter(action, STATIC, **params):
if article_content is None:
logging.warning("Something went wrong when getting license for the image")
return 0
content = list(article_content.values())[0]['revisions'][0]['*'].lower()
if "{{license" not in content and "{{lizenz" not in content and "{{licence" not in content:
license = _("**No license!**")
else:
matches = re.search(r"\{\{(license|lizenz|licence)(\ |\|)(.*?)\}\}", content)
content = list(article_content.values())[0]['revisions'][0]['*']
try:
matches = re.search(re.compile(settings["license_regex"]), content, re.IGNORECASE)
if matches is not None:
license = matches.group(3)
license = matches.group("license")
else:
license = "?"
if re.search(re.compile(settings["license_regex_detect"]), content, re.IGNORECASE) is None:
license = _("**No license!**")
else:
license = "?"
except sre_constants.error:
logging.error("Given regex for the license detection is incorrect. Please fix license_regex or license_regex_detect values in the config!")
license = "?"
except IndexError:
logging.error("Given regex for the license detection is incorrect. It does not have a capturing group called \"license\" specified. Please fix license_regex value in the config!")
license = "?"
embed["fields"] = [{"name": _("Options"), "value": _("([preview]({link}))").format(link=embed["image"]["url"])}]
params["desc"] = _("{desc}\nLicense: {license}").format(desc=params["desc"], license=license)
elif action == 6:

View file

@ -18,6 +18,8 @@
"show_updown_messages": true,
"overview": false,
"overview_time": "00:00",
"license_regex_detect": "\\{\\{(license|lizenz|licence)",
"license_regex": "\\{\\{(license|lizenz|licence)(\\ |\\|)(?P<license>.*?)\\}\\}",
"appearance":{
"daily_overview": {
"color": 16312092,