Professional Documents
Culture Documents
Collaboration SEVT
May 2016
Contents
Contents .................................................................................................................................... 2
Prepare yourself ........................................................................................................................... 3
Topics......................................................................................................................................... 3
Introduction: What does it do? .............................................................................................. 4
Step 1. Configure Script ......................................................................................................... 4
Step 2. Import Python Lybraries ........................................................................................... 4
Step 3. Read Text File .............................................................................................................. 5
Step 4. Create Spark Room .................................................................................................... 6
Step 5. Add Users to Spark Room ......................................................................................... 6
Step 6. Execute the code ........................................................................................................ 6
Updates
0.1 first version
0.2 updates, added Gold Lab instructions
0.2b minor updates, removed test email addresses
0.2c minor updates
0.3 added editor instructions, added JSON response after running code, switched to all double quotes
Prepare yourself
IF you already have installed Python, continue from step 5 Install OpenPyXL library
1. Create a Spark account by entering your email address on this Spark website
2. Get your access token from Spark for Developers
3. Install Python 3.x (below we use 3.4.4, you could also use a newer version)
OSX
Download https://www.python.org/ftp/python/3.4.4/python-3.4.4-macosx10.6.pkg
- Run installation package
Windows
Download 64-bit https://www.python.org/ftp/python/3.4.4/python-3.4.4.amd64.msi
Download 32-bit https://www.python.org/ftp/python/3.4.4/python-3.4.4.msi
- Save and run the MSI package, use default install folder C:\Python34
- Add this folder to the Windows %PATH% variable
- Control panel, System, Advanced tab, Environment Variables button,
- Select PATH and click edit. Append C:\Python34 to the existing string.
4. Install the Requests Library
OSX
install Requests for Python 3, use these command line commands:
$ sudo curl -O https://bootstrap.pypa.io/get-pip.py
$ sudo python3 get-pip.py
$ sudo pip3 install requests
Windows
pip comes with Python 3.4 Windows
- Open a command line window and change to the C:\Python34\Scripts\ folder
- Execute: pip3.4 install requests
Reference Info
Official Python 3.4 installation documentation: https://docs.python.org/3.4/installing/
Official Requests library documentation: http://docs.python-requests.org/en/latest/
Topics
1. Configure Python Script
2. Read text file
3. Create room
4. Add users to room
OR (my preference), dont use Pythons IDLE but use a different text editor.
My favorites: OSX: Athom, TextWrangler WINDOWS: Notepad++
1. myToken: you can get your personal access token from the Spark developer
site:
Go to https://developer.ciscospark.com and login
Click the icon/avatar on the top right to see your token.
import json
import requests
import sys
1. Import json - to process the JSON data returned from the API call to Spark
2. Import requests - to send an receive data from the Spark APIs
3. Import sys - systems library to get parameters and read files
The code below will capture the parameters and store them in 2 variables. The last line of code
reads all lines in the text file and puts the result in variable email
argLen = len(sys.argv)
if argLen < 3 :
print("Usage: "+sys.argv[0]+" <email file> <room title>")
exit(0)
emailFile = sys.argv[1]
roomTitle = sys.argv[2]
# Read the email file and save the emails in an list
emails = [line.strip() for line in open(emailFile)]
{
"created": "2016-03-22T16:22:50.745Z",
"title": "My New Room",
"isLocked": False,
"type": "Group"
"lastActivity": "2016-03-23T09:25:08.217Z",
"id": "Y2xxx29zcGFyazovL30YS0xMDMZ1LTlhY2ItZWQwxxxkMzRlMDU2",
}
{
"created": "2016-03-22T16:22:50.745Z",
"isMonitor": "False",
"PersonId": "Y2xxx29zcGFyazovL30YS0xMDMZ1LTlhY2ItZWQwxxxkMzRlMDU2",
"isModerator": False,
"type": "Group"
"isModerator": False,
"personDisplayName": "apilab2016@gmail.com",
"personEmail": "apilab2016@gmail.com",
"RoomId": "Y2xxx29zcGFyazovL30YS0xMDMZ1LTlhY2ItZWQwxxxkMzRlMDU2",
}
CONGRATULATIONS !
You just completed the
Spark User Provisioning Lab
MORE INFO: http://cs.co/collabapi (Cisco internal link)