From b42d6f54a1fc757518498744acb7cd77657e1663 Mon Sep 17 00:00:00 2001
From: Bob Mottram <bob@freedombone.net>
Date: Sat, 17 Oct 2020 22:23:46 +0100
Subject: [PATCH] Enter news processing rules from the newswire edit screen

---
 daemon.py            | 10 ++++++++++
 translations/ar.json |  4 +++-
 translations/ca.json |  4 +++-
 translations/cy.json |  4 +++-
 translations/de.json |  4 +++-
 translations/en.json |  4 +++-
 translations/es.json |  4 +++-
 translations/fr.json |  4 +++-
 translations/ga.json |  4 +++-
 translations/hi.json |  4 +++-
 translations/it.json |  4 +++-
 translations/ja.json |  4 +++-
 translations/oc.json |  4 +++-
 translations/pt.json |  4 +++-
 translations/ru.json |  4 +++-
 translations/zh.json |  4 +++-
 webinterface.py      | 22 +++++++++++++++++++++-
 17 files changed, 76 insertions(+), 16 deletions(-)

diff --git a/daemon.py b/daemon.py
index 69a15481..cd18ef8c 100644
--- a/daemon.py
+++ b/daemon.py
@@ -2984,6 +2984,16 @@ class PubServer(BaseHTTPRequestHandler):
                 if os.path.isfile(filterNewswireFilename):
                     os.remove(filterNewswireFilename)
 
+            # save news tagging rules
+            hashtagRulesFilename = \
+                baseDir + '/accounts/hashtagrules.txt'
+            if fields.get('hashtagRulesList'):
+                with open(hashtagRulesFilename, 'w+') as rulesfile:
+                    rulesfile.write(fields['hashtagRulesList'])
+            else:
+                if os.path.isfile(hashtagRulesFilename):
+                    os.remove(hashtagRulesFilename)
+
             newswireTrustedFilename = baseDir + '/accounts/newswiretrusted.txt'
             if fields.get('trustedNewswire'):
                 newswireTrusted = fields['trustedNewswire']
diff --git a/translations/ar.json b/translations/ar.json
index de49c154..4b89fe1a 100644
--- a/translations/ar.json
+++ b/translations/ar.json
@@ -311,5 +311,7 @@
     "Site Editors": "محررو الموقع",
     "Allow news posts": "السماح بنشر الأخبار",
     "Publish": "ينشر",
-    "Publish a news article": "انشر مقالة إخبارية"
+    "Publish a news article": "انشر مقالة إخبارية",
+    "News tagging rules": "قواعد وسم الأخبار",
+    "See instructions": "انظر التعليمات"
 }
diff --git a/translations/ca.json b/translations/ca.json
index 3499c9de..d007be90 100644
--- a/translations/ca.json
+++ b/translations/ca.json
@@ -311,5 +311,7 @@
     "Site Editors": "Editors de llocs",
     "Allow news posts": "Permet publicacions de notícies",
     "Publish": "Publica",
-    "Publish a news article": "Publicar un article de notícies"
+    "Publish a news article": "Publicar un article de notícies",
+    "News tagging rules": "Regles d'etiquetatge de notícies",
+    "See instructions": "Consulteu les instruccions"
 }
diff --git a/translations/cy.json b/translations/cy.json
index 2ab1795c..555b01d0 100644
--- a/translations/cy.json
+++ b/translations/cy.json
@@ -311,5 +311,7 @@
     "Site Editors": "Golygyddion Safle",
     "Allow news posts": "Caniatáu swyddi newyddion",
     "Publish": "Cyhoeddi",
-    "Publish a news article": "Cyhoeddi erthygl newyddion"
+    "Publish a news article": "Cyhoeddi erthygl newyddion",
+    "News tagging rules": "Rheolau tagio newyddion",
+    "See instructions": "Gweler y cyfarwyddiadau"
 }
diff --git a/translations/de.json b/translations/de.json
index ceb6179e..f1c88a27 100644
--- a/translations/de.json
+++ b/translations/de.json
@@ -311,5 +311,7 @@
     "Site Editors": "Site-Editoren",
     "Allow news posts": "Nachrichtenbeiträge zulassen",
     "Publish": "Veröffentlichen",
