Find the answer to your Linux question:
Results 1 to 4 of 4
I've been working with SLES 10.x for just over a year now, running CMS's like Xoops and WordPress/WordPress MU. I've been working with MySQL, PHP, and most recently, Python, as ...
  1. #1
    Just Joined!
    Join Date
    Mar 2008
    Posts
    2

    Call Python script from web browser

    I've been working with SLES 10.x for just over a year now, running CMS's like Xoops and WordPress/WordPress MU. I've been working with MySQL, PHP, and most recently, Python, as a part of these implementations.

    We have some intranet sites running that a manager wants to see site stats on, so I have implemented the excellent Scratchy parser and it produces reports that will work great for this purpose. It's Python based, and I'm using the report.py function documented here
    to produce monthly reports. This script parses data from the Apache access_log and drops it into a MySQL database, and then drops that data into an HTML file with an associated stylesheet. These are dropped into the /usr/share/scratchy directory into a subdirectory created for that date.

    My objective is to create an access point for the managers where they can call this script using the --month and --year parameters via web browser. I want to create an "admin page" that allows them to select month and year, perhaps (but not mandatory) from drop down menus, which then invokes the report.py script on my server, it compiles the report, and then the browser returns the HTML file using the stylesheet.

    I've gotten my feet wet in web development, I've taken some programming classes (C++ and Java) in the past, but I'm by no means well-versed and am still learning. I'm not sure which is the best angle to approach the this problem and am looking for recommendations from more experienced folks on how I should handle this. I am really trying to build my coding skills and so any pointers as to the best approach will be much appreciated!

    Thanks very much!

  2. #2
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    So here's what I'm thinking:

    You're going to create some page with a form on it, where the manager selects the month and year. This will then submit to some other page. This page can be written in any language: you might use PHP, an MVC framework (if you're already using one), or anything that you can do scripting with.

    Anyway, in this new page, you read the month and year parameters (and be sure to do safety-checking on them!), and then invoke the Python script from this page. Once that runs, you can return the page.

    Does that make sense?
    DISTRO=Arch
    Registered Linux User #388732

  3. #3
    Just Joined!
    Join Date
    Mar 2008
    Posts
    2
    Thank you for the info, Cabhan. So, as far as framework, do you have any thoughts on Symfony? If I understand correctly, it has a fairly easy learning curve, especially if one has already been working in PHP. But with all of the options available out there, I guess I'm just looking for some advice on best practices for something like this, and just as importantly, if there are worst practices- things to avoid!

    I really appreciate your input, thank you again.

  4. #4
    Trusted Penguin Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,230
    Well, are you creating a whole new site, or are you adding a page to an existing site? Frameworks are most effective when they manage everything: if you're not going to have the whole site managed by the framework, you may be better off just writing the page.

    For the record, I should say that the only framework I've used personally is a Perl one, and that was for a Web 2.0-y site that had already been set up before I was there. So that was cool. And frameworks can be very useful.

    Maybe someone else here has more thoughts on setting up and selecting a framework of some sort. But the cool thing is that best practices are best practices in any environment: frameworks just help you to do them and help keep things nicely organized. You'll pick a lot of this up as you go along.

    But whether you use a framework or not, you can start thinking about how you would go about programming something like this.
    DISTRO=Arch
    Registered Linux User #388732

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...