Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
npnkhoi committed Aug 21, 2022
1 parent dfb18c8 commit 4c802d8
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 14 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# When2STEM: Course information scrapper at Fulbright University Vietnam.
# Course information scrapper at Fulbright University Vietnam
## Installation
0. `pip install pipenv`

1. Clone this repo
1. Clone this repo and `cd` to this project folder.
2. Install packages:
* In your terminal, `cd` to this project folder
* Run `pip install pipenv` (install `pipenv` for package management)
* Run `pip install pipenv`
* Run `pipenv install` (automatically install all required packages)
3. Download the appropriate driver of your web browser, put it into this project folder. For Chrome, go to https://chromedriver.chromium.org/.
4. Run `cp env_sample.py env.py`, then edit the content of `env.py`. This file contains 3 things: the location of the browser driver (step 3), your Outlook username and password.

## Execution
1. Run `pipenv shell` -> activate virtual environment.
2. Run `python -m src.main`
3. Enjoy the automation!
2. Run `python -m src.main [id]`, where `id` is the order of the target term in the dropdown list in the offering page of OneStop.
3. When the browser is at the 2FA page, you have 60s to verify it.
Binary file added geckodriver-v0.31.0-linux64/geckodriver
Binary file not shown.
4 changes: 2 additions & 2 deletions src/get_courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
DESCRIPTION = 'slds-rich-text-editor__output.uiOutputRichText.forceOutputRichText'
SCHEDULE = 'forceRecordLayout.slds-table.slds-no-row-hover.slds-table_cell-buffer.slds-table_fixed-layout.uiVirtualDataGrid--default.uiVirtualDataGrid'
METADATA = 'slds-grid.slds-gutters_small'
CURRENT_TERM = 'Summer' # FIXME: Update this!
CURRENT_TERM = 'Fall' # FIXME: Update this!

def scroll(browser: WebDriver):
"""Scroll the course list to make more course visible"""
Expand Down Expand Up @@ -93,4 +93,4 @@ def get_course_schedule(browser: WebDriver):
data[term].append(course)
browser.back()

return data
return data
9 changes: 7 additions & 2 deletions src/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
from src.utils import click_element, click_element_among, get_element, get_element_among, get_elements
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver import Chrome

TERM_SELECTOR = 'triggerLinkText.selectedListView.slds-page-header__title'
TERM_OPTION = 'virtualAutocompleteOptionText'

def login(browser) -> None:
def login(browser: Chrome) -> None:
print('Logging into OneStop ...')
browser.get('https://onestop.fulbright.edu.vn/')

Expand All @@ -19,11 +20,15 @@ def login(browser) -> None:

password_field = get_element(browser, By.ID, 'i0118')
password_field.send_keys(PASSWORD)

# 'Sign in' button
click_element(browser, By.ID, 'idSIButton9')

# Start authentication
current = browser.switch_to.active_element
current.send_keys(Keys.RETURN)

# 'Yes' (stayed sign in)
print('You have 60 seconds for 2FA authentication')
click_element(browser, By.ID, 'idSIButton9', timeout=60)
print('Successfully logged in')

Expand Down
9 changes: 7 additions & 2 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from src.get_courses import get_course_schedule
from selenium import webdriver
from env import FIREFOX_DRIVER_PATH
from env import CHROME_DRIVER_PATH, FIREFOX_DRIVER_PATH
from src.init import access_enrollment, login
import click
from src.utils import current_time, save_json
Expand All @@ -9,7 +9,12 @@
@click.argument('term-id', type=int) # 1-based, from Fall2021
def main(term_id):
tic = current_time()
browser = webdriver.Firefox(executable_path=FIREFOX_DRIVER_PATH)
# PROFILE = '/home/khoi/snap/firefox/common/.cache/mozilla/firefox/t466tqbs.Khoi/'
# fp = webdriver.FirefoxProfile(PROFILE)
# browser = webdriver.Firefox(executable_path=FIREFOX_DRIVER_PATH, firefox_profile=fp)
print('hey')
browser = webdriver.Chrome(executable_path=CHROME_DRIVER_PATH)
print('Start login ...')
login(browser)
access_enrollment(browser, term_id)
data = get_course_schedule(browser)
Expand Down
4 changes: 2 additions & 2 deletions src/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

""" Selenium utils """

DEFAULT_WAIT = 5
DEFAULT_WAIT = 10
def get_element(browser, by_method, key, timeout=DEFAULT_WAIT):
return WebDriverWait(browser, timeout).until(EC.visibility_of_element_located((by_method, key)))

Expand Down Expand Up @@ -59,4 +59,4 @@ def get_next_to(data: List[str], key: str, offset=1) -> str or None:
for i in range(len(data) - offset):
if data[i] == key:
return data[i+offset]
return None
return None

0 comments on commit 4c802d8

Please sign in to comment.