Skip to content
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

No login parse #885

Merged
merged 15 commits into from
Nov 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,758 changes: 1 addition & 1,757 deletions rpi_data/Professors.json

Large diffs are not rendered by default.

2,668 changes: 2,668 additions & 0 deletions rpi_data/fall-2024.csv

Large diffs are not rendered by default.

54 changes: 54 additions & 0 deletions rpi_data/modules/ci_scraper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from bs4 import BeautifulSoup as bs
import requests
from pypdf import PdfReader
import os

'''

Check notice on line 6 in rpi_data/modules/ci_scraper.py

View check run for this annotation

codefactor.io / CodeFactor

rpi_data/modules/ci_scraper.py#L6

String statement has no effect (pointless-string-statement)
Scrapes a Communication Intensive PDF as of August 2024

by Giancarlo Martinelli (discord: gcm)
'''

'''

Check notice on line 12 in rpi_data/modules/ci_scraper.py

View check run for this annotation

codefactor.io / CodeFactor

rpi_data/modules/ci_scraper.py#L12

String statement has no effect (pointless-string-statement)
Checks if a string is a number (I just wanted something that returned a boolean)
'''
def is_number(s: str) -> bool:
try:
num = int(s)
return True
except:

Check notice on line 19 in rpi_data/modules/ci_scraper.py

View check run for this annotation

codefactor.io / CodeFactor

rpi_data/modules/ci_scraper.py#L19

No exception type(s) specified (bare-except)
return False

'''

Check notice on line 22 in rpi_data/modules/ci_scraper.py

View check run for this annotation

codefactor.io / CodeFactor

rpi_data/modules/ci_scraper.py#L22

String statement has no effect (pointless-string-statement)
Scrapes an individual page for all of its relevant course codes
'''
def parse_page(page_text: str) -> list[str]:
lines = page_text.split("\n")
result = []
for line in lines:
words = line.split(" ")
if len(words[0]) == 5 and is_number(words[0]):
result.append(words[1].rsplit("-", 1)[0])
return result

'''

Check notice on line 34 in rpi_data/modules/ci_scraper.py

View check run for this annotation

codefactor.io / CodeFactor

rpi_data/modules/ci_scraper.py#L34

String statement has no effect (pointless-string-statement)
Main function, reads a pdf's text and then individually scrapes each page
'''
def parse_pdf(pdf_path: str) -> set[str]:
pdf = PdfReader(pdf_path)
cis = set()
num_pages = len(pdf.pages)
for i in range(num_pages):
page = pdf.pages[i]
text = page.extract_text()
parsed = parse_page(text)
[cis.add(i) for i in parsed]

Check notice on line 45 in rpi_data/modules/ci_scraper.py

View check run for this annotation

codefactor.io / CodeFactor

rpi_data/modules/ci_scraper.py#L45

Expression "[cis.add(i) for i in parsed]" is assigned to nothing (expression-not-assigned)
return cis

'''

Check notice on line 48 in rpi_data/modules/ci_scraper.py

View check run for this annotation

codefactor.io / CodeFactor

rpi_data/modules/ci_scraper.py#L48

String statement has no effect (pointless-string-statement)
For testing
'''
if __name__ == "__main__":
dir_path = os.path.dirname(os.path.realpath(__file__))
pdf_path = os.path.join(dir_path, 'pdfs', 'fall2024-ci.pdf')
parse_pdf(pdf_path)
Loading