def process_ur_records( ur_records ): for i, ur in ur_records: try: date_of_birth = date_from_value( ur.get('DOB', '') ) except Exception as e: safe_print( u'Row {}: Invalid birthdate "{}" ({}) {}'.format( i, ur.get('DOB',''), ur, e ) ) continue if not ur.get('License Numbers',''): safe_print( u'Row {}: Missing License Code '.format(i) ) continue attributes = { 'license_code': to_int_str(ur.get('License Numbers','')), 'last_name': to_str(ur.get('Last Name','')), 'first_name': to_str(ur.get('First Name','')), 'gender': gender_from_str(to_str(ur.get('Sex','m'))), 'date_of_birth':date_of_birth, 'city': to_str(ur.get('Member City','')), 'state_prov': to_str(ur.get('Member Province','')), 'nationality': to_str(ur.get('Nationality','')), 'zip_postal': to_str(get_key(ur,('ZipPostal','Zip''Postal','ZipCode','PostalCode','Zip Code','Postal Code',), None)) } attributes = { a:v for a, v in attributes.iteritems() if v is not None } if ur.get('Tag','').strip(): attributes['existing_tag'] = to_int_str(ur.get('Tag','')).strip() try: lh = LicenseHolder.objects.get( license_code=attributes['license_code'] ) if set_attributes(lh, attributes): lh.save() except LicenseHolder.DoesNotExist: lh = LicenseHolder( **attributes ) lh.save() safe_print( u'{i:>6}: {license:>8} {dob:>10} {uci_code} {last}, {first}, {city}, {state_prov}'.format( i=i, license=removeDiacritic(lh.license_code), dob=lh.date_of_birth.strftime('%Y/%m/%d'), uci_code=lh.uci_code, last=removeDiacritic(lh.last_name), first=removeDiacritic(lh.first_name), city=removeDiacritic(lh.city), state_prov=removeDiacritic(lh.state_prov) ) ) TeamHint.objects.filter( license_holder=lh ).delete() teams = [t.strip() for t in ur.get('Afiliates','').split(',')] if teams: last_team = None for t in teams: team = Team.objects.get_or_create( name=t )[0] last_team = team pcd = ur.get('Primary Cycling Discipline','').strip().lower() for id, d in discipline_id.iteritems(): if d.name.lower() in pcd: TeamHint( discipline=d, license_holder=lh, effective_date=effective_date, team=last_team ) break
def __repr__( self ): return utils.removeDiacritic( u'("{}",{}: event="{}",{}, rank={}, strs={}, vfr={}, oc={})'.format( self.license_holder.full_name(), self.license_holder.pk, self.event.name, self.event.pk, self.rank, self.starters, self.value_for_rank, self.original_category.code_gender ) )
def new_f(*args, **kwargs): parameters = [_getstr(a) for a in args] + [ u'{}={}'.format(key, _getstr(value)) for key, value in kwargs.iteritems() ] writeLog('{}({})'.format(f.__name__, removeDiacritic(u', '.join(parameters)))) return f(*args, **kwargs)
def getTagFromLicense(license, tag_from_license_id=0): license = utils.removeDiacritic(license.strip().upper()) for prefix in ('_XXX_', '_TEMP_', '_DUP_', '_CPY_'): if license.startswith(prefix): license = license[len(prefix):] license = license[:10] break # Try to find a trailing decimal component of the license code. result = reNumEnd.search(license) if result: # Get the text and number component of the license code. num = license[result.start():result.end()] num_count = len(num) text = license[:result.start()] if num_count < 15 else '' text_count = len(text) else: # This license code has no numeric component. text = license text_count = len(text) num = '0' num_count = 0 assert text_count <= 10, 'Maximum allowed text chars is 10' assert num_count <= 15, 'Maximum allowed num chars is 15' if num_count: return '{tag_from_license_id:02X}{text_count:X}{num_count:X}{text_hex}{num:0{byte_count}X}'.format( tag_from_license_id=255 - tag_from_license_id, text_count=text_count, num_count=num_count, text_hex=''.join('{:02X}'.format(ord(c)) for c in text), num=int(num), byte_count=bytes_from_digits[num_count] * 2, ) else: return '{tag_from_license_id:02X}{text_count:X}0{text_hex}'.format( tag_from_license_id=255 - tag_from_license_id, text_count=text_count, text_hex=''.join('{:02X}'.format(ord(c)) for c in text), )
def add_properties_page(wb, title_format, event, raceNumber): competition = event.competition server_date_time = timezone.localtime(event.date_time) ws = wb.add_worksheet('--CrossMgr-Properties') row = write_row_data(ws, 0, property_headers, title_format) row_data = [ u'-'.join([competition.name, event.name]), competition.organizer, competition.city, competition.stateProv, competition.country, server_date_time.strftime('%Y-%m-%d'), server_date_time.strftime('%H:%M'), timezone.get_current_timezone().zone, raceNumber, competition.discipline.name, competition.using_tags, ['km', 'miles'][competition.distance_unit], True if event.event_type == 1 else False, # Time Trial event.rfid_option, competition.ftp_host, competition.ftp_user, scramble.encode(utils.removeDiacritic(competition.ftp_password)), competition.ftp_path, competition.ftp_upload_during_race, competition.ga_tracking_id, event.road_race_finish_times, event.dnsNoData, getattr(event, 'win_and_out', False), u'-'.join([competition.long_name, event.name]) if competition.long_name else u'', competition.organizer_email, ] row = write_row_data(ws, row, row_data)
def country_from_ioc(ioc): return ioc_country.get(removeDiacritic(ioc.strip()[:3]).upper(), None)
def messsage_stream_write( s ): message_stream.write( removeDiacritic(s) )