Esempio n. 1
0
def main():

    login, password = get_credentials()

    # log-in to Django site
    if login and password:
        tw.go(LOGIN_URL)
        tw.formvalue('1', 'username', login)
        tw.formvalue('1', 'password', password)
        tw.submit()

    if isinstance(DATA_URL, basestring):
        urls = [DATA_URL]
    else:
        urls = list(DATA_URL)

    # retrieve URIs
    for url in urls:
        try:
            tw.go(url)
            tw.code('200')
            tw.show()
        except TwillAssertionError:
            code = get_browser().get_code()           
            print (u"Unable to access %(url)s. "
                   u"Received HTTP #%(code)s."
                   % {'url': url, 'code': code})
    tw.reset_browser()
Esempio n. 2
0
    def setup(
        self,
        login=None,
        password=None,
        service_url="https://bramka.play.pl",
        login_url="https://logowanie.play.pl/p4-idp2/LoginForm.do",
        logout_url="https://logowanie.play.pl/p4-idp2/LogoutUser",
    ):
        self.SERVICE_URL = service_url
        self.LOGIN_URL = login_url
        self.LOGOUT_URL = logout_url
        self.MY_PHONE_NUMBER = login
        self.MY_PASSWORD = password

        web.config("readonly_controls_writeable", True)
        web.agent(self.MY_HTTP_AGENT)

        web.go(self.SERVICE_URL)
        web.submit()
        web.code(200)
        web.formvalue("loginForm", "login", self.MY_PHONE_NUMBER)
        web.formvalue("loginForm", "password", self.MY_PASSWORD)
        web.submit()
        web.code(200)
        self._retry_find("editableSmsComposeForm", 5)
def main():
    joker = SpawnKillerThread()
    try:
        SpawnDistributedCluster()
        print "Waiting for two JBoss instances to start up in cluster mode..."
        time.sleep(10)
        joker.start()
        #commands.debug('http', 1)
        #commands.debug('commands',1)
        b = get_browser()
        import socket
        myip = "http://" + socket.gethostbyname(socket.gethostname())
        b.go(myip + "/session-basket")
        b.submit(5)
        wordBatch = listOfRandomWords()
        for idx, w in enumerate(wordBatch):
            print "Adding word %d: '%s' to the list..." % (idx, w)
            commands.formvalue("1", "newItem:j_idt11", w)
            b.submit(4)
            commands.code(200)
            commands.find(w)
            time.sleep(0.25)
        print wordBatch, len(wordBatch)
        b.submit(5)
        commands.code(200)
        commands.reload()
        for w in wordBatch:
            commands.find(w)
    finally:
        joker.stopKilling = True
        joker.join()
        KillJBoss(0)
        KillJBoss(1)
	def __init__ (self, email, password):
		Browser.go(PANDORA_LOGIN_URL)
		Browser.formvalue(1, 'login_username', email)
		Browser.formvalue(1, 'login_password', password)
		Browser.submit()

		self.webname = Browser.info().split('/').pop()
Esempio n. 5
0
 def send(self, msg, *send_to):
     for contact in send_to:
         web.follow(self.SERVICE_URL)
         web.follow("newsms")
         web.formvalue("sendSMS", "smsBody", msg)
         to = getattr(contact, "mobile", contact)
         web.formvalue("sendSMS", "smsTo", to)
         web.submit()
         web.code(200)
         web.find("newsms")
Esempio n. 6
0
def test_profile_record():
    """
    Test availability of user profile
    """
    go(SITE + '/accounts/login/')
    code(200)
    show()
    formvalue(1, 'username', 'root')
    formvalue(1, 'password', '1')
    submit()
    code(200)
Esempio n. 7
0
def test_reset_password():
    """
    Test user password reset
    """
    go(SITE + '/accounts/password/reset/')
    code(200)
    show()
    formvalue(1, 'email', '*****@*****.**')
    submit()
    code(200)
    find('Password reset successful')
    return
