I was able to solve this by redirecting stdout to a file in advance of the 
DownloadReportWithAwql() call:


output_file = 'report_download.csv'


# Create report query.
report_query = (adwords.ReportQueryBuilder()
                .Select('CampaignId', 'CampaignName', 'CostPerConversion', 
'Conversions', 'Ctr', 'Cost',
                        'Clicks', 'Impressions', 'AverageCpc')
                .From('CAMPAIGN_PERFORMANCE_REPORT')
                .Where('CampaignStatus').In('ENABLED', 'PAUSED', 'REMOVED')
                .During('20180101,20180201')
                .Build())

# You can provide a file object to write the output to. For this
# demonstration, redirect stdout to a file object.
with open(output_file, 'w'):
    sys.stdout = open(output_file, 'w')
    report_downloader.DownloadReportWithAwql(
        report_query, 'CSV', sys.stdout, skip_report_header=True,
        skip_column_header=False, skip_report_summary=True,
        include_zero_impressions=True)


On Monday, April 23, 2018 at 12:55:56 AM UTC-7, John N. wrote:
>
> Very new to using API's and Python in general but I was able to generate 
> an AD Performance report using the following:
>
>   report_query = (adwords.ReportQueryBuilder()
>            .Select('CampaignName', 'AdGroupName', 'HeadlinePart1', 
> 'HeadlinePart2', 'Description', 'Clicks','Cost','AverageCpc','Labels')
>            .From('AD_PERFORMANCE_REPORT')
>            .Where('CampaignStatus').EqualTo('ENABLED')
>            .Where('Clicks').GreaterThan('0')
>            .During('YESTERDAY')
>            .Build())
>
>   report_downloader.DownloadReportWithAwql(
>       report_query, 'CSV', sys.stdout, skip_report_header=False,
>       skip_column_header=False, skip_report_summary=False,
>       include_zero_impressions=True)
>
> However, the call prints the output within the cmd prompt and closes. This 
> is probably a very basic question but how would i update the report 
> download section to produce a CSV file? Would i need to pass the 
> information to a Pandas DataFrame and write to excel?
>
> Thanks in advance.
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwords-api@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to adwords-api+unsubscr...@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/e7983ad7-f0be-4c57-bdcd-88d8f6849403%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to