Eichhoernchen/SiriServer — Issue #252: Display image from static URL
Author: autobuck
Created: 2012-02-14 17:03:43+00:00
State: open

Hi,
I am trying to adapt displaypicture.py to display a single static image from my own webserver. I'm having trouble presumably because I don't really understand what's going on with JSON parts. Can anybody help with this?

```
#displaypicture.py
#usage: say "display a picture of william shakespeare"
import re
import urllib2, urllib
import json
from plugin import *
from plugin import __criteria_key__
from siriObjects.uiObjects import AddViews
from siriObjects.answerObjects import AnswerSnippet, AnswerObject, AnswerObjectLine
class define(Plugin):
@register("en-GB", "(display|show me|show).*(security|home security|camera*)")
def defineword(self, speech, language, regex):
# Title = regex.group(regex.lastindex)
# Query = urllib.quote_plus(Title.encode("utf-8"))
SearchURL = u'http://example.getmyip.com:57080/jpg/current.jpg'
try:
jsonResponse = urllib2.urlopen(SearchURL).read()
jsonDecoded = json.JSONDecoder().decode(jsonResponse)
#ImageURL = jsonDecoded['responseData']['results'][0]['unescapedUrl']
ImageURL = jsonDecoded
#ImageURL = jsonResponse
view = AddViews(self.refId, dialogPhase="Completion")
ImageAnswer = AnswerObject(title=str('Test View'),lines=[AnswerObjectLine(image=ImageURL)])
view1 = AnswerSnippet(answers=[ImageAnswer])
view.views = [view1]
self.sendRequestWithoutAnswer(view)
self.complete_request()
except (urllib2.URLError):
self.say("Sorry, a connection to Brainfusion Security could not be established.")
self.complete_request()
```