Esempio n. 8
0
def test_incorrect_username():
    """
    Test an incorrect log in to site with invalid username
    """
    go(SITE + '/accounts/login/')
    code(200)
    show()
    formvalue(1, 'username', 'testincorrect')
    formvalue(1, 'password', '1')
    submit()
    code(200)
    find('Please enter a correct username and password.')
    return
Esempio n. 9
0
def test_success_login():
    """
    Test a success log in to site
    """
    go(SITE + '/accounts/login/')
    code(200)
    show()
    formvalue(1, 'username', 'test')
    formvalue(1, 'password', '1')
    submit()
    code(200)
    find('<h4 align="center">My profile</h4>')
    return
Esempio n. 10
0
    def send(self, msg, *send_to):
        web.go(self.SERVICE_URL)
        self._retry_find("editableSmsComposeForm", 5)

        try:
            page = web.get_browser().get_html()
            web.notfind("inputCaptcha")
        except twill.errors.TwillAssertionError, e:
            found = re.search("(/composer/public/jcaptcha\?id=.*)", page)
            assert found
            web.go(found.groups()[0])
            with tempfile.NamedTemporaryFile(suffix=".jpeg") as captcha:
                web.save_html(captcha.name)
                web.back()
                os.system("open %s " % captcha.name)
                web.formvalue("editableSmsComposeForm", "inputCaptcha", raw_input("Captcha: "))
Esempio n. 11
0
 def set_form_value( self, form, kwd, field_name, field_value ):
     '''
     Set the form field field_name to field_value if it exists, and return the provided dict containing that value. If
     the field does not exist in the provided form, return a dict without that index.
     '''
     form_id = form.attrs.get( 'id' )
     controls = [ control for control in form.controls if str( control.name ) == field_name ]
     if len( controls ) > 0:
         log.debug( 'Setting field %s of form %s to %s.' % ( field_name, form_id, str( field_value ) ) )
         tc.formvalue( form_id, field_name, str( field_value ) )
         kwd[ field_name ] = str( field_value )
     else:
         if field_name in kwd:
             log.debug( 'No field %s in form %s, discarding from return value.' % ( str( control ), str( form_id ) ) )
             del( kwd[ field_name ] )
     return kwd
Esempio n. 12
0
def download_with_login(url, login_url, login=None,
                              password=None, ext='',
                              username_field='username',
                              password_field='password',
                              form_id=1):
    ''' Download a URI from a website using Django by loging-in first

        1. Logs in using supplied login & password (if provided)
        2. Create a temp file on disk using extension if provided
        3. Write content of URI into file '''

    # log-in to Django site
    if login and password:
        tw.go(login_url)
        tw.formvalue('%s' % form_id, username_field, login)
        tw.formvalue('%s' % form_id, password_field, password)
        tw.submit()

    # retrieve URI
    try:
        tw.go(url)
        tw.code('200')
    except TwillAssertionError:
        code = get_browser().get_code()
        # ensure we don't keep credentials
        tw.reset_browser()
        raise DownloadFailed(u"Unable to download %(url)s. "
                             u"Received HTTP #%(code)s."
                             % {'url': url, 'code': code})
    buff = StringIO.StringIO()
    twill.set_output(buff)
    try:
        tw.show()
    finally:
        twill.set_output(None)
        tw.reset_browser()

    # write file on disk
    suffix = '.%s' % ext if ext else ''
    fileh, filename = tempfile.mkstemp(suffix=suffix)
    os.write(fileh, buff.getvalue())
    os.close(fileh)
    buff.close()

    return filename
Esempio n. 13
0
def _getCalendar(config, top, ymd):
    b = twill.get_browser()
    b.set_agent_string("Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7) Gecko/20040616")

    val = lambda p: config.value(top, p)

    server = val(EM['server']).rstrip('/')
    returnParams = urllib.urlencode(dict(ae="Folder", t="IPF.Appointment",
                                         yr=ymd[0], mn=ymd[1], dy=ymd[2]))
    returnUrl = "%s/owa/?%s" % (server, returnParams)
    b.go("%s/owa/auth/logon.aspx?%s" % (server,
                                        urllib.urlencode(dict(url=returnUrl))))
    
    C.formvalue(1, "username", val(EM['user']))
    C.formvalue(1, "password", val(EM['password']))
    C.submit(8)

    return b.get_html()
