issues with bad names in peewee and python

Booting, installing, newbie
Post Reply
Message
Author
sayhello_to_the_world
Posts: 77
Joined: Mon 24 Dec 2012, 15:19

issues with bad names in peewee and python

#1 Post by sayhello_to_the_world »

update 3 - after the installation of peewwee i runned the script again,,,

Code: Select all



    import urllib
    import urlparse
    import re
    import peewee
    import json
    
    db = MySQLDatabase('cpan', user='root',passwd='rimbaud')
    
    class User(Model):
        name = TextField()
        cname = TextField()
        email = TextField()
        url = TextField()
    
        class Meta:
            database = db # this model uses the cpan database
    
            
    User.create_table() #ensure table is created
    
    
    url = "http://search.cpan.org/author/?W"
    html = urllib.urlopen(url).read()
    for lk, capname, name in re.findall('<a href="(/~.*?/)"><b>(.*?)</b></a><br/><small>(.*?)</small>', html):
        alk = urlparse.urljoin(url, lk)
    
        data = { 'url':alk, 'name':name, 'cname':capname }
    
        phtml = urllib.urlopen(alk).read()
        memail = re.search('<a href="mailto:(.*?)">', phtml)
        if memail:
            data['email'] = memail.group(1)
            
    
    data = json.load() #your json data file here
    
    for entry in data: #assuming your data is an array of JSON objects
        user = User.create(name=entry["name"], cname=entry["cname"],
            email=entry["email"], url=entry["url"])
        user.save()
    

i got back the following results:

Code: Select all

       

    Traceback (most recent call last):
      File "cpan5.py", line 10, in <module>
        db = MySQLDatabase('cpan', user='root',passwd='rimbaud')
    NameError: name 'MySQLDatabase' is not defined
    linux-70ce:/home/martin/perl # 
well i guess that i have some issues with the name.

note:
the database is named cpan
the user is root
the passwd is rimbaud

well what do i have done wrong?

just need some tipps.

by the way : the database is up and running....a mysql db on a opensuse 13.1

Post Reply