Created
          April 9, 2015 21:03 
        
      - 
      
- 
        Save higs4281/bfa9c06a5eb666f19154 to your computer and use it in GitHub Desktop. 
    dump script
  
        
  
    
      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
    
  
  
    
  | def dump_arrests(qset): | |
| header = [ | |
| 'name', | |
| 'dob', | |
| 'address', | |
| 'transient', | |
| 'sex', | |
| 'race', | |
| 'agency', | |
| 'booking_county', | |
| 'arrest_date', | |
| 'arrest_location', | |
| 'charges', | |
| 'watcher_url', | |
| 'arrest_notes', | |
| 'pk' | |
| ] | |
| with open('%s.csv' % slug, 'w') as f: | |
| writer = ckw(f) | |
| writer.writerow(header) | |
| for each in qset: | |
| NAME = "%s, %s" % (each.last_name, " ".join([bit for bit in [each.first_name, each.middle_name, each.name_suffix] if bit]) ) | |
| DOB = "%s" % each.birth_date | |
| CIT = "%s" % each.home_city | |
| ZIP = "%s" % each.home_zip | |
| ADDRESS = ", ".join([bit for bit in [each.home_address, CIT, ZIP] if bit]) | |
| WURL = each.get_url() | |
| CHARGES = ", ".join([ch.description for ch in each.charge_set.all()]) | |
| if each.arrest_notes: | |
| NOTES = each.arrest_notes.replace('\n', ' ').replace('\r', '') | |
| else: | |
| NOTES = each.arrest_notes | |
| writer.writerow([ | |
| NAME, | |
| DOB, | |
| ADDRESS, | |
| each.transient, | |
| each.gender, | |
| each.race, | |
| "%s" % each.arrest_agency, | |
| "%s" % each.booking_county, | |
| "%s" % each.arrest_date, | |
| each.arrest_location, | |
| CHARGES, | |
| WURL, | |
| NOTES, | |
| each.pk | |
| ]) | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment