riak_rabbit / scripts / load_stockdata.py

import csv, json
import riak

DATA_FILE="goog.csv"

def munge(r):
    return dict(
        date=r['Date'],
        volume=r['Volume'],
        adj_close=r['Adj Close'],
        open=r['Open'],
        high=r['High'],
        low=r['Low'])

def main():
    client = riak.RiakClient()
    bucket = client.bucket("goog_prices")
    fp = file(DATA_FILE, "rbU")
    reader = csv.reader(fp)
    h = reader.next()
    count = 0
    for line in reader:
        record = munge(dict(zip(h, line)))
        obj = bucket.new(record['date'])
        obj.set_data(json.dumps(record))
        obj.store()
        count += 1
    print "stored %s objects" % count

if __name__ == "__main__":
    main()
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.