Format: text/x-python
⬇ Download File (2.9 KB)
   1  # Copyright 2010-2023 Kurt McKee <contactme@kurtmckee.org>
   2  # Copyright 2002-2008 Mark Pilgrim
   3  # All rights reserved.
   4  #
   5  # This file is a part of feedparser.
   6  #
   7  # Redistribution and use in source and binary forms, with or without
   8  # modification, are permitted provided that the following conditions are met:
   9  #
  10  # * Redistributions of source code must retain the above copyright notice,
  11  #   this list of conditions and the following disclaimer.
  12  # * Redistributions in binary form must reproduce the above copyright notice,
  13  #   this list of conditions and the following disclaimer in the documentation
  14  #   and/or other materials provided with the distribution.
  15  #
  16  # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS'
  17  # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18  # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19  # ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
  20  # LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  21  # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
  22  # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  23  # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
  24  # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  25  # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  26  # POSSIBILITY OF SUCH DAMAGE.
  27  
  28  import re
  29  
  30  from .w3dtf import _parse_date_w3dtf
  31  
  32  # Unicode strings for Hungarian date strings
  33  _hungarian_months = {
  34      'janu\u00e1r':   '01',  # e1 in iso-8859-2
  35      'febru\u00e1ri': '02',  # e1 in iso-8859-2
  36      'm\u00e1rcius':  '03',  # e1 in iso-8859-2
  37      '\u00e1prilis':  '04',  # e1 in iso-8859-2
  38      'm\u00e1ujus':   '05',  # e1 in iso-8859-2
  39      'j\u00fanius':   '06',  # fa in iso-8859-2
  40      'j\u00falius':   '07',  # fa in iso-8859-2
  41      'augusztus':     '08',
  42      'szeptember':    '09',
  43      'okt\u00f3ber':  '10',  # f3 in iso-8859-2
  44      'november':      '11',
  45      'december':      '12',
  46  }
  47  
  48  _hungarian_date_format_re = re.compile(r'(\d{4})-([^-]+)-(\d{,2})T(\d{,2}):(\d{2})([+-](\d{,2}:\d{2}))')
  49  
  50  
  51  def _parse_date_hungarian(date_string):
  52      """Parse a string according to a Hungarian 8-bit date format."""
  53      m = _hungarian_date_format_re.match(date_string)
  54      if not m or m.group(2) not in _hungarian_months:
  55          return None
  56      month = _hungarian_months[m.group(2)]
  57      day = m.group(3)
  58      if len(day) == 1:
  59          day = '0' + day
  60      hour = m.group(4)
  61      if len(hour) == 1:
  62          hour = '0' + hour
  63      w3dtfdate = '%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s%(zonediff)s' % \
  64                  {
  65                      'year': m.group(1),
  66                      'month': month,
  67                      'day': day,
  68                      'hour': hour,
  69                      'minute': m.group(5),
  70                      'zonediff': m.group(6),
  71                  }
  72      return _parse_date_w3dtf(w3dtfdate)
  73