获取 OpenReview API v2 客户端
()
| 124 | |
| 125 | |
| 126 | def get_client() -> Optional[OpenReviewClient]: |
| 127 | """获取 OpenReview API v2 客户端""" |
| 128 | global _CLIENT_RETRY_AFTER |
| 129 | |
| 130 | if not OPENREVIEW_AVAILABLE: |
| 131 | return None |
| 132 | |
| 133 | if _CLIENT_RETRY_AFTER and time.time() < _CLIENT_RETRY_AFTER: |
| 134 | return None |
| 135 | |
| 136 | username = os.environ.get("OPENREVIEW_USERNAME", "") |
| 137 | password = os.environ.get("OPENREVIEW_PASSWORD", "") |
| 138 | token = os.environ.get("OPENREVIEW_TOKEN", "") |
| 139 | cache_key = f"{username}|{token}" |
| 140 | |
| 141 | if cache_key in _CLIENT_CACHE: |
| 142 | return _CLIENT_CACHE[cache_key] |
| 143 | |
| 144 | if not username or not password: |
| 145 | if token: |
| 146 | # 使用 token 直接创建客户端 |
| 147 | client = OpenReviewClient( |
| 148 | baseurl=OPENREVIEW_BASE, |
| 149 | token=token |
| 150 | ) |
| 151 | _CLIENT_CACHE[cache_key] = client |
| 152 | return client |
| 153 | else: |
| 154 | print("Warning: OPENREVIEW_USERNAME or OPENREVIEW_PASSWORD not set.") |
| 155 | print("Set credentials in .env file for full API access.") |
| 156 | _CLIENT_CACHE[cache_key] = None |
| 157 | return None |
| 158 | |
| 159 | try: |
| 160 | client = OpenReviewClient( |
| 161 | baseurl=OPENREVIEW_BASE, |
| 162 | username=username, |
| 163 | password=password |
| 164 | ) |
| 165 | print("OpenReview API v2 client initialized") |
| 166 | _CLIENT_CACHE[cache_key] = client |
| 167 | return client |
| 168 | except Exception as e: |
| 169 | error_text = str(e) |
| 170 | if "RateLimitError" in error_text or "Too many requests" in error_text: |
| 171 | _CLIENT_RETRY_AFTER = time.time() + 30 |
| 172 | print(f"OpenReview client initialization error: {e}") |
| 173 | _CLIENT_CACHE[cache_key] = None |
| 174 | return None |
| 175 | |
| 176 | |
| 177 | def _build_submission_invitations(conference: str, year: int) -> List[str]: |
no test coverage detected