if error_result: logger.error("There was an error trying to create a politician") else: logger.debug( "It seems we have found a politician: {display_full_name}".format( display_full_name=politician_on_stage.display_full_name())) results = { 'error_result': error_result, 'politician_on_stage': politician_on_stage, } return results WE_VOTE_API_KEY = get_environment_variable("WE_VOTE_API_KEY") ORGANIZATIONS_URL = get_environment_variable("ORGANIZATIONS_URL") ORGANIZATIONS_JSON_FILE = get_environment_variable("ORGANIZATIONS_JSON_FILE") CANDIDATE_CAMPAIGNS_URL = get_environment_variable("CANDIDATE_CAMPAIGNS_URL") CANDIDATE_CAMPAIGNS_JSON_FILE = get_environment_variable( "CANDIDATE_CAMPAIGNS_JSON_FILE") POSITIONS_URL = get_environment_variable("POSITIONS_URL") POSITIONS_JSON_FILE = get_environment_variable("POSITIONS_JSON_FILE") # TODO DALE Get this working def import_we_vote_organizations_from_json(request, load_from_uri=False): """ Get the json data, and either create new entries or update existing :return: """
handle_record_not_saved_exception(e, logger=logger) if error_result: logger.error("There was an error trying to create a politician") else: logger.debug("It seems we have found a politician: {display_full_name}".format( display_full_name=politician_on_stage.display_full_name() )) results = { 'error_result': error_result, 'politician_on_stage': politician_on_stage, } return results WE_VOTE_API_KEY = get_environment_variable("WE_VOTE_API_KEY") ORGANIZATIONS_URL = get_environment_variable("ORGANIZATIONS_URL") ORGANIZATIONS_JSON_FILE = get_environment_variable("ORGANIZATIONS_JSON_FILE") CANDIDATE_CAMPAIGNS_URL = get_environment_variable("CANDIDATE_CAMPAIGNS_URL") CANDIDATE_CAMPAIGNS_JSON_FILE = get_environment_variable("CANDIDATE_CAMPAIGNS_JSON_FILE") POSITIONS_URL = get_environment_variable("POSITIONS_URL") POSITIONS_JSON_FILE = get_environment_variable("POSITIONS_JSON_FILE") # TODO DALE Get this working def import_we_vote_organizations_from_json(request, load_from_uri=False): """ Get the json data, and either create new entries or update existing :return: """ if load_from_uri:
# import_export_voting_info_project/controllers.py # Brought to you by We Vote. Be good. # https://github.com/votinginfoproject # -*- coding: UTF-8 -*- from wevotebase.base import get_environment_variable import wevote_functions.admin import xmltodict VOTING_INFO_PROJECT_SAMPLE_XML_FILE = get_environment_variable( "VOTING_INFO_PROJECT_SAMPLE_XML_FILE") logger = wevote_functions.admin.get_logger(__name__) def import_voting_info_project_from_xml(): logger.info("TO BE IMPLEMENTED") load_from_url = False if load_from_url: # Request json file from Google servers logger.info("Loading Sample XML from url") # request = requests.get(VOTER_INFO_URL, params={ # "key": GOOGLE_CIVIC_API_KEY, # This comes from an environment variable # "address": "254 Hartford Street San Francisco CA", # "electionId": "2000", # }) # structured_json = json.loads(request.text) else: # Load saved json from local file logger.info("Loading sample XML from local file")
# Brought to you by We Vote. Be good. # https://developers.google.com/resources/api-libraries/documentation/civicinfo/v2/python/latest/civicinfo_v2.elections.html # -*- coding: UTF-8 -*- import json import requests from exception.models import handle_record_not_found_exception from import_export_google_civic.models import GoogleCivicContestOffice, GoogleCivicBallotItemManager, \ GoogleCivicCandidateCampaign, GoogleCivicContestReferendum, GoogleCivicElection from wevotebase.base import get_environment_variable from wevote_functions.models import logger, value_exists # TODO DALE is it ok to import logger like above? the following line was saying it couldn't find admin.get_logger # logger = wevote_functions.admin.get_logger(__name__) GOOGLE_CIVIC_API_KEY = get_environment_variable("GOOGLE_CIVIC_API_KEY") VOTER_INFO_URL = get_environment_variable("VOTER_INFO_URL") VOTER_INFO_JSON_FILE = get_environment_variable("VOTER_INFO_JSON_FILE") # Complete description of all Google Civic fields: # https://developers.google.com/resources/api-libraries/documentation/civicinfo/v2/python/latest/index.html # voterInfoQuery Details: # https://developers.google.com/resources/api-libraries/documentation/civicinfo/v2/python/latest/civicinfo_v2.elections.html#voterInfoQuery def import_voterinfo_from_json(save_to_db): """ Get the json data, and call the sub functions that :return: """ load_from_google_servers = False if load_from_google_servers:
# import_export_theunitedstatesio/models.py # Brought to you by We Vote. Be good. # -*- coding: UTF-8 -*- from django.db import models import csv from wevotebase.base import get_environment_variable import wevote_functions.admin LEGISLATORS_CURRENT_CSV_FILE = get_environment_variable("LEGISLATORS_CURRENT_CSV_FILE") # UnitedStates.io CSV Field names legislators_current_fields = ( "last_name", # row[0] "first_name", # row[1] "birthday", # row[2] "gender", # row[3] "type", # row[4] "state", # row[5] "district", # row[6] "party", # row[7] "url", # row[8] "address", # row[9] "phone", # row[10] "contact_form", # row[11] "rss_url", # row[12] "twitter", # row[13] "facebook", # row[14] "facebook_id", # row[15] "youtube", # row[16]
# import_export_voting_info_project/controllers.py # Brought to you by We Vote. Be good. # https://github.com/votinginfoproject # -*- coding: UTF-8 -*- from wevotebase.base import get_environment_variable import wevote_functions.admin import xmltodict VOTING_INFO_PROJECT_SAMPLE_XML_FILE = get_environment_variable("VOTING_INFO_PROJECT_SAMPLE_XML_FILE") logger = wevote_functions.admin.get_logger(__name__) def import_voting_info_project_from_xml(): logger.info("TO BE IMPLEMENTED") load_from_url = False if load_from_url: # Request json file from Google servers logger.info("Loading Sample XML from url") # request = requests.get(VOTER_INFO_URL, params={ # "key": GOOGLE_CIVIC_API_KEY, # This comes from an environment variable # "address": "254 Hartford Street San Francisco CA", # "electionId": "2000", # }) # structured_json = json.loads(request.text) else: # Load saved json from local file logger.info("Loading sample XML from local file")
# import_export_theunitedstatesio/models.py # Brought to you by We Vote. Be good. # -*- coding: UTF-8 -*- from django.db import models import csv from wevotebase.base import get_environment_variable import wevote_functions.admin LEGISLATORS_CURRENT_CSV_FILE = get_environment_variable( "LEGISLATORS_CURRENT_CSV_FILE") # UnitedStates.io CSV Field names legislators_current_fields = ( "last_name", # row[0] "first_name", # row[1] "birthday", # row[2] "gender", # row[3] "type", # row[4] "state", # row[5] "district", # row[6] "party", # row[7] "url", # row[8] "address", # row[9] "phone", # row[10] "contact_form", # row[11] "rss_url", # row[12] "twitter", # row[13] "facebook", # row[14] "facebook_id", # row[15] "youtube", # row[16]