I am node.js developer but i learnt python and made my python script work 
according to me. But what i am not getting is why its not working. Is it 
some python mistake or something else?
Eventhough if i run it directly it works fine.
On Wednesday, December 21, 2016 at 2:42:10 PM UTC+5:30, 
shu...@mobistreak.com wrote:
>
> If i call the script.py directly in my terminal then it works but when i 
> call it from my controller.js then it does not. A simple program works in 
> the script.py but my below code does not. I have tried it with options, 
> sending data using events like on, message but nothing works. Can anyone 
> help why it does not work? what should be done to make it work?
>
> *controller.js*
>>
>> var PythonShell = require('python-shell');PythonShell.defaultOptions = { 
>> scriptPath: './server/python/' };
>>
>> exports.adwords =  {
>>   handler: function(request, reply){
>>     PythonShell.run('script.py', function (err, res) {
>>       if (err) throw err;
>>       reply(res); 
>>     });}); 
>>
>> *script.py*
>
>  
>  
> import logging
>
> import osimport sys, jsonimport csvfrom googleads import adwords
>
> logging.basicConfig(level=logging.INFO)
> logging.getLogger('suds.transport').setLevel(logging.DEBUG)
>
> def main(client):
>    report_downloader = client.GetReportDownloader(version='v201609')
>
> report = {
>   'reportName': 'LAST_7_DAYS AD_PERFORMANCE_REPORT',
>   'dateRangeType': 'LAST_7_DAYS',
>   'reportType': 'AD_PERFORMANCE_REPORT',
>   'downloadFormat': 'CSV',
>   'selector': {
>       'fields': ['CallOnlyPhoneNumber', 'Cost']
>   }}
>
> file_path = 
> os.path.join(os.path.dirname(os.path.realpath(__file__)),"report.csv")
> f = open(file_path,'wb')
> f.write(report_downloader.DownloadReportAsString(report, 
> skip_report_summary=True))
> f.close()
> with open(file_path, 'rb') as f:
>   f.next()
>   reader = csv.DictReader(f)
>   data = dict()
>
>   for row in reader:
>     number = row['Call-only ad phone number'].replace("-", "")
>     number = number.strip()
>     if number:
>       if number in data:
>         data[number] += int(row['Cost'])
>       else:
>         data[number] = int(row['Cost'])
> print data
> f.close()
> if __name__ == '__main__':
>   adwords_client = adwords.AdWordsClient.LoadFromStorage()
>   adwords_client.SetClientCustomerId('111-111-1111') 
>   main(adwords_client)
>
>

-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and Google+:
https://googleadsdeveloper.blogspot.com/
https://plus.google.com/+GoogleAdsDevelopers/posts
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

You received this message because you are subscribed to the Google
Groups "AdWords 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 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/e4f6aaae-7434-42cb-9284-58c60e95cfad%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to