json data


In [1]:
import requests
import json
import random
import time
import os
import pprint
from numpy import *

BBC NEWS


In [221]:
getTop = requests.get(u'http://api.bbcnews.appengine.co.uk/topics')
oldTop = json.loads(getTop.text)
#print oldTop

In [222]:
woTop = random.randint(1,12)

In [223]:
catTop = blaTop[woTop]
print catTop


{u'id': u'business', u'title': u'Business'}

In [224]:
idTop = catTop['id']
print idTop


business

In [225]:
urBbc = ('http://api.bbcnews.appengine.co.uk/stories/' + idTop)
#print urBbc
getBbc = requests.get(urBbc)
oldBbc = json.loads(getBbc.text)
#print oldBbc

In [226]:
ehhBbc = oldBbc[u'topic'][u'title']
print ehhBbc


Business

In [227]:
storBbc = oldBbc[u'stories']

In [228]:
#print storBbc

In [229]:
faiBbc = storBbc[0]
print faiBbc


{u'thumbnail': u'http://news.bbcimg.co.uk/media/images/70057000/jpg/_70057195_70057137.jpg', u'published': 1379891109, u'link': u'http://www.bbc.co.uk/news/business-24194720#sa-ns_mchannel=rss&ns_source=PublicRSS20-sa', u'description': u'Building Societies are "well placed" to benefit from an economic recovery, and are showing "healthy" profits, says the accountancy firm KPMG.', u'title': u"Building societies 'are healthy'"}

In [230]:
thumBbc = faiBbc[u'thumbnail']

print thumBbc


http://news.bbcimg.co.uk/media/images/70057000/jpg/_70057195_70057137.jpg

In [231]:
titlBbc = faiBbc[u'title']
print titlBbc


Building societies 'are healthy'

In [232]:
desBbc = faiBbc[u'description']
print desBbc


Building Societies are "well placed" to benefit from an economic recovery, and are showing "healthy" profits, says the accountancy firm KPMG.

In [233]:
linBbc = faiBbc['link']
print linBbc


http://www.bbc.co.uk/news/business-24194720#sa-ns_mchannel=rss&ns_source=PublicRSS20-sa

In [234]:
pubBbc = faiBbc['published']

In [235]:
print pubBbc


1379891109

In [236]:
blaTop = oldTop['topics']
print blaTop

couId = list.count(blaTop, "{")
print couId


[{u'id': u'headlines', u'title': u'Headlines'}, {u'id': u'world', u'title': u'World'}, {u'id': u'science_and_environment', u'title': u'Science'}, {u'id': u'technology', u'title': u'Technology'}, {u'id': u'entertainment_and_arts', u'title': u'Entertainment'}, {u'id': u'business', u'title': u'Business'}, {u'id': u'politics', u'title': u'Politics'}, {u'id': u'health', u'title': u'Health'}, {u'id': u'education', u'title': u'Education'}, {u'id': u'uk', u'title': u'UK'}, {u'id': u'england', u'title': u'England'}, {u'id': u'scotland', u'title': u'Scotland'}, {u'id': u'wales', u'title': u'Wales'}]
0

In [237]:
savBbc = open('savBbc','w')
savBbc.write('<h1 style="text-align: center;"><strong>')
savBbc.write(ehhBbc)
savBbc.write('</strong></h1><h2 style="text-align: center;\"><a href=\"')
savBbc.write(linBbc)
savBbc.write('"><strong>')
savBbc.write(titlBbc)
savBbc.write('</strong></a></h2><p style="text-align: justify;">')
savBbc.write(desBbc)
savBbc.write('</p><img class="aligncenter" alt="" src="')
savBbc.write(thumBbc)
savBbc.write('" />')
savBbc.close()

tacBbc = open('tacBbc','w')
tacBbc.write(titlBbc)
tacBbc.close()

In [238]:
opnBbc = ('savBbc','r')
for opn in opnBbc:
    print(opn)


savBbc
r

In [207]:
ls


doc         pressBbc.py  savFile       TradePress.py
json.ipynb  random       tacBbc        tradeTitle
LastData    README.md    titleData     twitter.txt
mysite/     redditdrawn  tradeData     wordpress_xmlrpc
openArt     redDrawn.py  tradeLast.py
pprint      savBbc       trademe.py

In [152]:



---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-152-2766261fd348> in <module>()
----> 1 twitter

NameError: name 'twitter' is not defined

ArtControl, BroBeur, FreshFigure, WCMCKEE - json


In [32]:
ranUrl = random.randint(0,3)
myUrl = ('artcontrol.me', 'freshfigure.com/art', 'brobeur.com', 'wcmckee.com')
fulUrl = myUrl[ranUrl]
print fulUrl


artcontrol.me

In [33]:
comUrl = ('http://' + fulUrl + '/?wpapi=get_posts&dev=0')
print comUrl


http://artcontrol.me/?wpapi=get_posts&dev=0

In [34]:
getArt = requests.get(comUrl)
oldArt = json.loads(getArt.text)
#print oldBbc
anoArt = oldArt[u'posts']
#print anoArt

titArt = anoArt[0]
print titArt


{u'status': u'publish', u'category': [{u'term_group': u'0', u'count': u'25', u'name': u'Digital Painting', u'parent': u'0', u'term_id': u'169', u'cat_ID': u'169', u'category_description': u'', u'category_parent': u'0', u'cat_name': u'Digital Painting', u'category_count': u'25', u'term_taxonomy_id': u'181', u'taxonomy': u'category', u'category_nicename': u'digpaint', u'slug': u'digpaint', u'description': u''}], u'name': u'trademe-and-portraits', u'parent': u'0', u'title': u'trademe and portraits', u'url': u'http://artcontrol.me/?p=5204', u'author': [{u'first_name': u'Will', u'last_name': u'mckee', u'name': u'Will', u'nicename': u'wmckee', u'url': u'', u'slug': u'wmckee', u'gravatar': u'http://www.gravatar.com/avatar/5e2931ce807064cea9fc263f5346ad86?s=100&d=mm&r=g', u'id': u'1', u'description': u''}], u'excerpt': u"Hello. I've setup my laptop to run GIMP the same way as my desktop. This frees up my desktop for other uses.\r\n\r\nHere are several paintings I've done recently in GIMP (running", u'modified': u'2013-09-10 19:45:27', u'slug': u'trademe and portraits', u'comment_count': u'0', u'tag': [{u'term_group': u'0', u'count': u'84', u'name': u'GIMP', u'parent': u'0', u'term_id': u'59', u'term_taxonomy_id': u'60', u'taxonomy': u'post_tag', u'slug': u'gimp', u'description': u''}, {u'term_group': u'0', u'count': u'1', u'name': u'Linux Mint', u'parent': u'0', u'term_id': u'214', u'term_taxonomy_id': u'234', u'taxonomy': u'post_tag', u'slug': u'linux-mint', u'description': u''}, {u'term_group': u'0', u'count': u'1', u'name': u'trademe', u'parent': u'0', u'term_id': u'213', u'term_taxonomy_id': u'233', u'taxonomy': u'post_tag', u'slug': u'trademe', u'description': u''}], u'date': u'2013-09-10 19:45:27', u'type': u'post', u'id': u'5204', u'comment_status': u'open'}

In [35]:
exArt = titArt[u'excerpt']

In [37]:
print exArt


Hello. I've setup my laptop to run GIMP the same way as my desktop. This frees up my desktop for other uses.

Here are several paintings I've done recently in GIMP (running

In [38]:
namArt = titArt[u'title']
print namArt


trademe and portraits

In [38]:


In [38]:


In [39]:
urlArt = titArt[u'url']
print urlArt


http://artcontrol.me/?p=5204

In [40]:
datArt = titArt[u'date']
print datArt


2013-09-10 19:45:27

In [41]:
sluArt = titArt['slug']
print sluArt


trademe and portraits

In [42]:
parArt = titArt['parent']
print parArt


0

In [43]:
savFile = open('savFile','w')
savFile.write(namArt)
savFile.write(' - ')
savFile.write(exArt)
savFile.write(datArt)
savFile.close()

In [44]:
opeFile = open('savFile','r')
for file in opeFile:
    print file


trademe and portraits - Hello. I've setup my laptop to run GIMP the same way as my desktop. This frees up my desktop for other uses.



Here are several paintings I've done recently in GIMP (running2013-09-10 19:45:27

In [45]:
n = random.randint(1,20)
print n


2

In [67]:
timNum = random.randint(1,12)
print timNum


4

In [68]:
x = timNum * n
print x


60

In [69]:
lisNum = [n, timNum, x]
print lisNum


[15, 4, 60]

In [70]:
derbNum = list.sort(lisNum)
print derbNum


None

In [71]:
print lisNum


[4, 15, 60]