I have installed twill on my computer (having previously installed Python 2.5) and have been using it recently.
Python is installed on disk C on my computer: C:\Python25
And the twill folder (“twill-0.9”) is located here: E:\tmp\twill-0.9
Here is a code that I’ve been using in twill:
go “some website’s sign-in page URL”
formvalue 2 userid “my login”
formvalue 2 pass “my password”
submit
go “URL of some other page from that website”
save_html result.txt
This code helps me to log in to one website, in which I have an account, record the HTML code of some other page of that website (that I can access only after logging in), and store it in a file named “result.txt” (of course, before using this code I firstly need to replace “my login” with my real login, “my password” with my real password, “some website’s sign-in page URL” and “URL of some other page from that website” with real URLs of that website, and number 2 with the number of the form on that website that is used as a sign-in form on that website’s log-in page)
This code I store in “test.twill” file that is located in my “twill-0.9” folder: E:\tmp\twill-0.9\test.twill I run this file from my command prompt: python twill-sh test.twill
Now, I also have installed “Google App Engine SDK” from “Google App Engine” and have also been using it for awhile.
For example, I’ve been using this code:
import hashlib
m = hashlib.md5()
m.update("Nobody inspects")
m.update(" the spammish repetition ")
print m.hexdigest()
This code helps me transform the phrase “Nobody inspects the spammish repetition” into md5 digest.
Now, how can I put these two pieces of code together into one python script that I could run on “Google App Engine”?
Let’s say, I want my code to log in to a website from “Google App Engine”, go to another page on that website, record its HTML code (that’s what my twill code does) and than transform this HTML code into its md5 digest (that’s what my second code does). So, how can I combine those two codes into one python code?
I guess, it should be done somehow by importing twill, but how can it be done? Can a python code - the one that is being run by “Google App Engine” - import twill from somewhere on the internet? Or, perhaps, twill is already installed on “Google App Engine”?
Update 1:
(this update is my response to Wooble’s answer)
Here is the list of all folders (in my “twill-0.9” folder) that contain __init
__.py files. (some folders on this list are located inside of other folders, which are also mentioned in this list) :
E:\twill-0.9\build\lib\twill\extensions\match_parse
E:\twill-0.9\build\lib\twill\extensions
E:\twill-0.9\build\lib\twill\other_packages\_mechanize_dist
E:\twill-0.9\build\lib\twill\other_packages
E:\twill-0.9\build\lib\twill
E:\twill-0.9\twill\extensions\match_parse
E:\twill-0.9\twill\extensions
E:\twill-0.9\twill\other_packages\_mechanize_dist
E:\twill-0.9\twill\other_packages
E:\twill-0.9\twill
To use third-party libraries in App Engine projects, you simply have to include them with your application when you deploy. Copy the twill folder (the one containing
__init__.py
) into your application's folder and deploy it.Looking at the twill Google Code project, it appears that twill includes its dependencies (pyparsing, mechanize, etc.) in the package, so you may not need to include anything else.
here is an example of using twill to run a google search if this helps. It shows using twill and beautifulsoup together to parse web pages:
I believe you're looking for a way to import the twill module into App-Engine. You'll have to figure out either where the twill python files are or how to get a source package of them to package it with your website, but it looks like importing 3rd party modules can be done with a few exceptions, see below.
Try ZipImport following the directions from Google's site here and here.
from Google's third Party Library page:
No idea what twill does (well, googled), but AppEngine offers
fetch()
function which can be used to fetch web pages. It also supports POST method e.g. for logins.(I doubt twill works in AppEngine, because AppEngine has limited python libraries available for security reasons. Just a guess, though.)