Taking data from here and putting it there
All of these (and more) are possible sources and targets for everyday data needs.
If time permits, issue all or part of the stored list as:
[div class="whatsnew-date"]
[h2]DATE[/h2]
[div class="book-summary"]
[p][span class="book-title"]TITLE[/span][/p]
[img class="thumblet" src="IMAGE_URL" /]
[div class="book-synopsis-summary"]
[p class="synopsis"]SYNOPSIS[/p]
[p class="summary"]SUMMARY[/p]
[/div]
[/div]
CREATE TABLE whatsnew
(
id INTEGER PRIMARY KEY,
title TEXT,
synopsis TEXT,
summary TEXT,
image BLOB,
date_added DATE
)
Built-in modules
Third-party modules
import is the way to get hold of an external module as a namespace
import os, sys
import urllib
from BeautifulSoup import BeautifulSoup as Soup
web_connection = urllib.urlopen ("http://local.goodtoread.org/whatsnew")
page = Soup (web_connection)
print page.find ("h2")
# or print page.h2
from datetime import datetime
date_block = page.find ("div", "whatsnew-date")
date_string = date_block.h2.string
#
# Wow! Feature
#
w, d, m, y = date_string.split ()
print w
print d
print m
print y
d = d[:-2]
date_string = "%s %s %s" % (d, m, y)
date = datetime.datetime.strptime (date_string, "%d %B %Y").date ()
summaries = []
for summary in date_block.findAll ("div", "book-summary"):
title = summary.find ("span", "book-title").string
summaries.append ((date, title))
import urlparse
image = summary.find ("img", "thumblet")
href = urlparse.urljoin ("http://local.goodtoread.org/", image['src'])
image_data = urllib.urlopen (href).read ()
open ("temp.jpg", "wb").write (image_data)
os.startfile ("temp.jpg")
import sqlite3
reviews = []
for review in date_block.findAll ("div", "book-summary"):
title = review.find ("span", "book-title").string
synopsis = review.find ("p", "synopsis").string
summary = review.find ("p", "summary").string
image = review.find ("img", "thumblet")
url = urlparse.urljoin ("http://local.goodtoread.org", image['src'])
image_data = urllib.urlopen (url).read ()
reviews.append ((date, title, synopsis, summary, image_data))
db = sqlite3.connect ("books.db")
db.execute ("DELETE FROM whatsnew")
db.executemany ("""
INSERT INTO whatsnew (title, synopsis, summary, image, date_added)
VALUES (?, ?, ?, ?, ?)
""",
reviews
)
db.commit ()