I'm quite new to Python and web2py hence when I started a little project 
for displaying some stats on a website I quickly got to points where I just 
got stack. I'll describe one hopefully someone would help with and provide 
some explanations. Basically it work but for the moment mostly manual which 
isn't that great. I define my table

db.define_table('table_1',
   Field('name',length=20,label='Name')...
   ...
   format='%(Name)s'
)
### then in Controler

def stats():
   db.table_1.id.readable = False
   db.table_1.stat1.represent = lambda value, row: stat(value)...
   ...
   return dict(stattable=SQLFORM.grid(db.table_1, ....
This gives me a nice web page where I can display all my stats and modify 
them as needed.

Then the need came to automate it somehow so I created a simple mySQL db 
where I feed my stats. New to databases so that was another challenge but I 
found a YT the basics of mySQL in 30 minutes :) Now I'd like to get the 
data from the external db to replace the values in w2p internal db where a 
row with the same name exists and add new rows where it doesn't.

import mySQLdb
def stat_db():
    statdb = MySQLdb.connect(host=....
    cur = statdb.cursor()   ### I goggled this bit :)

### here are my internal db fields
fields = db(db.table_1.id>0).select(db.tabela_1.name, distinct=True, 
orderby=db.table_1.name)  
### and the external db rows
cur.execute("select * from statdb")
rows= cur.fetchall()

So I suppose this gets all the rows from my external db but no idea how I 
would look for the right row in the internal db to replace the values. The 
common field in both db's is the 'name'. 

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to