Changeset 7575 for main/waeup.sirp


Ignore:
Timestamp:
2 Feb 2012, 23:03:46 (13 years ago)
Author:
uli
Message:

First silly phone-number converter.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/tools/fix_import_file.py

    r7574 r7575  
    3131import csv
    3232import datetime
     33import re
    3334import sys
    3435
     
    4849    'reg_state': 'reg_state',
    4950    'password': 'password',
     51    'phone': 'phone',
    5052    }
    5153
     
    8284##
    8385
     86# Look for the first sequence of numbers
     87RE_PHONE = re.compile('[^\d]*(\d*)[^\d]*')
     88
    8489def convert_fieldnames(fieldnames):
    8590    """Replace input fieldnames by fieldnames of COLNAME_MAPPING.
     
    175180        if value == "not set":
    176181            return ""
     182        return value
     183
     184    @classmethod
     185    def phone(self, value):
     186        """ '<num-seq1>-<num-seq2> asd' -> '--<num-seq1><num-seq2>'
     187
     188        Dashes and slashes are removed before looking for sequences
     189        of numbers.
     190        """
     191        value = value.replace('-', '')
     192        value = value.replace('/', '')
     193        match = RE_PHONE.match(value)
     194        phone = match.groups()[0]
     195        value = '--%s' % phone
    177196        return value
    178197
Note: See TracChangeset for help on using the changeset viewer.