2 # -*- coding: iso-8859-1 -*-
5 # sfquery -- Source Forge query script using the ClientCGI high-level interface
7 # Retrieves a SourceForge XML export object for a given project.
8 # Specify the *numeric* project ID. the user name, and the password,
9 # as arguments. If you have a valid ~/.netrc entry for sourceforge.net,
10 # you can just give the project ID.
12 # By Eric S. Raymond, August 2002. All rites reversed.
17 assert sys.version[:3] >= "2.2", "requires Python 2.2 or better"
19 class SourceForgeUserSession(curl.Curl):
20 # SourceForge-specific methods. Sensitive to changes in site design.
21 def login(self, name, password):
22 "Establish a login session."
23 self.post("account/login.php", (("form_loginname", name),
24 ("form_pw", password),
27 ("login", "Login With SSL")))
29 "Log out of SourceForge."
30 self.get("account/logout.php")
31 def fetch_xml(self, numid):
32 self.get("export/xml_export.php?group_id=%s" % numid)
34 if __name__ == "__main__":
35 if len(sys.argv) == 1:
36 project_id = '28236' # PyCurl project ID
38 project_id = sys.argv[1]
39 # Try to grab authenticators out of your .netrc
41 auth = netrc.netrc().authenticators("sourceforge.net")
42 name, account, password = auth
45 password = sys.argv[3]
46 session = SourceForgeUserSession("https://sourceforge.net/")
47 session.set_verbosity(0)
48 session.login(name, password)
50 if session.answered("Invalid Password or User Name"):
51 sys.stderr.write("Login/password not accepted (%d bytes)\n" % len(session.body()))
53 # We'll see this if we get the right thing.
54 elif session.answered("Personal Page For: " + name):
55 session.fetch_xml(project_id)
56 sys.stdout.write(session.body())
59 # Or maybe SourceForge has changed its site design so our check strings
60 # are no longer valid.
62 sys.stderr.write("Unexpected page (%d bytes)\n"%len(session.body()))