Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Python (http://www.programmingforums.org/forum43.html)
-   -   Best way to do this? (http://www.programmingforums.org/showthread.php?t=11642)

bulio Oct 20th, 2006 8:48 AM

Best way to do this?
 
Hi everyone,

I would like to write a command-line program that allows me to input data to my website so that I can add new products without having to use the web-form to add items. The site can be found here: http://coyote-equipment.com

I have thought about two possible ways of going about this, and was wondering what you guys think would be the easiest way for a python newbie to do this. The site uses Joomla CMS with a shop module called Virtuemart.

1) Use a python module to connect to the site and automatically fill data in each form depending on what I type in the command line. (Ex: Serial #: 0000 would be placed in the product description field.)

2) Acess the mysql database and create new entries. I did a mysqldump and located an exisisting product to have an idea on how I would add a product. The syntax looks like this:

Quote:

(9,1,0,'CM00','A compressor for an SB-III','Compressor for an SB-III. Rebuilt and ready to use.','d75898348851e9d9820a1800d2c6d466.png',
'b94ba316eba27aa3a9ac650fabf79346.jpg','Y','0.0000','pounds',
'0.0000','0.0000','0.0000','inches','',0,1156305600,'','N',0,NULL,1156342698,1156342698,
'Compressor',0,'','',2,'piece',0),
So from what I can piece together, the syntax would be this:

Quote:

(9,1,0,'Product ID',' Short Description','thumbnail photo',
'large photo','Y','0.0000','pounds', //Measurements
'0.0000','0.0000','0.0000','inches','',0,1156305600,'','N',0,NULL,1156342698,1156342698,
'Item type',0,'','',2,'Item category',0),
Thanks everyone! :D

Infinite Recursion Oct 20th, 2006 9:07 AM

Personally, I'd go with a direct connection to the database. You may want to DESC the table so you have a handle on what the field names are, some of those values look random.

DaWei Oct 20th, 2006 9:10 AM

I would access the db directly, using PHPMyAdmin, or similar, and add products via a file.

EDIT: Woops, IR is on the same wavelength.

bulio Oct 20th, 2006 11:40 AM

Quote:

Originally Posted by Infinite Recursion (Post 117017)
Personally, I'd go with a direct connection to the database. You may want to DESC the table so you have a handle on what the field names are, some of those values look random.

So I first need to find out the description of each table field. Next, what module would I use to write to the mysql DB? (I'd need to connect to the DB via the internet). I would then prompt the user for information and store the information as variables. At the end, I would send the variables to the DB and have a new product created. Correct?

bulio Oct 20th, 2006 12:51 PM

I would have edited my above message, but it is older than 60 mins :S

Here are the mysql tables releavant to what I'm planning on doing. I'm not sure which ones affect the addition of a new product though (Except for description and price).

http://rafb.net/paste/results/FT1m4e18.html

DaWei Oct 20th, 2006 1:31 PM

I would presume that those things identified by 'product' would be the approriate items. Did you investigate phpMyAdmin? It gives you one hell of a lot of control over your database, including writing your own SQL, modifying the database and/or its contents with files (.csv or other text-based), backing up tables that you might screw up when you modify them, stuff like that. It is often made available by your host, just as a matter of course.

bulio Oct 20th, 2006 1:34 PM

Quote:

Originally Posted by DaWei (Post 117042)
I would presume that those things identified by 'product' would be the approriate items. Did you investigate phpMyAdmin? It gives you one hell of a lot of control over your database, including writing your own SQL, modifying the database and/or its contents with files (.csv or other text-based), backing up tables that you might screw up when you modify them, stuff like that. It is often made available by your host, just as a matter of course.

I haven't looked at it yet, although I can install it on the server if I want to (I think I'll take a look at it once the website is fully operational). I'd preferrably want to go the Python route, as It would be much faster than clicking around a web interface to add a product. I will be adding around 50 products a week and I think having a simple command-line utility would probably do the trick.

Infinite Recursion Oct 20th, 2006 1:35 PM

Yes. You will need a description of the fields, with emphasis on the type, null / not null, unique, etc. I don't know much about web development with Python, so I cannot elaborate on which module you would need... Sane would probably be able to answer that for you... I believe he is our resident Python wizard. I personally would have went with PHP for this effort.

Yep. You could either prompt the user for information or parse a master file of new products for a bulkload. Upon submission, you should have a new product (new entry in the DB) created.

In regards to the table... any fields that you don't need and are not required by other components (carts, reports, etc) you can place NULL values in manually, or you can selectively specify which columns you want to update in the 'insert' sql statement.



EDIT: Fancy meeting you all here... :) PhpMyAdmin is a great tool. I favor the idea of a command line utility for bulk adds. Assuming the backend is MySQL, the module you would need may be MySQLdb.

bulio Oct 20th, 2006 1:52 PM

Yeah, I've been currently toying with MySQLdb since this morning with Python 2.4, still trying to get it to connect to my mysql server. (I need to fix mysql permissions)

Infinite Recursion Oct 20th, 2006 2:15 PM

I'll throw it around a bit also... been curious about it. Let us know if you run into problems.


All times are GMT -5. The time now is 10:21 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC