Debian Codegraph @

examples/pypi.py

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 #!/usr/bin/env python3
2
3 # Search PyPI, the Python Package Index, and retrieve latest mechanize tarball.
4
5 # This is just to demonstrate mechanize: You should use easy_install to do
6 # this, not this silly script.
7
8 import sys
9 import os
10
11 import mechanize
12 from mechanize.polyglot import urlsplit
13
14
15 def download_mechanize():
16 browser = mechanize.Browser(factory=mechanize.RobustFactory())
17 browser.set_handle_robots(False)
18
19 browser.open("http://pypi.python.org/pypi")
20 browser.select_form(name="searchform")
21 browser.form["term"] = "mechanize"
22 browser.submit()
23 browser.follow_link(text_regex="mechanize-?(.*)")
24 link = browser.find_link(text_regex=r"\.tar\.gz")
25 filename = os.path.basename(urlsplit(link.url)[2])
26 if os.path.exists(filename):
27 sys.exit("%s already exists, not grabbing" % filename)
28 browser.retrieve(link.url, filename)
29
30
31 if __name__ == "__main__":
32 download_mechanize()