-    "Publish a news article": "Veröffentlichen Sie einen Nachrichtenartikel"
+    "Publish a news article": "Veröffentlichen Sie einen Nachrichtenartikel",
+    "News tagging rules": "Regeln für das Markieren von Nachrichten",
+    "See instructions": "Siehe Anweisungen"
 }
diff --git a/translations/en.json b/translations/en.json
index e5a65517..ca15cb68 100644
--- a/translations/en.json
+++ b/translations/en.json
@@ -311,5 +311,7 @@
     "Site Editors": "Site Editors",
     "Allow news posts": "Allow news posts",
     "Publish": "Publish",
-    "Publish a news article": "Publish a news article"
+    "Publish a news article": "Publish a news article",
+    "News tagging rules": "News tagging rules",
+    "See instructions": "See instructions"
 }
diff --git a/translations/es.json b/translations/es.json
index 32c7ac5f..453f97bf 100644
--- a/translations/es.json
+++ b/translations/es.json
@@ -311,5 +311,7 @@
     "Site Editors": "Editores del sitio",
     "Allow news posts": "Permitir publicaciones de noticias",
     "Publish": "Publicar",
-    "Publish a news article": "Publica un artículo de noticias"
+    "Publish a news article": "Publica un artículo de noticias",
+    "News tagging rules": "Reglas de etiquetado de noticias",
+    "See instructions": "Vea las instrucciones"
 }
diff --git a/translations/fr.json b/translations/fr.json
index 068971bd..a2774c54 100644
--- a/translations/fr.json
+++ b/translations/fr.json
@@ -311,5 +311,7 @@
     "Site Editors": "Éditeurs du site",
     "Allow news posts": "Autoriser les articles d'actualité",
     "Publish": "Publier",
-    "Publish a news article": "Publier un article de presse"
+    "Publish a news article": "Publier un article de presse",
+    "News tagging rules": "Règles de marquage des actualités",
+    "See instructions": "Voir les instructions"
 }
diff --git a/translations/ga.json b/translations/ga.json
index 547f6b56..927c5d32 100644
--- a/translations/ga.json
+++ b/translations/ga.json
@@ -311,5 +311,7 @@
     "Site Editors": "Eagarthóirí Suímh",
     "Allow news posts": "Ceadaigh poist nuachta",
     "Publish": "Fhoilsiú",
-    "Publish a news article": "Foilsigh alt nuachta"
+    "Publish a news article": "Foilsigh alt nuachta",
+    "News tagging rules": "Rialacha clibeála nuachta",
+    "See instructions": "Féach na treoracha"
 }
diff --git a/translations/hi.json b/translations/hi.json
index 758a933a..f3f64de1 100644
--- a/translations/hi.json
+++ b/translations/hi.json
@@ -311,5 +311,7 @@
     "Site Editors": "साइट संपादकों",
     "Allow news posts": "समाचार पोस्ट की अनुमति दें",
     "Publish": "प्रकाशित करना",
-    "Publish a news article": "एक समाचार लेख प्रकाशित करें"
+    "Publish a news article": "एक समाचार लेख प्रकाशित करें",
+    "News tagging rules": "समाचार टैगिंग नियम",
+    "See instructions": "निर्देश देखें"
 }
diff --git a/translations/it.json b/translations/it.json
index e103f50c..d6d636fe 100644
--- a/translations/it.json
+++ b/translations/it.json
@@ -311,5 +311,7 @@
     "Site Editors": "Editori del sito",
     "Allow news posts": "Consenti post di notizie",
     "Publish": "Pubblicare",
-    "Publish a news article": "Pubblica un articolo di notizie"
+    "Publish a news article": "Pubblica un articolo di notizie",
+    "News tagging rules": "Regole di tagging delle notizie",
+    "See instructions": "Vedere le istruzioni"
 }
diff --git a/translations/ja.json b/translations/ja.json
index ac44cd3e..a2bd4421 100644
--- a/translations/ja.json
+++ b/translations/ja.json
@@ -311,5 +311,7 @@
     "Site Editors": "サイト編集者",
     "Allow news posts": "ニュース投稿を許可する",
     "Publish": "公開する",
