In [0]:
In [0]:
In [1]:
import requests
import json
import random
Requests and json are the two main modules used for this. Random can also be handy
In [2]:
getPrn = requests.get('http://api.redtube.com/?output=json&data=redtube.Videos.searchVideos&page=1')
Simple requests command to get the json object. This could be any json object - not just RedTube
In [25]:
loaPrn = json.loads(getPrn.text)
#print loaUrl
Convert it into readable text that you can work with
In [26]:
naoPrn = loaPrn[u'videos'][0]
print naoPrn
Compress down - look at first element of json object. You could cycle through older elements by increasing the int
In [27]:
ngePrn = naoPrn[u'video']
print ngePrn
Compress down again - this time video. It's always a bit of a trial and error to figure out navagating json objects, IPython is perfect for this.
This could be imporoved by turning the following unicode into a list and get the program to cycle though - saving off each element. Maybe save to a list?
In [28]:
ratPrn = ngePrn[u'rating']
In [31]:
thumPrn = ngePrn[u'thumb']
In [32]:
print thumPrn
In [33]:
ratPrn = ngePrn[u'ratings']
print ratPrn
In [34]:
urlPrn = ngePrn[u'url']
print urlPrn
In [35]:
viwPrn = ngePrn[u'views']
print viwPrn
In [36]:
idPrn = ngePrn[u'video_id']
print idPrn
In [37]:
pdaPrn = ngePrn[u'publish_date']
print pdaPrn
In [38]:
timPrn = ngePrn[u'duration']
print timPrn
In [39]:
titPrn = ngePrn[u'title']
print titPrn
In [40]:
tagPrn = ngePrn[u'tags']
print tagPrn
In [41]:
derbPrn = (tagPrn, 'tag_name')
print derbPrn
In [42]:
thNum = 0
taTrn = tagPrn[thNum]
print taTrn
thNum + 1
Out[42]:
TODO: Cycle the list and print all tags
In [44]:
naTrn = taTrn['tag_name']
print naTrn
In [44]:
In [48]:
import dominate
In [45]:
savPrn = open('savPrn','w')
savPrn.write('<h3 style="text-align: center;"><a href="' + urlPrn + '">')
savPrn.write(titPrn + '</a></h3>')
savPrn.write('<p style="text-align: right;">' + pdaPrn)
savPrn.write('</a></h3><img class="aligncenter" alt="null" src="' + thumPrn)
savPrn.write('" />')
savPrn.close()
In [24]:
opPrn = open('savPrn','r')
for op in opPrn:
print op
In [24]:
In [24]:
In [ ]: