#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Posts
    49
    Rep Power
    0

    Shopping Website - Python as a CGI


    Hi all,
    I am developing a Shopping website, where all the order summary will be Handled by the Python CGI.
    Few Things to Note.
    1. In the backend , i have a File having detail about the item and quantity before hand
    say
    ITEM1 - 100
    ITEM2 - 100

    My python Code should access the File.

    2. As soon as the Customer enter the quantity of a specific item, in the text box and clicks add to CART, the python code should deduct the quantity from the file using the Python code.

    How can i implement this, please help me with this.

    Any ideas and help would be appreciated.

    Shah
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Firstly, you might be better off using a DB (Data Base) such as MySQL or SQLite, both should make the task much simpler. If you do need to use a flat file then look at some of Pythons DB modules in the Python docs.

    http://www.python.org/doc/2.4/modindex.html

    If you decide to do this manually then you will need to read the file in and place the values into a dictionary. You can then edit the quantity for the item using it's name. This then needs to be written back to the file system .

    I would also suggest that you look at the pickle module.

    http://www.python.org/doc/2.4/lib/module-pickle.html

    Hope this helps,

    Mark.
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Posts
    49
    Rep Power
    0
    Hi!, Thanks

    Look like i have got some idea,

    U mean to Say,

    I will have a txt file, with data already.

    then i will use python coding to extract data from the file and store it in a dictinoary.

    then then use the dicitonary to manipulate the data.

    If this is the case, how would i get the data and store it in a Dictinoary,

    Also let me know,

    so my dictinoary will look like

    ['ITEM1',100,'ITEM2',100....]

    if u have some sample Source code let me know,

    I appreciate it, thanz

    Shah
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    I'm assuming that you will have created the file when the user signs in (picks up there Basket) to keep track of whatever they want to add to the basket.

    You will need to create a Dictionary for the contents of this file when you need to add something. Since the file is empty you should end up with an empty dictionary. When your parser is working that is .

    You will then read the file each time you need to see what is in the basket.

    I don't have any application specific code for you to look at since this is pretty specific. Try writing some code to do this yourself and we will advise on what needs to be done.

    This example shows how to populate a dictionary with items & quantities:

    Code:
    >>> basket = {}
    >>> basket['ITEM1'] = 1
    >>> basket['ITEM2'] = 1
    >>> basket['ITEM4'] = 2
    >>> basket
    {'ITEM2': 1, 'ITEM1': 1, 'ITEM4': 2}
    >>> basket['ITEM1'] += 1
    >>> basket
    {'ITEM2': 1, 'ITEM1': 2, 'ITEM4': 2}
    >>>
    Of course you might like to wrap this up in a class to make it easier to use. Adding actions to manipulate the basket i.e. Save for Later .

    Take care,

    Mark.
    programming language development: www.netytan.com Hula

  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    40
    Rep Power
    10
    Hi Shah,

    I think it's better if you can use a db to keep track of the records, if the table structure is simple, SQLite is a good choice, SQLite can output to txt file as well;
    you can use MySQL if your table structure is complex.
    Python db API is available for both db.

    have fun,
    ah new
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    34
    Further to netytan's post, if this is actually going to be a shop (rather than just something you are writing out of interest) then you probably want to make sure two people can't add something to their baskets when there's only one in stock, and that kind of thing.

    i.e. If it's in stock, and you add it to your basket, then you don't want someone else to get it while you are still paying.

    You also don't want:

    - 1 item left in stock.
    - Person 1 adds to basket
    - Person 1 goes to pay
    - Person 2 adds to basket
    - Person 1 finishes paying and you then count the item as sold
    - Person 2 goes to pay, and can pay because they have something in their basket.
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    174
    Rep Power
    11
    If you're going "the way of paypal" here's a URL showing in a general way how to use paypal ipn... with python of course.

    Paypal IPN and Python

    cheers
    sf2k
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Posts
    49
    Rep Power
    0
    Thank you,

    Let me review the concept, behind it

    Thanz

IMN logo majestic logo threadwatch logo seochat tools logo