@@ -50,10 +50,11 @@ def CreateAuthorization(username, password, appid):
5050
5151 return token
5252
53- ## Perform Quote request
53+ ## Perform Chart request
5454def RetrieveChart (token , appid ):
55-
55+ ##construct a Chart request message
5656 ricName = raw_input ('Please input Symbol: ' )
57+
5758 chartRequestMsg = {'GetChart_Request_2' : {'chartRequest' : {
5859 'TimeSeries' : {'TimeSeriesRequest_typehint' : ['TimeSeriesRequest' ],
5960 'TimeSeriesRequest' : [{'Symbol' : ricName ,
@@ -270,15 +271,16 @@ def RetrieveChart(token, appid):
270271 'Culture' : 'en-US' ,
271272 'ReturnPrivateNetworkURL' : False ,
272273 }}}
273-
274- interdayURL = 'http://api.rkd.reuters.com/api/Charts/Charts.svc/REST/Charts_1/GetChart_2'
274+ ##construct Chart URL and header
275+ chartURL = 'http://api.rkd.reuters.com/api/Charts/Charts.svc/REST/Charts_1/GetChart_2'
275276 headers = {'content-type' : 'application/json;charset=utf-8' ,'X-Trkd-Auth-ApplicationID' : appid , 'X-Trkd-Auth-Token' : token }
276277
277278 print '############### Sending Chart request message to TRKD ###############'
278- chartResult = doSendRequest (interdayURL , chartRequestMsg ,headers )
279+ chartResult = doSendRequest (chartURL , chartRequestMsg ,headers )
279280 if chartResult is not None and chartResult .status_code == 200 :
280281 print 'Time Series Interday response message: '
281282 print chartResult .json ()
283+ ##print returned server, tag and image url
282284 server = chartResult .json ()['GetChart_Response_2' ]['ChartImageResult' ]['Server' ]
283285 print '\n Server: %s' % (server )
284286 tag = chartResult .json ()['GetChart_Response_2' ]['ChartImageResult' ]['Tag' ]
@@ -287,12 +289,16 @@ def RetrieveChart(token, appid):
287289 print 'Url: %s' % (imageUrl )
288290 return imageUrl
289291
292+ ##download image url from the TRKD Chart service as chart.png
290293def downloadChartImage (chartURL ):
294+ ##create header
291295 user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
292296 headers = { 'User-Agent' : user_agent }
293297 print '\n Downlading chart.png file from %s' % (chartURL )
298+ ##download image using Python urllib2
294299 downloadResult = urllib2 .Request (chartURL , headers = headers )
295300 imgData = urllib2 .urlopen (downloadResult ).read ()
301+ ##write file
296302 fileName = './chart.png'
297303 with open (fileName ,'wb' ) as outfile :
298304 outfile .write (imgData )
@@ -309,9 +315,10 @@ def downloadChartImage(chartURL):
309315
310316token = CreateAuthorization (username ,password ,appid )
311317print 'Token = %s' % (token )
312- ## if authentiacation success, continue subscribing Time Series intraday
318+ ## if authentiacation success, continue subscribing Chart
313319if token is not None :
314320 chartURL = RetrieveChart (token ,appid )
321+ ## if chart request success, continue downloading Chart image
315322 if chartURL is not None :
316323 print '############### Downloading Chart file from TRKD ###############'
317324 downloadChartImage (chartURL )
0 commit comments