<commit_before>'''
Utility function to fix rollcall votes
by adding corresponding bill numbers

usage:
export DJANGO_SETTINGS_MODULE=leg_tracker.settings
python updateBillNo.py
'''

import json, os, urllib, re

import django
django.setup()

from billcatcher.models import Bill, Rollcall

#bill_url = 'http://52.22.90.29/bills/?format=json'

rollcall_url = 'http://52.22.90.29/rollcalls/?format=json'

#load bill data
#bill_response = urllib.urlopen(bill_url)
#bill_data = json.loads(bill_response.read())
#print "...bills loaded"

#load all rollcall votes
rollcall_response = urllib.urlopen(rollcall_url)
rollcall_data = json.loads(rollcall_response.read())

#for each vote:
for vote in rollcall_data:
	#get the bill identifier
	bill_url = vote['bill_identifier']
	bill_response = urllib.urlopen(bill_url + '?format=json')
	bill_data = json.loads(bill_response.read())

	print 'Bill number:' + bill_data['bill_number']

	#get the bill number
	updated_values = {
		'bill_number' : bill_data['bill_number']
	}

	#update the rollcall data
	pk_id = vote['url'].split('/')[-2]
	_, created = Rollcall.objects.update_or_create(
		rollcall_id = pk_id,
		defaults = updated_values
	)<commit_msg>changing tactics<commit_after>'''
Utility function to fix rollcall votes
by adding corresponding bill numbers

usage:
export DJANGO_SETTINGS_MODULE=leg_tracker.settings
python updateBillNo.py
'''

import json, os, urllib, re

import django
django.setup()

from billcatcher.models import Bill, Rollcall

#bill_url = 'http://52.22.90.29/bills/?format=json'

rollcall_url = 'http://52.22.90.29/rollcalls/?format=json'

#load bill data
#bill_response = urllib.urlopen(bill_url)
#bill_data = json.loads(bill_response.read())
#print "...bills loaded"

#load all rollcall votes
rollcall_response = urllib.urlopen(rollcall_url)
rollcall_data = json.loads(rollcall_response.read())

#for each vote:
for vote in rollcall_data:
	#get the bill identifier
	bill_url = vote['bill_identifier']
	bill_response = urllib.urlopen(bill_url + '?format=json')
	bill_data = json.loads(bill_response.read())

	print 'Bill number:' + bill_data['bill_number']

	r = Rollcall.objects.get(rollcall_id=vote['url'].split('/')[-2])
	r.bill_number = bill_data['bill_number']
	r.save()

	#get the bill number
	#updated_values = {
	#	'bill_number' : bill_data['bill_number']
	#}

	#update the rollcall data
	#pk_id = vote['url'].split('/')[-2]
	#_, created = Rollcall.objects.update_or_create(
	#	rollcall_id = pk_id,
	#	defaults = updated_values
	#)
{'fraction_non_alphanumeric': 0.13269384492406075, 'fraction_numerical': 0.013988808952837729, 'mean_word_length': 5.621693121693122, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3682969', 'n_tokens_mistral': 947, 'n_tokens_neox': 895, 'n_words': 192}