from grab import Grab
import re
RE_PROXY_LINE = re.compile(r'^(?:\d{1,3}\.){3}\d{1,3}:\d{1,4}$')
def main(**kwargs):
g = Grab()
g.go('http://account.fineproxy.org/')
g.set_input('log', '***')
g.set_input('pass', '****')
g.submit()
if not g.doc.select('//a[@href="/profile/logout/"]').exists():
raise Exception('Unexpected response')
post = {
'templ': '{ip}:{port}',
'type': 'httpip',
'format': 'text',
}
g.go('http://account.fineproxy.org/proxy/', post=post)
rows = g.response.body.splitlines()
if RE_PROXY_LINE.match(rows[0]) and RE_PROXY_LINE.match(rows[1]):
g.response.save('/web/proxy.txt')
else:
raise Exception('Unexpected response')