#! /usr/bin/env python

import os
import requests

CACHE_DIR = '/var/cache/vincennes'

if not os.path.exists(CACHE_DIR):
    os.mkdir(CACHE_DIR)

PARTS = ['menu', 'demarches', 'partenaires', 'agenda', 'magazine', 'autopromo',
        'services', 'acces-directs', 'kiosque', 'grand-projets', 'actualites']

for part in PARTS:
    r = requests.get('https://www.vincennes.fr/api/data/(Element)/' + part)
    r.raise_for_status()
    fd = file(os.path.join(CACHE_DIR, part), 'w')
    fd.write(r.content)
    fd.close()
