Commit e322d31 1 parent 5e6fcf7 commit e322d31 Copy full SHA for e322d31
File tree 3 files changed +30
-0
lines changed
3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change 20
20
'video' ,
21
21
'weather' ,
22
22
'wiki' ,
23
+ 'xkcd' ,
23
24
]
24
25
25
26
# List of modules that send data personalized to the user
Original file line number Diff line number Diff line change
1
+ import requests
2
+ from templates .text import TextTemplate
3
+ import json
4
+ import config
5
+
6
+ def process (input , entities = None ):
7
+ output = {}
8
+ try :
9
+ r = requests .get ('http://xkcd.com/info.0.json' )
10
+ data = r .json ()
11
+ number = data ['num' ]
12
+ title = data ['title' ]
13
+ link = data ['img' ]
14
+
15
+ output ['input' ] = input
16
+ output ['output' ] = TextTemplate ('Number: ' + number + '\n Title: ' + title + '\n Link: ' + link ).get_message ()
17
+ output ['success' ] = True
18
+ except :
19
+ error_message = 'Error retrieving latest XKCD'
20
+ ouput ['error_message' ] = TextTemplate (error_message ).get_message ()
21
+ output ['success' ] = False
22
+ return output
Original file line number Diff line number Diff line change
1
+ import modules
2
+
3
+ def test_xkcd ():
4
+ assert ('xkcd' == modules .process_query ('Show me the latest xkcd' )[0 ])
5
+ assert ('xkcd' == modules .process_query ('current xkcd' )[0 ])
6
+ assert ('xkcd' == modules .process_query ('show me an xkcd' )[0 ])
7
+ assert ('xkcd' != modules .process_query ('tell me a joke' )[0 ])
You can’t perform that action at this time.
0 commit comments