【发布时间】:2020-04-29 17:33:06
【问题描述】:
我有这个我在 anaconda 中做的 python 脚本,并以 .py 格式下载到我的本地工作区
#!/usr/bin/env python
# coding: utf-8
# In[33]:
#!/usr/bin/env python
#
# Copyright 2016 Google Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""This example downloads a criteria performance report as a string with AWQL.
To get report fields, run get_report_fields.py.
The LoadFromStorage method is pulling credentials and properties from a
"googleads.yaml" file. By default, it looks for this file in your home
directory. For more information, see the "Caching authentication information"
section of our README.
"""
from googleads import adwords
import io
import pandas as pd
adwords_client = adwords.AdWordsClient.LoadFromStorage()
# Initialize appropriate service.
report_downloader = adwords_client.GetReportDownloader(version='v201809')
# Create report query.
report_query = (adwords.ReportQueryBuilder()
.Select('CampaignId', 'AdGroupId', 'Id', 'Criteria',
'CriteriaType', 'FinalUrls', 'Impressions', 'Clicks',
'Cost')
.From('CRITERIA_PERFORMANCE_REPORT')
.Where('Status').In('ENABLED', 'PAUSED')
.During('LAST_7_DAYS')
.Build())
output = io.StringIO()
report_downloader.DownloadReportWithAwql(
report_query, 'CSV', output, skip_report_header=True,
skip_column_header=False, skip_report_summary=True,
include_zero_impressions=True)
output.seek(0)
df = pd.read_csv(output)
print(df.head())
# In[44]:
df.to_csv("/Users/ezerivarola/Desktop/Google_ADS_API/report1.csv",index=False)
# In[ ]:
我正在尝试使用 crontab 使用以下命令来安排它:
* * * * * /usr/local/bin/python3 /Users/ezerivarola/Desktop/Google_ADS_API/Report1_DF.py
但是,虽然我没有收到任何错误,并且在查看邮件时我看到它正在运行,但没有生成脚本的 csv 文件。
有没有人知道这可能是什么问题?
【问题讨论】:
-
如果您从终端手动运行它,它会运行吗? /usr/local/bin/python3 /Users/ezerivarola/Desktop/Google_ADS_API/Report1_DF.py
-
是的,完美执行
-
您是否尝试过在 cron 命令中指定用户?就像是。 * * * * * 用户 /usr/local/bin/python3 /Users/ezerivarola/Desktop/Google_ADS_API/Report1_DF.py
-
我试过这个:* * * * * ezerivarola /usr/local/bin/python3 /Users/ezerivarola/Desktop/Google_ADS_API/Report1_DF.py。但什么也没发生