Я делал это так, но не всегда правильный бюджет получается, может коллективным разумом получится разобраться?
def get_amount():
def get_budget_for_client():
service = config.adwords_client.GetService('BudgetOrderService', version='v201702')
selector = {
'fields': ['BudgetOrderName', 'SpendingLimit', 'TotalAdjustments'],
}
budgets = []
page = service.get(selector)
if 'entries' in page and page['entries']:
for payer in page['entries']:
budgets.append(round(int(payer['spendingLimit']['microAmount']) / 1000000, 2))
all_budgets = sum(budgets)
return all_budgets
def get_spend_for_client():
report_downloader = config.adwords_client.GetReportDownloader(version='v201702')
report_query = "SELECT Cost FROM ACCOUNT_PERFORMANCE_REPORT "
report = report_downloader.DownloadReportAsStringWithAwql(report_query, 'CSV', skip_report_header=True,
skip_column_header=False,
skip_report_summary=True,
client_customer_id=customer_id)
file = io.StringIO(report)
reader = csv.DictReader(file, delimiter=',')
for row in reader:
return round(float(row['Cost']) / 1000000, 2)
all_moneys = get_budget_for_client()
spend = get_spend_for_client()
return round(all_moneys - spend)