diff --git a/django_diu/import_command.py b/django_diu/import_command.py index 96310ad56fe9fb4b3a84ee899ee464899ec4f283..69cde4ff687452b170e4855e539cc406154f15bb 100644 --- a/django_diu/import_command.py +++ b/django_diu/import_command.py @@ -8,6 +8,8 @@ from django.core.management import BaseCommand, CommandError import mysql.connector import requests_cache import click +import xml.etree.ElementTree as ET + class MyConverter(mysql.connector.conversion.MySQLConverter): @@ -158,6 +160,21 @@ class DataFrameImportTask(ImportTask): self.source_count = self.dataframe.shape[0] +class XMLImportTask(ImportTask): + + description = "Abstract XML import task" + + xmlFile = None + xpathSelector = "*" + + def open_data_source(self): + tree = ET.parse(argv[1]) + root = tree.getroot() + self.rows = root.findall(self.xpathSelector) + + def count_source(self): + self.source_count = len(self.rows) + class ImportCommand(BaseCommand): help = "Generic command to import data into a django database"