![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | ||
|
Hobbyist Programmer
Join Date: Jul 2004
Location: Location
Posts: 138
Rep Power: 5
![]() |
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:
Quote:
![]() |
||
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
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.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#3 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
I would access the db directly, using PHPMyAdmin, or similar, and add products via a file.
EDIT: Woops, IR is on the same wavelength.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Jul 2004
Location: Location
Posts: 138
Rep Power: 5
![]() |
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?
|
|
|
|
|
|
#5 |
|
Hobbyist Programmer
Join Date: Jul 2004
Location: Location
Posts: 138
Rep Power: 5
![]() |
I would have edited my above message, but it is older than 60 mins
![]() 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 |
|
|
|
|
|
#6 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#7 | |
|
Hobbyist Programmer
Join Date: Jul 2004
Location: Location
Posts: 138
Rep Power: 5
![]() |
Quote:
|
|
|
|
|
|
|
#8 |
|
Programming Guru
![]() ![]() ![]() |
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.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Jul 2004
Location: Location
Posts: 138
Rep Power: 5
![]() |
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)
|
|
|
|
|
|
#10 |
|
Programming Guru
![]() ![]() ![]() |
I'll throw it around a bit also... been curious about it. Let us know if you run into problems.
__________________
http://jasonpowers.net "There are a thousand hacking at the branches of evil to one who is striking at the root." |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|