Змея / Говнокод #26889 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
# TODO: fix this shit
def publish(self, session: requests.Session, auth_cookie: str, max_retries: int, retry_time: float) -> bool:
    for i in range(max_retries):
        L.info(f'PostForm.publish(), loading attempt #{i + 1}')
        if self.load_new(session, auth_cookie):
            break
        time.sleep(retry_time)
    else:  # No break
        L.error('PostForm.publish(): could not load the form')
        return False
    
    for i in range(max_retries):
        L.info(f'PostForm.publish(), posting attempt #{i + 1}')
        if not self.try_recognize_captcha(session):
            time.sleep(retry_time)
            continue  # Load an another captcha with the same csrf/captcha_id
        if self.try_post(session, auth_cookie) == PostForm.Status.POST_DONE:
            return True
        time.sleep(retry_time)
    L.error(f'PostForm.publish() failed, max_retries exceeded')
    return False

Блять, отвратительно.

Запостил: gost gost, (Updated )

Комментарии (4) RSS

  • for offtop in offtops_to_perekat:
        perekat = Perekat.make_perekat(offtop.category, session)
        if perekat.old_offtop is None or perekat.old_offtop.id != offtop.id:
            L.error(f'Perekat.make_perekat() returned invalid old_offtop (perekat for {offtop.post_id})')
            continue
    
        # Publish new offtop
        time.sleep(config.PEREKAT_ACTIONS_PAUSE)
        if not perekat.form.publish(requests_session, auth_cookie, config.POST_MAX_RETRIES, config.POST_RETRY_TIME):
            L.error(f'Could not publish new offtop (perekat for {offtop.post_id})')
            continue
    
        if perekat.form.post_id is None:
            L.error(f'Could not get new offtop\'s post_id (perekat for {offtop.post_id})')
            continue
    
        perekat.new_offtop.post_id = perekat.form.post_id
        perekat.new_offtop.comment_list_id = perekat.form.comments_list_id
        perekat.new_offtop = session.merge(perekat.new_offtop)
        session.commit()  # Save published post_id
    Ответить
    • # Get old offtop's comment_list_id
          if offtop.comment_list_id is None:
              try:
                  info = ngk.get_post_info(offtop.post_id)
              except NGKException:
                  L.exception(f'Could not get comment_list_id for {offtop.post_id}')
              else:
                  offtop.comment_list_id = info.comment_list_id
          
          # Publish perekat comment
          if offtop.comment_list_id is not None:
              perekat_comment_form = perekat.generate_perekat_comment(perekat.form.post_id, offtop.comment_list_id)
              time.sleep(config.PEREKAT_ACTIONS_PAUSE)
              if not perekat_comment_form.publish(requests_session, auth_cookie, config.COMMENT_MAX_RETRIES, config.COMMENT_RETRY_TIME):
                  L.warning(f'Could not publish perekat comment to {offtop.post_id}')
              else:
                  offtop.perekat_comment_id = perekat_comment_form.comment_id
          
          if perekat.form.comments_list_id is None:
              L.error(f'Could not get new offtop\'s comments_list_id (perekat for {offtop.post_id})')
              continue
      
          # Publish welcome comment
          welcome_comment_form = perekat.generate_welcome_comment(perekat.form.comments_list_id)
          time.sleep(config.PEREKAT_ACTIONS_PAUSE)
          if not welcome_comment_form.publish(requests_session, auth_cookie, config.COMMENT_MAX_RETRIES, config.COMMENT_RETRY_TIME):
              L.warning(f'Could not publish welcome comment to {perekat.form.post_id}')
          else:
              perekat.new_offtop.welcome_comment_id = welcome_comment_form.comment_id
      Ответить

Добавить комментарий

Где здесь C++, guest?!

    А не использовать ли нам bbcode?


    8