Esempio n. 14
0
File: ygd.py Progetto: tuxdna/ygd
def start(args):
    parser = OptionParser(version=VERSION)
    parser.add_option("-p", "--password", help="account password")
    parser.add_option("-u", "--username", help="account user name")
    parser.add_option("-g", "--groupname", help="group name")

    (options, args) = parser.parse_args(args)
    password = options.password
    username = options.username
    yahoo_group = options.groupname
    if not (username and yahoo_group):
        parser.print_help()
        sys.exit(1)

    if not password:
        password = getpass.getpass()

    if not password:
        parser.print_help()
        sys.exit(1)

    yg_url = "%s/%s/"%(YG_BASE_URL, yahoo_group)

    tc.go(yg_url)
    tc.follow("Sign In")
    tc.formvalue(1, 'login', username)
    tc.formvalue(1, 'passwd', password)
    tc.submit()
    tc.follow("Messages")

    b = tc.get_browser()
    browser_title =  b.get_title()
    m = re.search(r'Messages : (\d+)-(\d+) of (\d+)', browser_title)

    if not m:
        print "regular expression failed"
        sys.exit(1)

    start, end, total_messages = m.groups()

    for i in range(int(total_messages)):
        message_id = i + 1
        message_path = '%s/%s'%(yahoo_group, message_id)
        download_message(message_id, message_path, yahoo_group)
Esempio n. 15
0
    def login(self, user, password):
        def loggedin():
            """
            Check the browser's cookie jar for a cookie with a name ending in
            "bugzilla".  If it isn't expired, we're probably logged in.
            """
            for cookie in self.browser.cj:
                if cookie.name.endswith('bugzilla') and not cookie.is_expired():
                    return True
            return False

        if loggedin():
            return

        commands.go('https://bugzilla.novell.com/ICSLogin/?"https://bugzilla.novell.com/ichainlogin.cgi?target=index.cgi?GoAheadAndLogIn%3D1"')
        commands.formvalue('loginfrm', 'username', user)
        commands.formvalue('loginfrm', 'password', password)
        commands.submit('0')
        assert loggedin()
Esempio n. 16
0
    def setup(
        self,
        login=None,
        password=None,
        service_url="/portal/map/map/message_box",
        login_url="http://www.orange.pl/zaloguj.phtml",
    ):

        self.SERVICE_URL = service_url
        self.LOGIN_URL = login_url
        self.MY_PHONE_NUMBER = login
        self.MY_PASSWORD = password

        web.agent(self.MY_HTTP_AGENT)
        web.go(self.LOGIN_URL)
        web.code(200)
        web.formvalue("loginForm", "login", self.MY_PHONE_NUMBER)
        web.formvalue("loginForm", "password", self.MY_PASSWORD)
        web.submit()
        web.code(200)
        web.find(self.SERVICE_URL)
Esempio n. 17
0
    def send(self, msg, *send_to):
        """
        @todo: make use of native vodafone multi-recipients functionality
        """
        for contact in send_to:
            web.follow(self.SERVICE_URL)

            try:
                web.find("/myv/messaging/webtext/Challenge.shtml")
            except twill.errors.TwillAssertionError, e:
                pass
            else:
                web.go("/myv/messaging/webtext/Challenge.shtml")
                with tempfile.NamedTemporaryFile(suffix=".jpeg") as captcha:
                    web.save_html(captcha.name)
                    web.back()
                    os.system("open %s " % captcha.name)
                    web.formvalue("WebText", "jcaptcha_response", raw_input("Captcha: "))

            web.formvalue("WebText", "message", msg)
            to = getattr(contact, "mobile", contact)
            web.formvalue("WebText", "recipient_0", to)

            web.sleep(2)
            web.submit()
            web.code(200)
            web.find("Message sent!")
Esempio n. 18
0
def test_register():
    """
    Test user registration
    """
    go(SITE + '/accounts/register/')
    code(200)
    show()
    formvalue(1, 'username', 'demouser')
    formvalue(1, 'email', '*****@*****.**')
    formvalue(1, 'password1', '1')
    formvalue(1, 'password2', '1')
    submit()
    code(200)
    find('Confirmation e-mail sent')
    return
Esempio n. 19
0
    def setup(
        self,
        login=None,
        password=None,
        service_url="/myv/messaging/webtext/",
        login_url="https://www.vodafone.ie/myv/services/login/index.jsp",
        logout_url="/myv/services/logout/Logout.shtml",
    ):

        self.SERVICE_URL = service_url
        self.LOGIN_URL = login_url
        self.LOGOUT_URL = logout_url
        self.MY_PHONE_NUMBER = login
        self.MY_PASSWORD = password

        web.agent(self.MY_HTTP_AGENT)
        web.go(self.LOGIN_URL)
        web.code(200)
        web.formvalue("Login", "username", self.MY_PHONE_NUMBER)
        web.formvalue("Login", "password", self.MY_PASSWORD)
        web.submit()
        web.code(200)
        web.find(self.SERVICE_URL)
Esempio n. 20
0
def submit_login_form (config, url, tc):
    """Fill and submit login form."""
    user, password = config.get_user_password(url)
    cgiuser = config["loginuserfield"]
    cgipassword = config["loginpasswordfield"]
    formname = search_formname((cgiuser, cgipassword), tc)
    tc.formvalue(formname, cgiuser, user)
    tc.formvalue(formname, cgipassword, password)
    for key, value in config["loginextrafields"].items():
        tc.formvalue(formname, key, value)
    tc.submit()
Esempio n. 21
0
IMAGE = re.compile('e:: ([-+\w\.]+)') # figure/image

def replace_image_links(txt):
    "Remove code-block directives and relative images to make Artima happy"
    txt = re.sub(r'.. code-block:: \w+', '::', txt)
    return IMAGE.sub(r'e:: http://www.phyast.pitt.edu/~micheles/scheme/\1', txt)

if __name__ == '__main__':
    try:
        rstfile, thread  = sys.argv[1:]
    except ValueError:
        sys.exit('Usage: post <rstfile> <artima-thread-number>')
    text = replace_image_links(file(rstfile).read())
    c.go('http://www.artima.com/sign_in?d=%2Findex.jsp')
    c.formvalue('1', 'username', 'micheles')
    c.formvalue('1', 'password', 'pippolippo')
    c.submit()
    c.go('http://www.artima.com/weblogs/editpost.jsp?thread=%s' % thread)
    try:
        c.formvalue('1', 'body', text)
    except:
        print "Saving the offending post on /tmp/x.txt ..."
        file('/tmp/x.txt', 'w').write(text)
        raise
    c.submit()

