PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old March 11th, 2013, 11:15 PM
rbdeforest rbdeforest is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 5 rbdeforest User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 18 sec
Reputation Power: 0
Sending values to python then back via php?

Hi everyone,

So what I'm trying to do is for a visitor to input a value (in this case a page number for a rss feed) and then that is put into a website url. The url is then sent to a python program that gathers all the titles of articles on that page and sends them back to the php in order to be displayed for the visitor to see. I've tried reading up various ways to do this ($argv, etc.) but I just can't seem to come up with how to go about it.

Here is the codes i got thus far and am currently stuck at...

Python:
Code:
from urllib import urlopen 
import re 
webpage=urlopen('http://feeds.huffingtonpost.com/huffingtonpost/LatestNews').read() 
patFinderTitle = re.compile('<title>(.*)</title>') 
titles = patFinderTitle.findall(webpage) 
for (i,title,) in enumerate(titles): 
print('title %2d: %s' %(i,title,))


PHP/HTML:
Code:
<? $pagenumber = $_POST["pagenumber"]; ?> 

<body> 
<form method="post" action="pythontest.php"> 
Page Number:<input type="text" name="pagenumber"><br /> <input type="submit" value="submit" name="submit"> <br /> </form> 
</body> 


Can someone please help and direct me at how to go about this? I'm completely stuck. Thanks in advance!

Reply With Quote
  #2  
Old March 11th, 2013, 11:38 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,944 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 10 h 16 m 54 sec
Reputation Power: 7053
This is something you'll do from your pythontest.php file. How are you invoking the Python code?
__________________
PHP FAQ
How to program a basic, secure login system using PHP
Connect with me on LinkedIn


Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
  #3  
Old March 11th, 2013, 11:42 PM
rbdeforest rbdeforest is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 5 rbdeforest User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 18 sec
Reputation Power: 0
I'm not at the moment. I tried using commands such as argv, but i could not get it to work at all.

Reply With Quote
  #4  
Old March 11th, 2013, 11:56 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,944 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 10 h 16 m 54 sec
Reputation Power: 7053
$argv is only for input to the PHP script; it can only be passed to the PHP script from the program that is invoking PHP.

If you use the passthru() function to execute your Python command, the output will automatically be sent straight to the browser.

You could also use exec() and pass it a second parameter. The second parameter will be an array containing the output (it is passed by reference).

If you need bi-direction communication, you can use proc_open to open a pipe between the two programs; however, this is complicated, requires modifications to your Python code and sounds like more than you need for this particular application.

Reply With Quote
  #5  
Old March 12th, 2013, 01:20 AM
rbdeforest rbdeforest is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2013
Posts: 5 rbdeforest User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 18 sec
Reputation Power: 0
I think a bi-direction will be needed though, since it needs to be called back to php and then stylized. right? or am i totally missing the point?

Reply With Quote
  #6  
Old March 12th, 2013, 06:51 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,944 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 10 h 16 m 54 sec
Reputation Power: 7053
Bi-directional may not have been the best description. proc_open will allow both the PHP script and the Python script to run at the same time and allow them to pass multiple messages back and fourth as they are running.

passthru and exec will pause the PHP script while the Python script executes, and only continue running the PHP script after the Python script exits. The PHP script will only be able to send data to the Python script at one point, before the Python script starts, and it will only be able to receive data from the Python script once, after the Python script finishes.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Sending values to python then back via php?

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap