def get(self, url): if self.debug: print('-> GET ' + url) try: return self.opener.open(url).read() except urllib2.HTTPError, e: if self.debug_view_in_browser: helpers.view_in_browser(e.read()) raise
def post(self, url, params): encoded = urllib.urlencode(params) if self.debug: print('-> POST ' + url + ' data:' + encoded) try: return self.opener.open(url, encoded).read() except urllib2.HTTPError, e: if self.debug_view_in_browser: helpers.view_in_browser(e.read()) raise
def request(self, service, rtype, **kw): params = urllib.urlencode(kw) url = self.services_url + service + '/' try: if rtype == 'POST': data = self.opener.open(url, params).read() else: data = self.opener.open(url + '?' + params).read() except urllib2.HTTPError, e: view_in_browser(e.read()) raise
def get_current_usage(self): opener = helpers.get_opener() # Home page # Loading this page because we need a "SMAGENTNAME" variable which # looks to be a cookie that is in the URI. html = self.get(self.url) match = Optus.re_homepage.search(html) smagentname = match.group(1) # Login url = self.url + 'signon/Optus/login_ext.sec' args = { 'USER': self.username, 'PASSWORD': self.password, 'SMENC': 'ISO-8859-1', 'SMLOCALE': 'US-EN', 'target': 'HTTPS://my.optus.com.au/web/oscportal.portal?site=personal', 'smauthreason': '0', 'smagentname': smagentname, 'postpreservationdata': '', } html = self.post(url, args) if html.find('Please verify your User Name') != -1: raise InvalidCredentialsException() # Fetch usage page url = self.url + 'web/oscportal.portal?_nfpb=true&' + \ '_pageLabel=deeplink_myusage_postpaid&site=personal&' + \ 'pageName=unbilledUsage&virAcctNum=' + self.phone_number html = self.get(url) match = Optus.re_usage.search(html) usage = match.group(1) helpers.view_in_browser(html) # Parse the usage page return { GENERAL: usage, }