Created
August 14, 2015 08:23
-
-
Save rudimuliawan/b1edabc45496cf815e94 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import csv | |
| import unicodecsv | |
| from django.core.exceptions import ValidationError | |
| from stamps.core.utils import normalize_phone | |
| from stamps.core.validators import validate_mobile_phone | |
| dirty_csv = '/home/rudi/Documents/seorae_dirty.csv' | |
| clean_csv = open('/home/rudi/Documents/seorae_clean.csv', 'w') | |
| with open(dirty_csv, 'rU') as csv_file: | |
| csv_writer = unicodecsv.writer(clean_csv) | |
| rows = csv.reader(csv_file) | |
| for row in rows: | |
| phone = row[0].strip().replace(' ', '').replace('-', '').decode('utf-8') | |
| print phone | |
| try: | |
| _ = validate_mobile_phone(phone) | |
| except ValidationError as e: | |
| pass | |
| else: | |
| phone = normalize_phone(phone) | |
| csv_writer.writerow([phone]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment