Advertisement
Guest User

Komgal-Test

a guest
Sep 30th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. from django.http import HttpResponse
  2. import urllib2
  3. import json
  4.  
  5. def index(request):
  6.    
  7.     #defining endpoint variable
  8.     endpoint="url here"
  9.    
  10.     #getting the data from the web
  11.     serialized_data = urllib2.urlopen(endpoint).read()
  12.    
  13.     #serilize data to json
  14.     output= json.loads(serialized_data)
  15.    
  16.     id=output['channels'][0]['feeds'][0]['entry_id']
  17.     value=output['channels'][0]['feeds'][0]['value']
  18.     created=output['channels'][0]['feeds'][0]['created_at']
  19.    
  20.     #html='test %s' %(id)
  21.    
  22.     html='<head> <title> komagal </title> </head> <body> <center> <p1> The result which is parsed from the API is : </p1> <br/> <p2> id : %s </p2> <br/> <p2> created at : %s</p2> <br/> <p2> value : %s</p2> </center> </body>' %(id,created,value)
  23.    
  24.     #setting the ouput
  25.     return HttpResponse(html)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement