Gnumed.business.gmLinuxMedNewsXML

Package Gnumed :: Package business :: Module gmLinuxMedNewsXML |
[frames] | no frames]

# Source Code for Module Gnumed.business.gmLinuxMedNewsXML

     1  # -*- coding: utf-8 -*-
     2  """Import LinuxMedNews XML data.
     3
     4          http://linuxmednews.com/1414243433"""
     5  #============================================================
     6  __author__ = "K.Hilbert <Karsten.Hilbert@gmx.net>"
     7  __license__ = "GPL v2"
     8
     9  # std lib
    10  import sys
    11  import datetime as pyDT
    12  import logging
    13  from xml.etree import ElementTree as etree
    14
    15
    16  # GNUmed
    17  if __name__ == '__main__':
    18          sys.path.insert(0, '../../')
    19          from Gnumed.pycommon import gmI18N
    20          gmI18N.activate_locale()
    21          gmI18N.install_domain()
    22  from Gnumed.pycommon import gmTools
    23  from Gnumed.pycommon import gmDateTime
    24  from Gnumed.business import gmPerson
    25
    26
    27  _log = logging.getLogger('gm-LinuxMedNewsXML')
    28
    29  #============================================================
    30 -def parse_xml_linuxmednews(xml_text=None, filename=None):
    31          dob_format = '%Y-%m-%d'
    32
    33          try:
    34                  if xml_text is None:
    35                          _log.debug('parsing XML in [%s]', filename)
    36                          pat = etree.parse(filename)
    37                  else:
    38                          pat = etree.fromstring(xml_text)
    39          except etree.ParseError:
    40                  _log.exception('Cannot parse, is this really XML ?')
    41                  return None
    42
    43          dto = gmPerson.cDTO_person()
    44
    45          dto.firstnames = pat.find('firstname').text
    46          dto.lastnames = pat.find('lastname').text
    47          dto.title = pat.find('name_prefix').text
    48          dto.gender = pat.find('gender').text
    49          dob = pyDT.datetime.strptime(pat.find('DOB').text, dob_format)
    50          dto.dob = dob.replace(tzinfo = gmDateTime.pydt_now_here().tzinfo)
    51          dto.dob_is_estimated = False
    52          dto.source = 'LinuxMedNews XML'
    53
    54          #dto.remember_comm_channel(channel=None, url=None):
    55          #dto.remember_address(number=None, street=None, urb=None, region_code=None, zip=None, country_code=None, adr_type=None, subunit=None)
    56
    57          return dto
    58
    59  #============================================================
    60  # main/testing
    61  #============================================================
    62  if __name__ == '__main__':
    63
    64          if len(sys.argv) == 1:
    65                  sys.exit()
    66
    67          if sys.argv[1] != 'test':
    68                  sys.exit()
    69
    70          #import datetime
    71          gmDateTime.init()
    72
    73 -        def test():
    74                  print parse_xml_linuxmednews(filename = sys.argv[2])
    75
    76          test()
    77