From 78f8b8190f594e5a2079d450e69978ff13d7931a Mon Sep 17 00:00:00 2001 From: Alexis Filipozzi <alexis.filipozzi@gmail.com> Date: Fri, 17 Jun 2016 09:42:17 +0200 Subject: [PATCH] get text from title and remove useless tag --- README.txt | 26 +++++++++++++++++++++++++- formatter.py | 3 ++- html_parser.py | 15 +++++++++++++-- main.py | 1 + 4 files changed, 41 insertions(+), 4 deletions(-) diff --git a/README.txt b/README.txt index fc8a8be..607ef18 100644 --- a/README.txt +++ b/README.txt @@ -7,4 +7,28 @@ pip install -r requirements.txt Pour installer lxml il faut installer paquets : - libxml2-dev - python2.7-dev -- libxslt1-dev \ No newline at end of file +- libxslt1-dev + +Il faudra fournir un fichier de style guide-style.protoxml à la racine du dossier traduit, par exemple : +<?xml version="1.0" encoding="UTF-8"?> + +<package name="com.daysofwonder.dowml"> + + <message class="DOWMLStyle"> + + <text_attributes> + <size>22</size> + <font>TimesNewRomanPSMT</font> + <alignment>NEAR</alignment> + <vertical_alignment>CENTER</vertical_alignment> + </text_attributes> + + <layout> + <!--<size relative_width="1" relative_height="1"/>--> + <secondary_alignment>CENTER</secondary_alignment> + <weight>1</weight> + </layout> + + </message> + +</package> \ No newline at end of file diff --git a/formatter.py b/formatter.py index 55c2a16..13af4c8 100644 --- a/formatter.py +++ b/formatter.py @@ -55,7 +55,8 @@ class Formatter: self.format_body() def format_extra(self): - assert(self._data._title) + if not self._data._title: + self._data._title = "" title = etree.Element("property") title.attrib["key"] = "Title" diff --git a/html_parser.py b/html_parser.py index 22f2156..6bc0347 100644 --- a/html_parser.py +++ b/html_parser.py @@ -34,8 +34,19 @@ class Parser: def parse_title(self): title = self._soup.h1 - if title: - self._data._title = title.string + title_string = self.get_string_from_content(title) + self._data._title = title_string + + def get_string_from_content(self, content): + result = "" + for c in content: + name = c.name + if not name: + result += c.string + else: + result += self.get_string_from_content(c) + return result + def parse_content(self, content, lvl = 0): try: diff --git a/main.py b/main.py index 92ab54d..38d35c6 100644 --- a/main.py +++ b/main.py @@ -55,6 +55,7 @@ def parse_format_and_write_file(filename, dest, level): formatter.write_to_file(dest) except Exception as e: print "Error with file while fomatting: " + str(filename) + print "Error message: " + str(e) if __name__=="__main__": -- GitLab