Re: [web2py] Re: File Upload and save to DB

2011-03-28 Thread Ismael Alejandro
??

On Thu, Mar 24, 2011 at 7:18 PM, Ismael Alejandro ialejandr...@gmail.comwrote:

 Hi again, working with the original section, now I have this:


 - On a CLIENT computer, I generate the INI file with this structure:
 [Room]

 name = room1
 color = red
 size = big

 - I send it by FTP to the computer where web2py is running

 - I have this script to parse and process the INI files on the server:

 import os
 import ConfigParser
 import traceback

 _configDir = _configuploads

 def parse(filename):
  try:
  config = ConfigParser.ConfigParser()
  print filename
  config.read(filename)
  rooms = config.sections()
  print Rooms: %s%rooms
  dictio = {}
  for room in rooms:
  dictio[rom] = {}
  options = config.options(room)
  print Ops: %s%options
  for option in options:
  dictio[room][option] = config.get(room,option)
  print dictio
  return 0
  except:
  print Something failed!
  print traceback.format_exc()
  return 1

 objects = os.listdir(_configDir)

 for item in objects:
  fitem = os.path.join(os.getcwd(),_configDir,item)
  parse(fitem)
  print =

 this is a script placed on the root web2py directory (I'm using the source
 version on a Windows PC)

 So with this script I parse the INI and put the info in to a dictionary
 called dictio, now,  how could I use this dictio info for saving it in the
 DB. Keys are generic and standard so they are the fields names. Values are
 the Values :P


 I'm not expert with python, in fact all above is made with some code of
 here, some of there


 Thanks! I hope you can help me!






[web2py] Re: File Upload and save to DB

2011-03-28 Thread villas
I already made a suggestion, did you look at this?...

http://code.google.com/p/csvstudio/

This code is able to parse csv files and create web2py models, it
might be helpful.
Thanks,  D


On Mar 29, 1:28 am, Ismael Alejandro ialejandr...@gmail.com wrote:
 ??

 On Thu, Mar 24, 2011 at 7:18 PM, Ismael Alejandro 
 ialejandr...@gmail.comwrote:

  Hi again, working with the original section, now I have this:

  - On a CLIENT computer, I generate the INI file with this structure:
  [Room]

  name = room1
  color = red
  size = big

  - I send it by FTP to the computer where web2py is running

  - I have this script to parse and process the INI files on the server:

  import os
  import ConfigParser
  import traceback

  _configDir = _configuploads

  def parse(filename):
   try:
   config = ConfigParser.ConfigParser()
   print filename
   config.read(filename)
   rooms = config.sections()
   print Rooms: %s%rooms
   dictio = {}
   for room in rooms:
   dictio[rom] = {}
   options = config.options(room)
   print Ops: %s%options
   for option in options:
   dictio[room][option] = config.get(room,option)
   print dictio
   return 0
   except:
   print Something failed!
   print traceback.format_exc()
   return 1

  objects = os.listdir(_configDir)

  for item in objects:
   fitem = os.path.join(os.getcwd(),_configDir,item)
   parse(fitem)
   print =

  this is a script placed on the root web2py directory (I'm using the source
  version on a Windows PC)

  So with this script I parse the INI and put the info in to a dictionary
  called dictio, now,  how could I use this dictio info for saving it in the
  DB. Keys are generic and standard so they are the fields names. Values are
  the Values :P

  I'm not expert with python, in fact all above is made with some code of
  here, some of there

  Thanks! I hope you can help me!




Re: [web2py] Re: File Upload and save to DB

2011-03-24 Thread Ismael Alejandro
Hi again, working with the original section, now I have this:


- On a CLIENT computer, I generate the INI file with this structure:
[Room]

name = room1
color = red
size = big

- I send it by FTP to the computer where web2py is running

- I have this script to parse and process the INI files on the server:

import os
import ConfigParser
import traceback

_configDir = _configuploads

def parse(filename):
try:
config = ConfigParser.ConfigParser()
print filename
config.read(filename)
rooms = config.sections()
print Rooms: %s%rooms
dictio = {}
for room in rooms:
dictio[rom] = {}
options = config.options(room)
print Ops: %s%options
for option in options:
dictio[room][option] = config.get(room,option)
print dictio
return 0
except:
print Something failed!
print traceback.format_exc()
return 1

objects = os.listdir(_configDir)

for item in objects:
fitem = os.path.join(os.getcwd(),_configDir,item)
parse(fitem)
print =

this is a script placed on the root web2py directory (I'm using the source
version on a Windows PC)

So with this script I parse the INI and put the info in to a dictionary
called dictio, now,  how could I use this dictio info for saving it in the
DB. Keys are generic and standard so they are the fields names. Values are
the Values :P


I'm not expert with python, in fact all above is made with some code of
here, some of there


Thanks! I hope you can help me!


[web2py] Re: File Upload and save to DB

2011-03-23 Thread villas
Hi Ialejandro

Take a look at Massimo's csvStudio.  There is also a video on vimeo.

I remember that you can make models from the CSV data and manipulate
the data with simple methods.

-D


On Mar 23, 1:39 am, Ialejandro ialejandr...@gmail.com wrote:
 HI everyone!! this time I have a new question...

 I'm developing an application where I generate an INI file (could be
 any file) with specific info.

 For example I have this ini structure

 [Room]

 name = room1
 color = red
 size = big

 (I generate the file dynamically from an X computer [x could be any
 computer running a python script)

 After the file is generated, is sent by FTP to my web2py server PC in
 C:\SERVER\iniuploads

 The question is, how could I read the ini file values and save them in
 a model??

 Some to consider is:

 - Could be many ini files (each one with the room name, so the name of
 the file is the same of [Room])
 - I need to check every X time if a new ini file has been uploaded,
 and new files must be processed (save on db)
 - After a file is processed it must be deleted

 How could I do this?? It's ok to change the ini to any other file
 format, what I need is the contained info in a DB.


[web2py] Re: File Upload and save to DB

2011-03-22 Thread ron_m
I presume you know enough Python to be able to open these files, read and 
parse the content and come up with a data structure such as a dict of the 
name value pairs in the file.

In your own standalone program you can use the DAL by itself

from gluon/dal import DAL, Field

then you can connect to your database and define your model as per chapter 6 
of the book. Look at Chapter 4 first to get a good overview of web2py.

The data from the file can be driven into the appropriate table with 
db.insert(...)

Unlike the web applications you need to db.commit() at the end if everything 
succeeds or db.rollback() if you want to back out, this is done 
automatically for you in the web request-response cycle.


Another option is you could write a normal web app that has a controller 
that will take the ini file key value pairs as keyword args and then either 
fire the URL at the origin or a standalone program that reads the ini files 
and fires the URLs in using urllib2.