Created
August 4, 2015 14:00
-
-
Save chelnak/9042a3b60c17b9b00ee0 to your computer and use it in GitHub Desktop.
Create reservations from a csv of business groups
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/python | |
| 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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment