Пример #1
0
 def _get(url, lock=Lock()):
     attempt = 0
     while True:
         attempt += 1
         try:
             page = REQ.get(url)
             if 'id="id_login"' in page and 'id="id_password"' in page:
                 with lock:
                     if not Statistic.LOGGED_IN:
                         page = REQ.get(Statistic.LOGIN_URL_)
                         page = REQ.submit_form(
                             {
                                 'login': conf.HACKEREARTH_USERNAME,
                                 'password': conf.HACKEREARTH_PASSWORD,
                                 'signin': 'Log In',
                             },
                             limit=0,
                         )
                         Statistic.LOGGED_IN = True
             if 'AJAX' in url:
                 headers = {'x-requested-with': 'XMLHttpRequest'}
                 csrftoken = REQ.get_cookie('csrftoken')
                 if csrftoken:
                     headers['x-csrftoken'] = csrftoken
             else:
                 headers = {}
             return REQ.get(url, headers=headers)
         except FailOnGetResponse as e:
             if attempt == 15 or getattr(e.args[0], 'code', None) != 500:
                 raise ExceptionParseStandings(e.args[0])
             sleep(2 * attempt)
Пример #2
0
 def _get(url):
     attempt = 0
     while True:
         attempt += 1
         try:
             if 'AJAX' in url:
                 headers = {'x-requested-with': 'XMLHttpRequest'}
                 csrftoken = REQ.get_cookie('csrftoken')
                 if csrftoken:
                     headers['x-csrftoken'] = csrftoken
             else:
                 headers = {}
             return REQ.get(url, headers=headers)
         except FailOnGetResponse as e:
             if attempt == 7 or getattr(e.args[0], 'code', None) != 500:
                 raise ExceptionParseStandings(e.args[0])
             sleep(2**attempt)