Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Minor syntax changes in scrape_grades per PR comments
Browse files Browse the repository at this point in the history
- Removed unnecessary import to pass linting
- Changed task collecting to use list comprehension
- Changed colleges & years assignment to use ternary operators
  • Loading branch information
gannonprudhomme committed Mar 22, 2020
1 parent 64c26ad commit 1268c7f
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions autoscheduler/scraper/management/commands/scrape_grades.py
Expand Up @@ -9,7 +9,6 @@
import bs4
from aiohttp import ClientSession

from django.core.exceptions import ObjectDoesNotExist
from django.core.management import base

from scraper.models import Grades, Section
Expand Down Expand Up @@ -201,12 +200,8 @@ async def retrieve_pdf(year_semester: str, college: str):
semesters = [SPRING, SUMMER, FALL]

# Gather all of the retrieve functions into an array
tasks = []
for year in years:
for semester in semesters:
for college in colleges:
year_semester_term = str(year) + semester
tasks.append(retrieve_pdf(year_semester_term, college))
tasks = [retrieve_pdf(f"{year}{semester}", college)
for year in years for semester in semesters for college in colleges]

grades = [] # list of Grades models
for scraped_grades in await asyncio.gather(*tasks, loop=loop):
Expand Down Expand Up @@ -246,13 +241,10 @@ def handle(self, *args, **options):

# Retrieve the page data and get the available colleges & years from it
page_soup = fetch_page_data()
years = _get_available_years(page_soup)
if options['year']:
years = [options['year']]

colleges = _get_colleges(page_soup)
if options['college']:
colleges = [options['college']]
years = [options['year']] if options['year'] else _get_available_years(page_soup)
colleges = ([options['college']] if options['college']
else _get_colleges(page_soup))

loop = asyncio.get_event_loop()
scraped_grades = loop.run_until_complete(perform_searches(years, colleges))
Expand Down

0 comments on commit 1268c7f

Please sign in to comment.