Using the following python script to load the basketball tweets, I can
do bucket.get(key), which works. client.search(), doesn't work for me,
get_data() returns None:

#!/usr/bin/python

import csv
import riak
import simplejson
import sys
import datetime
import time
import uuid

# Connect to Riak.
client = riak.RiakClient(port=8087, transport_class=riak.RiakPbcTransport)

def load_csv2(bucket_name, filename):

        # Choose the bucket to store data in.
        bucket = client.bucket(bucket_name)

        c = csv.reader(open(filename))
        old_fields = c.next()
        fields = []
        for f in old_fields:
                if f == 'Time(PDT)':
                        f = 'timestamp'
                nf = f.lower()
                fields.append(nf)
        print fields

        for row in c:
                data = {
                }

                for ii in range(0,len(fields)-1):
                        data[fields[ii]] = row[ii]
                
                ts = data['timestamp']
                dt = datetime.datetime.strptime(data['timestamp'], "%b %d, %Y 
%H:%M:%S")
                ut = time.mktime(dt.timetuple())
                data['timestamp'] = int(ut)

                id = str(uuid.uuid1())
                print dt, id
                obj = bucket.new(id, data=data)
                obj.store(return_body=False)

                #~ sys.exit(1)

load_csv2('twitter', 'game1.csv')
#~ load_csv2('games', 'game2.csv')

Anyone using Riak Search with Python?

Thanks
Mike

On Mon, Apr 4, 2011 at 11:17 AM, Mike Stoddart <sto...@gmail.com> wrote:
> I wrote a simple Python client to insert data but when I try to
> perform a query, I get:
>
> Traceback (most recent call last):
>  File "./search.py", line 29, in <module>
>    row = result.get()
>  File "build/bdist.linux-x86_64/egg/riak/mapreduce.py", line 302, in get
>  File "build/bdist.linux-x86_64/egg/riak/bucket.py", line 245, in get
>  File "build/bdist.linux-x86_64/egg/riak/riak_object.py", line 290, in reload
>  File "build/bdist.linux-x86_64/egg/riak/transports/pbc.py", line 152, in get
>  File "build/bdist.macosx-10.6-universal/egg/google/protobuf/reflection.py",
> line 510, in setter
>  File 
> "build/bdist.macosx-10.6-universal/egg/google/protobuf/internal/type_checkers.py",
> line 91, in CheckValue
> TypeError: u'events' has type <type 'unicode'>, but expected one of:
> (<type 'str'>,)
>
> My query is:
>
> search_query = client.search('events', 'name:Fred')
>
> Is it complaining about the bucket name? I had to manually build protobuf.
>
> Thanks
> Mike
>

_______________________________________________
riak-users mailing list
riak-users@lists.basho.com
http://lists.basho.com/mailman/listinfo/riak-users_lists.basho.com

Reply via email to