-    "Publish a news article": "ニュース記事を公開する"
+    "Publish a news article": "ニュース記事を公開する",
+    "News tagging rules": "ニュースのタグ付けルール",
+    "See instructions": "手順を参照してください"
 }
diff --git a/translations/oc.json b/translations/oc.json
index 3e7c8007..a8fb2e27 100644
--- a/translations/oc.json
+++ b/translations/oc.json
@@ -307,5 +307,7 @@
     "Site Editors": "Site Editors",
     "Allow news posts": "Allow news posts",
     "Publish": "Publish",
-    "Publish a news article": "Publish a news article"
+    "Publish a news article": "Publish a news article",
+    "News tagging rules": "News tagging rules",
+    "See instructions": "See instructions"
 }
diff --git a/translations/pt.json b/translations/pt.json
index a894c6c0..8bdaec28 100644
--- a/translations/pt.json
+++ b/translations/pt.json
@@ -311,5 +311,7 @@
     "Site Editors": "Editores do site",
     "Allow news posts": "Permitir postagens de notícias",
     "Publish": "Publicar",
-    "Publish a news article": "Publique um artigo de notícias"
+    "Publish a news article": "Publique um artigo de notícias",
+    "News tagging rules": "Regras de marcação de notícias",
+    "See instructions": "Veja as instruções"
 }
diff --git a/translations/ru.json b/translations/ru.json
index 6ae4b03f..e44288f5 100644
--- a/translations/ru.json
+++ b/translations/ru.json
@@ -311,5 +311,7 @@
     "Site Editors": "Редакторы сайта",
     "Allow news posts": "Разрешить публикации новостей",
     "Publish": "Публиковать",
-    "Publish a news article": "Опубликовать новостную статью"
+    "Publish a news article": "Опубликовать новостную статью",
+    "News tagging rules": "Правила тегирования новостей",
+    "See instructions": "См. Инструкции"
 }
diff --git a/translations/zh.json b/translations/zh.json
index d2a33c46..0d937a75 100644
--- a/translations/zh.json
+++ b/translations/zh.json
@@ -311,5 +311,7 @@
     "Site Editors": "网站编辑",
     "Allow news posts": "允许新闻发布",
     "Publish": "发布",
-    "Publish a news article": "发布新闻文章"
+    "Publish a news article": "发布新闻文章",
+    "News tagging rules": "新闻标记规则",
+    "See instructions": "见说明"
 }
diff --git a/webinterface.py b/webinterface.py
index 11212460..06c0a109 100644
--- a/webinterface.py
+++ b/webinterface.py
@@ -1356,11 +1356,31 @@ def htmlEditNewswire(translate: {}, baseDir: str, path: str,
         '      <br><b><label class="labels">' + \
         translate['Filtered words'] + '</label></b>\n'
     editNewswireForm += '      <br><label class="labels">' + \
-        translate['One per line'] + '</label>\n'
+        translate['One per line'] + '</label>'
     editNewswireForm += '      <textarea id="message" ' + \
         'name="filteredWordsNewswire" style="height:200px">' + \
         filterStr + '</textarea>\n'
 
+    hashtagRulesStr = ''
+    hashtagRulesFilename = \
+        baseDir + '/accounts/hashtagrules.txt'
+    if os.path.isfile(hashtagRulesFilename):
+        with open(hashtagRulesFilename, 'r') as rulesfile:
+            hashtagRulesStr = rulesfile.read()
+
+    editNewswireForm += \
+        '      <br><b><label class="labels">' + \
+        translate['News tagging rules'] + '</label></b>\n'
+    editNewswireForm += '      <br><label class="labels">' + \
+        translate['One per line'] + '.</label>\n'
+    editNewswireForm += \
+        '      <a href="' + \
+        'https://gitlab.com/bashrc2/epicyon/hashtagrules.txt' + \
+        '">' + translate['See instructions'] + '</a>\n'
+    editNewswireForm += '      <textarea id="message" ' + \
+        'name="hashtagRulesList" style="height:200px">' + \
+        hashtagRulesStr + '</textarea>\n'
+
     editNewswireForm += \
         '</div>'