-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit ca1470d
Showing
18 changed files
with
3,455 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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,115 @@ | ||
.idea | ||
SiteStuff | ||
storage | ||
|
||
Notebooks/.ipynb_checkpoints | ||
|
||
|
||
|
||
# Created by .ignore support plugin (hsz.mobi) | ||
### Python template | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
var/ | ||
wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
.hypothesis/ | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
.static_storage/ | ||
.media/ | ||
local_settings.py | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# celery beat schedule file | ||
celerybeat-schedule | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
|
This file contains 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,19 @@ | ||
""" | ||
Created by 復讐者 on 2/15/19 | ||
""" | ||
__author__ = '復讐者' | ||
|
||
import json | ||
from CourseZero.FileSystemTools import getSystemRoot | ||
from CourseZero import environment as env | ||
|
||
|
||
def load_campus_id_data(data_json_path=env.DEFAULT_CSU_ID_FILE): | ||
with open( data_json_path, 'r' ) as fpp: | ||
return json.load(fpp) | ||
|
||
# campus_ids = load_campus_id_data(csu_id_data) | ||
# csu_names = [c['name'] for c in campus_ids] | ||
|
||
if __name__ == '__main__': | ||
pass |
This file contains 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,64 @@ | ||
""" | ||
Utillities for exploring the filesystem | ||
Created by 復讐者 on 12/27/16 | ||
""" | ||
__author__ = '復讐者' | ||
|
||
import os | ||
import datetime | ||
|
||
|
||
def getDateForMakingFileName(): | ||
"""Returns the standard string format of today's date to be used in making a file name""" | ||
return datetime.date.isoformat( datetime.date.today() ) | ||
|
||
|
||
def getTimestampForMakingFileName(): | ||
"""Returns the standard string format of timestamp used in making a file name""" | ||
return datetime.datetime.now().strftime( "%Y-%m-%d_%H:%M:%S" ) | ||
|
||
|
||
def getSystemRoot(): | ||
""" | ||
Returns the base directory path. | ||
""" | ||
return os.getenv( "HOME" ) | ||
|
||
|
||
def makeDataFileList( folderPath, exclude=[ ] ): | ||
""" | ||
Returns a a list of all files in the source directory | ||
so that each file has its path appended to it. | ||
Args: | ||
folderPath: The path to get file names from | ||
exclude: file names which should not be included in the output list | ||
""" | ||
exclude = exclude if any( exclude ) else [ '.DS_Store' ] | ||
datafiles = [ ] | ||
for root, dirs, files in os.walk( folderPath ): | ||
for name in files: | ||
if name not in exclude: | ||
datafiles.append( os.path.join( root, name ) ) | ||
|
||
return datafiles | ||
|
||
|
||
def makeDataFileIterator( folderPath, exclude=[ ] ): | ||
""" | ||
Returns an iterator of all files in the source directory | ||
so that each file has its path appended to it. | ||
Args: | ||
folderPath: The path to get file names from | ||
exclude: file names which should not be included in the output list | ||
""" | ||
exclude = exclude if any( exclude ) else [ '.DS_Store' ] | ||
for root, dirs, files in os.walk( folderPath ): | ||
for name in files: | ||
if name not in exclude: | ||
yield os.path.join( root, name ) | ||
|
||
|
||
if __name__ == '__main__': | ||
pass |
This file contains 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,66 @@ | ||
""" | ||
These are methods and functions to make queries to the site | ||
Created by 復讐者 on 2/15/19 | ||
""" | ||
__author__ = '復讐者' | ||
|
||
import requests | ||
import json | ||
|
||
import CourseZero.UrlMakers as U | ||
|
||
ABCS = 'abcdefghijklmnopqrstuvwxyz' | ||
|
||
USER_AGENT = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36" | ||
HEADERS = { 'User-Agent': USER_AGENT } | ||
|
||
|
||
def get_content( url, headers=HEADERS ): | ||
response = requests.get( url, headers=headers ) | ||
return response.content | ||
|
||
|
||
def get_docs_for_campus(campus_id, campus_name): | ||
data = [] | ||
print( "Searching for {}".format(campus_name) ) | ||
for letter in ABCS: | ||
try: | ||
url = U.make_course_search_url( letter, campus_id ) | ||
r = requests.get( url, headers=HEADERS ) | ||
data.append( r.json() ) | ||
except: | ||
pass | ||
return data | ||
|
||
|
||
def get_docs_for_campuses( campus_ids: list, data_json_path=None ): | ||
"""Queries for all documents for each campus in campus_ids. | ||
Saves the results as a json to the provided path | ||
:param data_json_path: | ||
:param campus_ids: List of tuples with format (csu name, campus id) | ||
""" | ||
|
||
data = [ ] | ||
|
||
for c in campus_ids: | ||
csu = c['name'] | ||
csuid = c['campus_id'] | ||
data += get_docs_for_campus(csuid, csu) | ||
# print( "Searching for {}".format(csu) ) | ||
# for letter in ABCS: | ||
# try: | ||
# url = U.make_course_search_url( letter, csuid ) | ||
# r = requests.get( url, headers=HEADERS ) | ||
# data.append( r.json() ) | ||
# except: | ||
# pass | ||
|
||
if data_json_path: | ||
with open( data_json_path, 'w+' ) as fpp: | ||
json.dump( data, fpp ) | ||
|
||
return data | ||
|
||
if __name__ == '__main__': | ||
pass |
This file contains 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,72 @@ | ||
""" | ||
Created by 復讐者 on 2/15/19 | ||
""" | ||
__author__ = '復讐者' | ||
|
||
|
||
class DataStore( object ): | ||
professor_first_name = None | ||
professor_last_name = None | ||
campus_name = None | ||
campus_id = None | ||
departments = [ ] | ||
course_ids = [] | ||
|
||
@classmethod | ||
def _parse_event( cls, event ): | ||
if event[ 'type' ] == 'change' and event[ 'name' ] == 'value': | ||
v = event[ 'new' ] | ||
return v | ||
|
||
@classmethod | ||
def set_professor_lname( cls, event ): | ||
v = cls._parse_event( event ) | ||
if v is not None: | ||
cls.professor_last_name = v | ||
|
||
@classmethod | ||
def set_professor_fname( cls, event ): | ||
v = cls._parse_event( event ) | ||
if v is not None: | ||
cls.professor_first_name = v | ||
|
||
@classmethod | ||
def set_campus_name( cls, event ): | ||
v = cls._parse_event( event ) | ||
if v is not None: | ||
cls.campus_name = v | ||
|
||
@classmethod | ||
def add_course( cls, course ): | ||
cls.course_ids.append( course ) | ||
cls.course_ids = list(set(cls.course_ids)) | ||
# cls.departments = list( set( cls.departments.append( dept ) ) ) | ||
|
||
@classmethod | ||
def remove_course( cls, course ): | ||
el = list(filter(lambda x: x == course, cls.course_ids))[0] | ||
idx = cls.course_ids.index(el) | ||
return cls.course_ids.pop(idx) | ||
|
||
@classmethod | ||
def add_department( cls, dept ): | ||
cls.departments.append( dept ) | ||
# cls.departments = list( set( cls.departments.append( dept ) ) ) | ||
|
||
@classmethod | ||
def remove_department( cls, dept ): | ||
el = list(filter(lambda x: x == dept, cls.departments))[0] | ||
idx = cls.departments.index(el) | ||
return cls.departments.pop(idx) | ||
|
||
|
||
class TakedownStore( DataStore ): | ||
agreed_w_reqd_statements = False | ||
|
||
@classmethod | ||
def toggle_statement_agreement( cls ): | ||
cls.agreed_w_reqd_statements = not cls.agreed_w_reqd_statements | ||
|
||
|
||
if __name__ == '__main__': | ||
pass |
This file contains 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,17 @@ | ||
""" | ||
Created by 復讐者 on 2/15/19 | ||
""" | ||
__author__ = '復讐者' | ||
|
||
|
||
def make_campus_search_url(campus): | ||
campus_search_url = "https://www.coursehero.com/ajax/autocomplete_resultset.php?term=%s&type=school" | ||
return campus_search_url % campus | ||
|
||
def make_course_search_url(query, csu_id): | ||
course_search_url = "https://www.coursehero.com/api/v1/courses/search/?q=%s&schoolId=%s" | ||
return course_search_url % (query, csu_id) | ||
|
||
|
||
if __name__ == '__main__': | ||
pass |
Oops, something went wrong.