#!/usr/bin/env python2.7 import pprint from googleapiclient.errors import HttpError from oauth import get_service_account_auth def list_surveys(surveys_service): """Prints the surveys that are owned by the given user. Args: surveys_service: The Surveys Service used to send the HTTP request. """ # [START google_surveys_list] surveys = surveys_service.surveys().list().execute() # [END google_surveys_list] return surveys if __name__ == '__main__': try: results = list_surveys(get_service_account_auth()) except HttpError, e: print 'Error listing surveys: %s\n' % e else: for s in results.get('resources'): pprint.pprint(s)
surveys_service: The Survey Service used to send the HTTP request. survey_id: The survey id for which we are downloading the survey results for. """ # [START google_surveys_results] survey = surveys_service.results().get_media(surveyUrlId=survey_id).execute() # [END google_surveys_results] return survey if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('survey_id', help='Survey ID to operate on.') parser.add_argument('--results_file', default='results.xls', help='Filename to store results. Defaults to results.xls.') args = parser.parse_args() try: survey_results = get_survey_results(get_service_account_auth(), args.survey_id) except HttpError, e: print 'Error fetching survey results: %s\n' % e else: f = open(args.results_file, 'wb') f.write(survey_results) print 'Successfully wrote survey %s results to %s\n' % (args.survey_id, args.results_file)
responses. For more details, visit https://developers.google.com/surveys/v2/reference/surveys. """ # [START google_surveys_start] if max_cost_per_response: json_spec = {'maxCostPerResponseNanos': max_cost_per_response} else: json_spec = {} surveys_service.surveys().start(resourceId=survey_id, body=json_spec).execute() # [END google_surveys_start] if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('survey_id', help='Survey ID to operate on.') parser.add_argument('--max_cost_per_response', default=0, help='Maximum cost to pay for incidence pricing responses. Defaults to 0.') args = parser.parse_args() try: start_survey(get_service_account_auth(), args.survey_id, args.max_cost_per_response) except HttpError, e: print 'Error starting survey: %s\n' % e else: print 'Started survey %s.\n' % args.survey_id
from googleapiclient.errors import HttpError from oauth import get_service_account_auth def delete_survey(surveys_service, survey_id): """Deletes a survey. Args: surveys_service: The Survey Service used to send the HTTP request. survey_id: The id of the survey to delete. """ # [START google_surveys_delete] surveys_service.surveys().delete(surveyUrlId=survey_id).execute() # [END google_surveys_delete] if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('survey_id', help='Survey ID to operate on.') args = parser.parse_args() try: delete_survey(get_service_account_auth(), args.survey_id) except HttpError, e: print 'Error deleting survey: %s\n' % e else: print 'Successully deleted survey with id %s\n' % args.survey_id
results for. """ # [START google_surveys_results] survey = surveys_service.results().get_media( surveyUrlId=survey_id).execute() # [END google_surveys_results] return survey if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('survey_id', help='Survey ID to operate on.') parser.add_argument( '--results_file', default='results.xls', help='Filename to store results. Defaults to results.xls.') args = parser.parse_args() try: survey_results = get_survey_results(get_service_account_auth(), args.survey_id) except HttpError, e: print 'Error fetching survey results: %s\n' % e else: f = open(args.results_file, 'wb') f.write(survey_results) print 'Successfully wrote survey %s results to %s\n' % ( args.survey_id, args.results_file)
def get_survey(surveys_service, survey_id): """Gets a survey. Args: surveys_service: The Survey Service used to send the HTTP request. survey_id: The id of the survey to get. Returns: A dictionary containing the survey fields. """ # [START google_surveys_get] survey = surveys_service.surveys().get(surveyUrlId=survey_id).execute() # [END google_surveys_get] return survey if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('survey_id', help='Survey ID to operate on.') args = parser.parse_args() try: survey_results = get_survey(get_service_account_auth(), args.survey_id) except HttpError, e: print 'Error fetching survey: %s\n' % e else: pprint.pprint(survey_results)
'question': 'What brand is your Android phone?', 'type': 'singleAnswer', 'answers': [ 'Google', 'Samsung', 'LG', 'Other'], } ] } survey = surveys_service.surveys().insert(body=body_def).execute() # [END google_surveys_create] return survey if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('owner_email', nargs='+', help='List of survey owner emails (space separated) for a new survey.') args = parser.parse_args() try: created_survey = create_survey(get_service_account_auth(), args.owner_email) except HttpError, e: print 'Error creating survey: %s\n' % e else: print 'Successully created survey with id %s\n' % created_survey['surveyUrlId']
'thresholdAnswers': ['Android phone'], }, { 'question': 'What brand is your Android phone?', 'type': 'singleAnswer', 'answers': ['Google', 'Samsung', 'LG', 'Other'], }] } survey = surveys_service.surveys().insert(body=body_def).execute() # [END google_surveys_create] return survey if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument( 'owner_email', nargs='+', help='List of survey owner emails (space separated) for a new survey.') args = parser.parse_args() try: created_survey = create_survey(get_service_account_auth(), args.owner_email) except HttpError, e: print 'Error creating survey: %s\n' % e else: print 'Successully created survey with id %s\n' % created_survey[ 'surveyUrlId']
https://developers.google.com/surveys/v2/reference/surveys. """ # [START google_surveys_start] if max_cost_per_response: json_spec = {'maxCostPerResponseNanos': max_cost_per_response} else: json_spec = {} surveys_service.surveys().start(resourceId=survey_id, body=json_spec).execute() # [END google_surveys_start] if __name__ == '__main__': parser = argparse.ArgumentParser() parser.add_argument('survey_id', help='Survey ID to operate on.') parser.add_argument( '--max_cost_per_response', default=0, help= 'Maximum cost to pay for incidence pricing responses. Defaults to 0.') args = parser.parse_args() try: start_survey(get_service_account_auth(), args.survey_id, args.max_cost_per_response) except HttpError, e: print 'Error starting survey: %s\n' % e else: print 'Started survey %s.\n' % args.survey_id