"""
from ms.http_utils import urlopen2
urlopen2('http://www.artima.com/sign_in?d=%2Findex.jsp', 
  dict(username='******', password='******'))
Esempio n. 22
0
def test_change_password():
    """
    Test user password change
    """
    go(SITE + '/accounts/login/')
    code(200)
    show()
    formvalue(1, 'username', 'test')
    formvalue(1, 'password', '1')
    submit()
    code(200)
    go(SITE + '/accounts/password/change/')
    code(200)
    show()
    formvalue(1, 'old_password', '1')
    formvalue(1, 'new_password1', '2')
    formvalue(1, 'new_password2', '2')
    submit()
    code(200)
    find('Password change successful')
    go(SITE + '/accounts/login/')
    code(200)
    show()
    formvalue(1, 'username', 'test')
    formvalue(1, 'password', '2')
    submit()
    code(200)
    return
Esempio n. 23
0
def pobierzPlan(user, password):
    tablicaHTMLow = []
    commands.add_extra_header('User-agent', 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.6')
    commands.clear_cookies()        # Czyszczenie ciastek
    commands.reset_browser()        #restart przegladarki
    commands.reset_output()
    #commands.config('use_BeautifulSoup', '0')
    commands.go("https://edukacja.pwr.wroc.pl/EdukacjaWeb/studia.do")   # Przechodzimy do edukacji
    
    commands.showlinks()            # DO USUNIECIA! Pokazuje linki

    commands.formclear('1')                                 # Czysci formularz logowania
    commands.formvalue('1', 'login', user)                  # Podaje login
    commands.formvalue('1', 'password', password)           # Podaje hasło
    commands.submit('0')                                    # Klika zaloguj
    
    print("Linki po submit")                                # DO USUNIECIA! Pokazuje informacje
    commands.showlinks()                                    # DO USUNIECIA! Pokazuje linki
    
    czyBledneLogowanie = sprawdzCzyBledneLogowanie(commands.show())                  # Sprawdza czy na stronie wystapil blad
    czyLogowanieWInnejSesji = sprawdzCzyLogowanieWInnejSesji(commands.show())
    if (czyBledneLogowanie == True):
        return "Bledne dane logowania"
    if (czyLogowanieWInnejSesji == True):
        return "zalogowany w innej sesji"
    commands.follow("zapisy.do")                               # Przechodzi linkiem na stronę zapisów
    
    # DO USUNIECIA! Pokazuje stronę po kliknięciu zapisy!
    print("Co po kliknieciu Zapisy")
    #commands.show()
    commands.showlinks()
    print "Forms:"
    formsy = commands.showforms()


    links = commands.showlinks()                            # Pobiera linki z danej strony 
    control = None
    values = None
    select_options = None
    try:
        control = commands.browser.get_form("1").find_control('ineSluId', type="select")
    except:
        print("Nie ma selecta.")
    #control = commands.browser.get_form("1").find_control('ineSluId', type="select")
    
    if(control != None):                                    # Jesli na stronie jest select
        values = pobierzElementySelect(commands.show())     # Pobieram parserem wartosci selecta
        select_options = utworzTabeleSelect(values)         # Tworze nowy select podmieniajac stary
        select_attrs = {'id': 'some_id'}                    # Tworze atrybuty nowego selecta
        for v in values:                                    # Lece petla po wartosciach selecta
            form = commands.get_browser().get_form("1")                                     # Pobieram formularz
            ct = commands.browser.get_form("1").find_control('ineSluId', type="select")     # Pobieram kontrolke z selectem
            add_select_to_form(form, 'ineSluId', select_attrs, select_options)              # Tworze nowego selecta
            form.fixup()                                                                    # Sprawdzam czy cos nowego nie zostało dodanego do form
            commands.showforms()
            
            commands.formvalue("1", ct.name, v.strip())                                     # Podaje wartosc dla selecta
            commands.submit('0')                                                            # Klikam submit
            html = pobierzZajecia(commands)                                                 # Pobieram zajecia
            commands.follow("zapisy.do")                                                    # Wracam do strony zapisów
            
            #commands.sleep(6)
            if (html != "skreslony z kierunku"):            # Jesli funkcja zwrocila ze jest ktos skreslony to nie dodaje htmlu
                tablicaHTMLow.append(html)                  # Jeli nie zwrocila takiego komunikatu to dodajemy ten html do tablicy
    else:
        html = pobierzZajecia(commands)                     # Jesli nie ma selecta to pobieramy zajeci z tego kierunku i juz :D
        if (html != "skreslony z kierunku"):
            tablicaHTMLow.append(html)
            
    #print control.name, control.value, control.type
    #item = control.get("172748")
    #print item.name, item.selected, item.id, item.attrs
    
    #new_options
    #commands.formclear('1')
    #
    #
    #form = commands.get_browser().get_form("1")
    #
    #print('TO JEST TEN FORM:')
    #print(form)
    #print(len(form.controls))
    #
    #notIsSelect = True
    
    #for ct in form.controls:
    #    #print(ct)
    #    if ct.name == 'ineSluId':
    #        notIsSelect = False
    #        print('JESTEM')
    #        commands.sleep(3)
    #        
    #        select_attrs = {'id': 'some_id'}
    #        values = pobierzElementySelect(commands.show())
    #        select_options = utworzTabeleSelect(values)
    #        print(values)
    #        print(select_options)
    #        
    #        
    #        for v in values:
    #            #form.fixup()
    #            add_select_to_form(form, 'ineSluId', select_attrs, select_options)
    #            form.fixup()
    #            #ct.get(v).selected = True
    #            print(ct)
    #            print(form)
    #            print(v)
    #            commands.showforms()
    #            
    #            commands.formvalue("1", ct.name, v.strip())            # Podaje login
    #            print("JEEDEFE")
    #            commands.submit('0')
    #            html = pobierzZajecia(commands)
    #            commands.follow("zapisy.do")
    #            print("JEEEEEEEEESSSSSTTTTTEEEEEMMM")
    #            
    #            commands.sleep(6)
    #            if (html != "skreslony z kierunku"):
    #                tablicaHTMLow.append(html)
                #ct.get(v).selected = False
                
                
                
                
            
            #for ct2 in form.controls:
            #    if ct2.type == 'submit':                                             # szukam wsrod niej tej co ma typ submit
            #        commands.get_browser().clicked(form, ct2.attrs['name'])      # klikam na ten przycisk
            #        commands.get_browser().submit()
            
            #links = commands.showlinks()
            #commands.back()
            #commands.showforms()
            

            #return "no"

    #if (notIsSelect == True):
    #    html = pobierzZajecia(commands)
    #    if (html != "skreslony z kierunku"):
    #        tablicaHTMLow.append(html)

    wyloguj(commands)
    commands.browser.clear_cookies()        #usuwanie ciasteczek
    commands.reset_browser()        #restart przegladarki
    commands.reset_output()

    return tablicaHTMLow
Esempio n. 24
0
 def runTest(self):
     """
     The twill test case is useful for emulating a user using HTML forms and clicking on buttons.
     Note we cannot connect to the twill server using urllib2 or any other third party client.
     Also, we cannot verify the header content in a twill response.
     """
     FILTER_FORM = 2
     
     logger = logging.getLogger("TwillTestCase")
     url = URL_BASE
     twill_quiet()
     logger.info('accessing ' + url)
     tc.go(url)
     tc.find("html") # sanity check that this is a html request.
     
     url = URL_BASE + 'filter/'
     logger.info('accessing ' + url)
     tc.go(url)
     tc.formvalue(FILTER_FORM,'tag','esnet')
     tc.submit(9) #simulates a click on the "create filter" button
     tc.find("html")
     tc.find('<table class="sortable">') #a line in event.list.html
     tc.notfind('experiment') #should be filtered out
     
     tc.go(url)
     tc.formvalue(FILTER_FORM,'display','timeline')
     tc.submit(9) #click should direct us to timeline.
     tc.find("html")
     tc.notfind('<table class="sortable">') 
     
     tc.go(url)
     tc.formvalue(FILTER_FORM,'display','json')
     tc.submit(9) #click should give us JSON object.
     tc.find('"pk": 1') #part of JSON string.
     tc.notfind("html")
     
     tc.go(url)
     tc.formvalue(FILTER_FORM,'name','upgrade')
     tc.formvalue(FILTER_FORM,'search','www.es.net')
     tc.formvalue(FILTER_FORM,'description','infrastructure')
     tc.submit(9)
     tc.find('html')
     tc.find('www.es.net') #part of the upgrade event.
     
     #Set headers to contain only the json mime
     tc.clear_extra_headers()
     tc.add_extra_header('Accept',JSON_MIME)
     
     url = URL_BASE
     logger.info('accessing ' + url)
     tc.go(url)
     logger.debug('JSON data:' + tc.show())
     tc.notfind("html") 
     tc.find('"name": "experiment"') #data from the fixture formatted by default serializer
     tc.find('"tags": "esnet"')
     
     url = URL_BASE + '1/'
     logger.info('accessing ' + url)
     tc.go(url)
     tc.notfind("html")
     tc.find('"name": "experiment"') 
     tc.notfind('"tags": "esnet"') 
Esempio n. 25
0
 def login(self, username, password):
     tc.go(self._login)
     tc.formvalue(2, 'username', username)
     tc.formvalue(2, 'password', password)
     tc.submit()
Esempio n. 26
0
def replace_image_links(txt):
    "Remove code-block directives and relative images to make Artima happy"
    txt = re.sub(r'.. code-block:: \w+', '::', txt)
    return IMAGE.sub(r'e:: http://www.phyast.pitt.edu/~micheles/scheme/\1',
                     txt)


if __name__ == '__main__':
    try:
        rstfile, thread = sys.argv[1:]
    except ValueError:
        sys.exit('Usage: post <rstfile> <artima-thread-number>')
    text = replace_image_links(file(rstfile).read())
    c.go('http://www.artima.com/sign_in?d=%2Findex.jsp')
    c.formvalue('1', 'username', 'micheles')
    c.formvalue('1', 'password', 'pippolippo')
    c.submit()
    c.go('http://www.artima.com/weblogs/editpost.jsp?thread=%s' % thread)
    try:
        c.formvalue('1', 'body', text)
    except:
        print "Saving the offending post on /tmp/x.txt ..."
        file('/tmp/x.txt', 'w').write(text)
        raise
    c.submit()
"""
from ms.http_utils import urlopen2
urlopen2('http://www.artima.com/sign_in?d=%2Findex.jsp', 
  dict(username='******', password='******'))
urlopen2('http://www.artima.com/weblogs/editpost.jsp',
Esempio n. 27
0
def vote_story(hn_id):
    """vote for an story"""
    vote = request.POST.get('vote', '').strip()

    # we need a voting direction "up" or "down"
    if vote == '' or (vote != 'up' and vote != 'down'):
        return abort(code=400, text="Invalid voting direction, " +
                                    "needs to be 'up' or 'down'?")

    # check for the http auth
    if not request.auth:
        return abort(code=401, text="We need your username and " +
                                "password for this operation.")

    # i can haz your hn password
    username, password = request.auth

    # we start web scraping
    go(HN_URL)

    # lets find the login url
    login_url = ''
    for link in showlinks():
        if link.text == "login":
            login_url = link.url

    go(login_url)

    # we login #1 is the form (login, #2 is register)
    formvalue('1', 'u', username)
    formvalue('1', 'p', password)

    # 4 is the position of the submit button
    submit('4') 

    # now we go to the story
    go('/item?id=%s' % hn_id)

    # and vote for it
    # find the link
    voting_url = ''
    for link in showlinks():
        if link.url.startswith('vote?for=%s&dir=%s&by=%s' % 
                                (hn_id, vote, username)):
            voting_url = '/' + link.url

    if voting_url == '':
        return abort(code=400, text="Something's wrong at voting, " +
                                    "Could not find the voting url. " +
                                    "Most likely you already voted or " +
                                    "the username or password are wrong.")
    go(voting_url)

    # lets find the login url
    for link in showlinks():
        if link.text == "logout":
            logout_url = link.url

    go(HN_URL)
    go(logout_url)

    # and we're done!
    reset_browser()

    # success! response is always in JSON
    return {'status': "ok", 'message': "voted successfully for %s" % hn_id}
Esempio n. 28
0
 def close(self, error_info=None):
     web.formvalue("logoutForm", "_dyncharset", None)
     web.submit()
     web.code(200)
     web.find("zaloguj")