Skip to content

Commit

Permalink
schema
Browse files Browse the repository at this point in the history
  • Loading branch information
tlevine committed Mar 11, 2013
1 parent 6e19fe0 commit ac84ee9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
3 changes: 3 additions & 0 deletions readme.md
Expand Up @@ -6,6 +6,9 @@ current auroras.
# Set your credentials
export FLICKR_KEY=12345abcde...

# Create schema
sqlite3 aurora.db < schema.sql

# Download
./run

Expand Down
3 changes: 3 additions & 0 deletions requirements.txt
@@ -0,0 +1,3 @@
requests
lxml
dumptruck
14 changes: 5 additions & 9 deletions run.py 100644 → 100755
Expand Up @@ -3,6 +3,7 @@
import datetime
from requests import get
from lxml.etree import fromstring
from dumptruck import DumpTruck

FLICKR_REST = 'http://api.flickr.com/services/rest/'
GROUPS = ['40371529@N00']
Expand Down Expand Up @@ -54,9 +55,6 @@ def parse(text):

def group(dt, group_id, verbose = False):
'Download a group.'
if not os.path.isdir(group):
os.mkdir(group)

n_pages = 1
n_page = 1
while n_page <= n_pages:
Expand All @@ -71,7 +69,7 @@ def group(dt, group_id, verbose = False):
dt.insert(data, 'photo')

# Continue
photos = fromstring(text).xpath('//photos')[0]
photos = fromstring(text.encode('utf-8')).xpath('//photos')[0]
n_page = int(photos.xpath('@page')[0])
n_pages = int(photos.xpath('@pages')[0])
if verbose:
Expand All @@ -80,11 +78,9 @@ def group(dt, group_id, verbose = False):


def main():
# Make directories.
dt = DumpTruck(dbname = 'aurora.db')
for group_id in groups:
group(dt, group_id)

dt = DumpTruck(dbname = 'aurora.db', adapt_and_convert = True)
for group_id in GROUPS:
group(dt, group_id, verbose = True)

if __name__ == '__main__':
main()
33 changes: 33 additions & 0 deletions schema.sql
@@ -0,0 +1,33 @@
CREATE TABLE photo (
-- Page
page INTEGER,
within_page INTEGER,

-- Standard response
id TEXT NOT NULL,
owner TEXT NOT NULL,
title TEXT NOT NULL,
dateadded DATETIME NOT NULL,

-- Special fields
date_upload DATETIME NOT NULL,
date_taken DATETIME NOT NULL,
description TEXT NOT NULL,
url_l TEXT NOT NULL,
longitude REAL NOT NULL,
latitude REAL NOT NULL,
UNIQUE(page, within_page)
);

CREATE VIEW aurora AS SELECT
url_l AS 'url',
'http://www.flickr.com/photos/' || owner || '/' || id AS 'photostream_url'
'http://www.flickr.com/people/' || owner AS 'owner_url'
date_taken,
date_upload,
dateadded AS date_added,
title,
description,
longitude,
latitude
FROM photo;

0 comments on commit ac84ee9

Please sign in to comment.