8/4/2015 - 2:00 PM

Create reservations from a csv of business groups

Create reservations from a csv of business groups


import csv
import getpass
import json
import os

from jinja2 import Environment, FileSystemLoader
from globalconfig import url, usr, passwd
from vraapiclient import reservation

#Get the current directory
currentDirectory = os.path.dirname(os.path.abspath(__file__))

client = reservation.ReservationClient(url, usr, passwd)

#Set up jinja2 environment
env = Environment(loader=FileSystemLoader(currentDirectory))
template = env.get_template('reservationTemplate.json')

with open('businessgroups.csv') as c:
        reader = csv.DictReader(c)
        for row in reader:

                name = 'CLTEST01-Res-{groupname}'.format(groupname = row['name'].replace(" ",""))

                #Set all configurable parameters here
                params = {
                    'ReservationName': name,
                    'SubTenantId': row['id'],

                #Create the JSON payload for the POS
                #This is where params are added to the json payload

                payload = json.loads(template.render(params=params))

                reservation = client.createReservation(payload)

                print "Reservation created: {id}".format(id=reservation)