From 0f7a122a8447f0b0e9b7d2ef3f57869a277b0348 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sat, 29 Sep 2018 09:23:40 +0100 Subject: Move hashflag parsing to Utils.get_hashflags --- src/Utils.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'src/Utils.py') diff --git a/src/Utils.py b/src/Utils.py index d5ab69d2..3d1b3a92 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -1,5 +1,5 @@ -import json, re, traceback, urllib.request, urllib.parse, urllib.error, ssl -import string +import io, json, re, traceback, urllib.request, urllib.parse, urllib.error +import ssl, string import bs4 from . import ModuleManager @@ -296,3 +296,20 @@ def export(setting, value): def strip_html(s): return bs4.BeautifulSoup(s, "lxml").get_text() + +def get_hashflags(filename): + hashflags = {} + with io.open(filename, mode="r", encoding="utf8") as f: + for line in f: + line = line.strip("\n") + if not line.startswith("#"): + break + elif line.startswith("#--"): + line_split = line.split(" ", 1) + hashflag = line_split[0][3:] + value = None + + if len(line_split) > 1: + value = line_split[1] + hashflags[hashflag] = value + return hashflags.items() -- cgit v1.3.1-10-gc9f91