Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for automating the login process via lynx's cmd script. #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions src/gggd.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@
PROFILE = 0

class LynxFetcher(object):
def __init__(self, lynx_cfg=None, lynx_cookie_file=None):
def __init__(self, lynx_cfg=None, lynx_cookie_file=None, cmd_log=None, cmd_script=None):
self.lynx_cfg = lynx_cfg
self.lynx_cookie_file = lynx_cookie_file
self.cmd_log = cmd_log
self.cmd_script = cmd_script

def default_params(self):
args = []
Expand All @@ -54,6 +56,12 @@ def default_params(self):
"-cookie_save_file=%s" % self.lynx_cookie_file,
"-cookies+"
])
if self.cmd_log:
args.append( "-cmd_log=" + self.cmd_log )

if self.cmd_script:
args.append( "-cmd_script=" + self.cmd_script )

return args

def fetch(self, url, list_only=False, source=False, header=False, stderr=False):
Expand Down Expand Up @@ -321,11 +329,13 @@ def fetch_update(self, update_count, replace_information=False):

self.fetch_content()

def login(self):
print """Please log in to your Google groups account (navigate the form fields with up
and down arrows, submit form with Enter) and then exit the browser (using the 'q' key).
Press Enter to continue."""
sys.stdin.readline()
def login(self, automated=None):
if not automated:
print """Please log in to your Google groups account (navigate the form fields with up
and down arrows, submit form with Enter) and then exit the browser (using the 'q' key).
Press Enter to continue."""
sys.stdin.readline()

self.fetcher.interactive( "https://www.google.com/a/UniversalLogin?continue=https://groups.google.com%s/forum/&service=groups2&hd=default" % self.org_path)


Expand Down Expand Up @@ -381,6 +391,8 @@ def main(argv=None): # IGNORE:C0111
parser.add_argument("-U", "--update-count", help="Number of messages to request in RSS for --update mode, default: 50", default=None, type=int)
parser.add_argument("-d", "--demangle", action="store_true", help="Demangle message contents before writing")
parser.add_argument("-o", "--organization", help="Use only if the Google Group is nested under an organization, eg 'w3c.org'")
parser.add_argument("-x", "--cmd-log", help="log keystroke commands to the given file")
parser.add_argument("-y", "--cmd-script", help="read keystroke commands from the given file")
parser.add_argument(dest="group", help="Name of the Google Group to fetch", metavar="group")

# Process arguments
Expand All @@ -401,6 +413,8 @@ def main(argv=None): # IGNORE:C0111
organization = args.organization
verbose = args.verbose
batch_mode = args.batch_mode
cmd_log = args.cmd_log
cmd_script = args.cmd_script

lynx_cfg = args.lynx_cfg
lynx_cookie_file = args.lynx_cookie_file
Expand All @@ -414,7 +428,7 @@ def main(argv=None): # IGNORE:C0111
if verbose: print "%s: does not exist, not using LYNX_CFG" % lynx_cfg
lynx_cfg = None

fetcher = LynxFetcher(lynx_cfg, lynx_cookie_file)
fetcher = LynxFetcher(lynx_cfg, lynx_cookie_file, cmd_log, cmd_script)

if not fetcher.has_cookies():
if args.login:
Expand All @@ -428,7 +442,7 @@ def main(argv=None): # IGNORE:C0111
group_information = GroupInformation(fetcher, group, organization)

if args.login:
group_information.login()
group_information.login( bool(cmd_script) )

if args.login_only:
return 0
Expand Down