import sys

from additional_data_importer import SynonymImporter, AntonymImporter, EtymologyImporter
from dump_processor import Processor


class AdditionalDataProcessor(Processor):
    importer_classes = [SynonymImporter, AntonymImporter, EtymologyImporter]
    importers = [c(dry_run=False) for c in importer_classes]
    language_code = 'en'

    def worker(self, xml_buffer: str):
        title, content = self.base_worker(xml_buffer)
        for importer in self.importers:
            importer.process_non_wikipage(title, content, self.language_code)


class EnwiktionaryDumpImporter(object):
    importer_classes = [SynonymImporter, AntonymImporter]

    language_code = 'en'

    def __init__(self):
        self.processor = AdditionalDataProcessor(self.language_code)

    def run(self, filename):
        self.processor.process(filename)


if __name__ == '__main__':
    Importer = EnwiktionaryDumpImporter
    Importer.language_code = sys.argv[1]
    importer = Importer()
    importer.run('user_data/en.xml')

    # addi.run('English nouns')

    # addi = SubsectionImporter(data='etym/en', dry_run=True)
    # addi.section_name = 'Etymology'
    # addi.run('Lemmas by language')

@@ -1,18 +1,17 @@
 import 
-sys
+re
 %0A%0Afrom a
@@ -316,167 +316,583 @@
 es%5D%0A
+%0A
     
-language_code = 'en'%0A%0A    def worker(self, xml_buffer: str):%0A        title, content = self.base_worker(xml_buffer)%0A        for importer in self.importers:%0A
+def __init__(self):%0A        self.count = 0%0A        self.missing_translation_writer = None%0A        self.processor_class = None%0A        self.translation_lookup_table = None%0A        self.entry_writer = None%0A%0A    def worker(self, xml_buffer: str):%0A        title, content = self.base_worker(xml_buffer)%0A        languages = re.findall('==%5B %5D?(%5BA-Za-z%5D+)%5B %5D?==%5Cn', content)%0A        for language in languages:%0A            for importer in self.importers:%0A                if language in importer.languages:%0A                    language_code = importer.languages%5Blanguage%5D%0A        
     
@@ -945,21 +945,16 @@
 ontent, 
-self.
 language
@@ -1065,34 +1065,8 @@
 r%5D%0A%0A
-    language_code = 'en'%0A%0A
     
@@ -1138,26 +1138,8 @@
 sor(
-self.language_code
 )%0A%0A 
@@ -1280,49 +1280,8 @@
 ter%0A
-    Importer.language_code = sys.argv%5B1%5D%0A
     

work for all languages