"""The usual python-pptx chart refresh: read the chart's own categories and series, change APAC's
actual to $4.4M and hand the data back through chart.replace_data, the documented way to update
a chart.

    python python_pptx_edit.py input.pptx output.pptx
"""

import sys

from pptx import Presentation
from pptx.chart.data import CategoryChartData

src, dst = sys.argv[1], sys.argv[2]
prs = Presentation(src)
chart = next(shape.chart for shape in prs.slides[0].shapes if shape.has_chart)
plot = chart.plots[0]
categories = list(plot.categories)
data = CategoryChartData()
data.categories = categories
for series in plot.series:
    values = list(series.values)
    if series.name == "Actual":
        values[categories.index("APAC")] = 4_400_000
    data.add_series(series.name, values)
chart.replace_data(data)
prs.save(dst)
print("APAC actual set to", 4_400_000)
