|
| 1 | +#!/usr/bin/python |
| 2 | + |
| 3 | +from ciscosparkapi import CiscoSparkAPI |
| 4 | + |
| 5 | +# VERY simple script to create a room, post a message, and post a file. Alternaitvely, if the room already exists it will delete the room. |
| 6 | + |
| 7 | + |
| 8 | +#storing the Authentication token in a file in the OS vs. leaving in script |
| 9 | +# see https://developer.ciscospark.com/getting-started.html to copy your token and simply place in a text file |
| 10 | +fat=open ("/home/brad/brad_at.txt","r+") #open the file with the token |
| 11 | +access_token=fat.readline().rstrip() #strip whitespace, newline, etc. |
| 12 | +fat.close #close file |
| 13 | + |
| 14 | +room_name="TEST Hello World Room" #set the name of our test room - PLEASE NOTE this room can be delted by script so don't use a current name |
| 15 | +room_count=0 |
| 16 | +test_message="Hello World" #set the test message we will post |
| 17 | +test_url=["https://upload.wikimedia.org/wikipedia/commons/thumb/6/64/Cisco_logo.svg/375px-Cisco_logo.svg.png"] #set the location of a file we will post |
| 18 | + |
| 19 | +api = CiscoSparkAPI(access_token) #invoke the API |
| 20 | + |
| 21 | +rooms = api.rooms.list() #grab the list of rooms where the user(from Access Token) is a member |
| 22 | + |
| 23 | + |
| 24 | +for room in rooms: #iterate through list of rooms |
| 25 | + if room.title == room_name: #look for our room |
| 26 | + room_count += 1 #if we find a room with the same name increment a counter |
| 27 | + print (room.title) |
| 28 | + room_id = room.id #grab the room id |
| 29 | + print (room_id) |
| 30 | + api.rooms.delete(room_id) #delete the room |
| 31 | + print ("Room Deleted") |
| 32 | + |
| 33 | +if (room_count == 0): #Otherwise create the room, post a message, add a user, and attachment |
| 34 | + room = api.rooms.create(room_name) #create a room with room_name - room.id will be the id of this new room |
| 35 | + print room #prints returned JSON |
| 36 | + message = api.messages.create(room.id,None,None,test_message) #create a message in the new room |
| 37 | + print message |
| 38 | + message = api.messages.create(room.id,None,None,None,None,test_url) #Post a file in the new room from test_url |
| 39 | + print message |
| 40 | + |
| 41 | + |
| 42 | + |
| 43 | + |
| 44 | + |
0 commit comments