-
Notifications
You must be signed in to change notification settings - Fork 17
Fix llm 01 patch #123
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
TobeTek
wants to merge
2
commits into
main
Choose a base branch
from
fix-llm-01-patch
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Fix llm 01 patch #123
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| QOOPER_EMAIL=user@email.com | ||
| QOOPER_PASSWORD=password | ||
|
|
||
| CHROME_DRIVER_PATH=/chromedriver-linux64/chromedriver | ||
| CHROME_PATH=/usr/bin/google-chrome |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| output/ | ||
| chromedriver* | ||
| qooper-token.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| - Setup Selenium (Chrome Driver, Chrome install) | ||
| Grab the Chrome installer and driver from https://googlechromelabs.github.io/chrome-for-testing/ | ||
|
|
||
| ```bash | ||
| wget https://storage.googleapis.com/chrome-for-testing-public/131.0.6778.85/linux64/chromedriver-linux64.zip | ||
| ``` | ||
|
|
||
| Selenium and Chrome in WSL | ||
| ```bash | ||
| https://www.gregbrisebois.com/posts/chromedriver-in-wsl2/ | ||
| ``` | ||
|
|
||
| - Setup environment variables | ||
| .env.example is a template to become .env | ||
|
|
||
|
|
||
| - Works by signing in to the site using Selenium (sign-in involves multiple APIs and services, and so would be difficult to achieve with vanilla web scrapping) | ||
|
|
||
| - Uses the tokens retrieved to query Qooper API | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import os | ||
| import sys | ||
| import json | ||
|
|
||
| from selenium import webdriver | ||
| from selenium.webdriver.common.by import By | ||
| from selenium.webdriver.chrome.service import Service | ||
| from selenium.webdriver.common.keys import Keys | ||
| from selenium.webdriver.support import expected_conditions as EC | ||
| from selenium.webdriver.remote.webdriver import BaseWebDriver | ||
| from selenium.webdriver.support.wait import WebDriverWait | ||
| from dotenv import load_dotenv | ||
|
|
||
| load_dotenv() | ||
|
|
||
|
|
||
| QOOPER_HOME_PAGE = "https://mentoring.qooper.io/" | ||
|
|
||
| try: | ||
| CHROME_DRIVER_PATH = os.environ.get( | ||
| "CHROME_DRIVER_PATH", r"chromedriver-linux64/chromedriver" | ||
| ) | ||
| CHROME_PATH = os.environ.get("CHROME_PATH", r"/usr/bin/google-chrome") | ||
| QOOPER_EMAIL = os.environ["QOOPER_EMAIL"] | ||
| QOOPER_PASSWORD = os.environ["QOOPER_PASSWORD"] | ||
| except KeyError as error: | ||
| print(f"Set environment variables: {error.with_traceback()}") | ||
| sys.exit(1) | ||
|
|
||
|
|
||
| def wait_for_element_visible( | ||
| driver: BaseWebDriver, element_identifier, by: By = By.XPATH, timeout=10 | ||
| ): | ||
| return WebDriverWait(driver, timeout).until( | ||
| EC.presence_of_element_located((by, element_identifier)) | ||
| ) | ||
|
|
||
|
|
||
| def wait_for_element_clickable( | ||
| driver: BaseWebDriver, element_identifier, by: By = By.XPATH, timeout=10 | ||
| ): | ||
| return WebDriverWait(driver, timeout).until( | ||
| EC.element_to_be_clickable((by, element_identifier)) | ||
| ) | ||
|
|
||
|
|
||
| def login_to_qooper(driver: webdriver.Chrome): | ||
| driver.get(QOOPER_HOME_PAGE) | ||
|
|
||
| input_email = wait_for_element_visible( | ||
| driver, | ||
| "input[type=email]", | ||
| By.CSS_SELECTOR, | ||
| ) | ||
| input_email.send_keys(QOOPER_EMAIL) | ||
| next_button = driver.find_element(By.CSS_SELECTOR, "button.btn.bg-blue") | ||
| next_button.click() | ||
|
|
||
| input_password = wait_for_element_visible( | ||
| driver, | ||
| "input[type=password]", | ||
| By.CSS_SELECTOR, | ||
| ) | ||
| input_password.send_keys(QOOPER_PASSWORD) | ||
| next_button = driver.find_element(By.CSS_SELECTOR, "button.btn.bg-blue") | ||
| next_button.click() | ||
|
|
||
| radio_input_kagglex = wait_for_element_clickable( | ||
| driver, | ||
| 'label[for="KaggleX Fellowship Program - Cohort 4"]', | ||
| By.CSS_SELECTOR, | ||
| timeout=30, | ||
| ) | ||
|
|
||
| radio_input_kagglex.click() | ||
| next_button = driver.find_element(By.CSS_SELECTOR, 'button[label="Continue"]') | ||
| next_button.click() | ||
|
|
||
| wait_for_element_visible( | ||
| driver, | ||
| "p", | ||
| By.TAG_NAME, | ||
| ) | ||
|
|
||
| auth_token = driver.execute_script("return localStorage.getItem('qooper_atfu');") | ||
| auth_token = json.loads(auth_token) | ||
| print('Auth token: ', f"{auth_token[:4]}...{auth_token[-4:]}") | ||
| with open('qooper-token.txt', 'w') as f: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚨 issue (security): Avoid storing authentication tokens in plaintext files Consider using environment variables or a secure credential store instead of writing tokens to disk. |
||
| f.write(auth_token) | ||
|
|
||
|
|
||
| options = webdriver.ChromeOptions() | ||
| options.page_load_strategy = "eager" | ||
| options.add_argument("--no-sandbox") | ||
| service = Service(executable_path=CHROME_DRIVER_PATH) | ||
|
|
||
| browser = webdriver.Chrome( | ||
| options=options, | ||
| service=service, | ||
| ) | ||
|
|
||
| try: | ||
| login_to_qooper(browser) | ||
|
|
||
| finally: | ||
| browser.quit() | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| annotated-types==0.7.0 | ||
| attrs==24.2.0 | ||
| certifi==2024.8.30 | ||
| charset-normalizer==3.4.0 | ||
| h11==0.14.0 | ||
| idna==3.10 | ||
| outcome==1.3.0.post0 | ||
| pydantic==2.10.2 | ||
| pydantic_core==2.27.1 | ||
| PySocks==1.7.1 | ||
| python-dotenv==1.0.1 | ||
| requests==2.32.3 | ||
| selenium==4.26.1 | ||
| sniffio==1.3.1 | ||
| sortedcontainers==2.4.0 | ||
| trio==0.27.0 | ||
| trio-websocket==0.11.1 | ||
| typing_extensions==4.12.2 | ||
| urllib3==2.2.3 | ||
| websocket-client==1.8.0 | ||
| wsproto==1.2.0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| from pydantic import BaseModel, RootModel | ||
| from typing import Optional, Generic, TypeVar | ||
|
|
||
| T = TypeVar("T") | ||
|
|
||
|
|
||
| class Group(BaseModel, Generic[T]): | ||
| id: int | ||
| name: str | ||
| description: Optional[str] = "" | ||
| image_url: Optional[str] | ||
| kind: str | ||
| tags: list[str] = [] | ||
| is_joined: bool = True | ||
| members_count: int = 0 | ||
| resources_count: int = 0 | ||
| discussions_count: int = 0 | ||
| past_events_count: int = 0 | ||
| upcoming_events_count: int = 0 | ||
| created_at: str | ||
|
|
||
|
|
||
| class GroupList(RootModel): | ||
| root: list[Group] | ||
|
|
||
|
|
||
| class GroupMember(BaseModel, Generic[T]): | ||
| id: int | ||
| first_name: str | ||
| last_name: str | ||
| image_url: Optional[str] | ||
| current_position: Optional[str] | ||
| current_organization: Optional[str] | ||
| roles: list[str] = [] | ||
|
|
||
|
|
||
| class GroupMemberList(RootModel): | ||
| root: list[GroupMember] | ||
|
|
||
|
|
||
| class GroupEvent(BaseModel, Generic[T]): | ||
| id: int | ||
| title: str | ||
| timezone: str | ||
| start_time: str | ||
| end_time: str | ||
| image_url: Optional[str] | ||
| updated_at: str | ||
| created_at: str | ||
| address: Optional[str] | ||
| # When scraping discussions or events, | ||
| # store their publishers in a separate group member table, | ||
| # Then keep only the ID on the relevant record | ||
| publisher: GroupMember["id"] | ||
|
|
||
|
|
||
| class GroupEventList(RootModel): | ||
| root: list[GroupEvent] | ||
|
|
||
|
|
||
| class Discussion(BaseModel, Generic[T]): | ||
| id: int | ||
| # If comments_count > 2, | ||
| # query the discussion detail page to get all comments | ||
| comments_count: Optional[int] = None | ||
| upvotes_count: Optional[int] = None | ||
| attachments_count: Optional[int] = None | ||
| title: Optional[str] = None | ||
| description: Optional[str] = None | ||
| created_at: str | ||
| publisher: GroupMember["id"] | ||
| tags: list[str] = [] | ||
| upvotes_user_ids: list[int] = [] | ||
| comments: list[int] = [] | ||
| is_comment: bool = False | ||
|
|
||
|
|
||
| class DiscussionList(RootModel): | ||
| root: list[Discussion] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (code-quality): Extract duplicate code into function (
extract-duplicate-method)