From 2cd771d8297799dc30bd02c4fd5a37fa48d7eaa0 Mon Sep 17 00:00:00 2001 From: wes Date: Sun, 20 Nov 2016 12:06:29 -0500 Subject: [PATCH 1/7] use script tags everywhere --- src/scripts/book.tag | 1 + src/scripts/class.tag | 1 + src/scripts/row.tag | 3 +++ src/scripts/search.tag | 21 ++++++++++++--------- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/scripts/book.tag b/src/scripts/book.tag index 0491b0f..2c1444d 100644 --- a/src/scripts/book.tag +++ b/src/scripts/book.tag @@ -27,6 +27,7 @@

+ + diff --git a/src/scripts/row.tag b/src/scripts/row.tag index 2725142..8dafbbd 100644 --- a/src/scripts/row.tag +++ b/src/scripts/row.tag @@ -4,6 +4,9 @@ data="{ this }"> + + diff --git a/src/scripts/search.tag b/src/scripts/search.tag index f18eb43..116aa17 100644 --- a/src/scripts/search.tag +++ b/src/scripts/search.tag @@ -1,10 +1,10 @@ -
+
- - Type keywords of your course's name or the course code (e.g. PSYCH 2B03) @@ -35,17 +35,17 @@
- + + + From e09df030502a97a13164c1d773e86422c00597ac Mon Sep 17 00:00:00 2001 From: wes Date: Sun, 20 Nov 2016 16:22:23 -0500 Subject: [PATCH 2/7] tweaks to layout to make it more responsive --- src/scripts/search.tag | 32 ++++++++++++++++----------- src/styles/search.scss | 46 ++++++++++++++++++++++++++++++++------- src/templates/search.html | 12 +++++----- 3 files changed, 63 insertions(+), 27 deletions(-) diff --git a/src/scripts/search.tag b/src/scripts/search.tag index 116aa17..7cf67b8 100644 --- a/src/scripts/search.tag +++ b/src/scripts/search.tag @@ -1,26 +1,32 @@ +
+
-
+
-
-
- -
-
- + name="title"> +
+ +
+
+ +
+
+ +
+
diff --git a/src/styles/search.scss b/src/styles/search.scss index cc27e0d..0439bd7 100644 --- a/src/styles/search.scss +++ b/src/styles/search.scss @@ -4,6 +4,10 @@ header { color: $blue; } +.form-group { + margin: auto; +} + .wraptext { white-space: pre-wrap !important; } @@ -77,17 +81,43 @@ a { margin-right: 0px !important; } -.form-item { - padding-left: 5px; - padding-right: 5px; - margin-right: -15px; +.search { + max-width: 60%; + margin-bottom: 10px; + margin-left: auto; + margin-right: auto; + @media (max-width: 735px) { + max-width: 80%; + } + @media (max-width: 480px) { + max-width: 100%; + margin-bottom: 10px; + } +} + +.semester { + margin-bottom: 10px; + @media (max-width: 480px) { + max-width: 100%; + margin-bottom: 10px; + } +} + +.search-btn { + margin-bottom: 10px; + @media (max-width: 480px) { + max-width: 100%; + margin-bottom: 10px; + } +} + +.search-controls { + margin-top: 5px; + margin-left: 20%; } .title { font-weight: bolder; - @media (min-width: 480px) { - margin-left: 80px; - } } .ui-autocomplete { @@ -141,7 +171,7 @@ a { .page-top { font-size: 15px; - width: 50% !important; + width: 80% !important; } .help-toast { diff --git a/src/templates/search.html b/src/templates/search.html index 9debd7c..f4b61d2 100644 --- a/src/templates/search.html +++ b/src/templates/search.html @@ -3,17 +3,17 @@ {{super()}} From 1d023d61fe4875b3e34c588cb9f3283158a79670 Mon Sep 17 00:00:00 2001 From: wes Date: Sat, 26 Nov 2016 08:41:13 -0500 Subject: [PATCH 3/7] styling changes --- src/scripts/results.tag | 5 +++- src/scripts/search.tag | 31 +++++++++++++---------- src/styles/bootstrap.min.css | 14 +++++++++++ src/styles/search.scss | 18 ++++++++++++-- src/templates/search.html | 48 ++++++++++++++++-------------------- src/visualize.py | 18 +------------- src/website.py | 1 - 7 files changed, 74 insertions(+), 61 deletions(-) create mode 100644 src/styles/bootstrap.min.css diff --git a/src/scripts/results.tag b/src/scripts/results.tag index dcdaf4e..a01ff3a 100644 --- a/src/scripts/results.tag +++ b/src/scripts/results.tag @@ -1,6 +1,9 @@
- + 0} class="course-row columns" each={ rows } data="{ this }" classrow={ row }> +
+ No Results, Sorry! +
- - - -{% endblock %} - + + + + + + + diff --git a/src/visualize.py b/src/visualize.py index 3ec1098..215296f 100755 --- a/src/visualize.py +++ b/src/visualize.py @@ -9,24 +9,8 @@ from operator import attrgetter import pygal import csv -class Textbook(object): - def __init__(self, dept, code, title, author, price): - self.dept = dept - self.code = code - self.title = title - self.author = author - self.price = float(price) - - def __repr__(self): - return "Dept = %s, Code = %s, %s by %s, costs $%s" % (self.dept, - self.code, - self.title, - self.author, - self.price) - - def courses(): - with open("./books.csv", "r") as books: + with open("./mcmaster/courses.csv", "r") as books: booksreader = csv.reader(books) for row in booksreader: yield row diff --git a/src/website.py b/src/website.py index bdbd64c..a543202 100755 --- a/src/website.py +++ b/src/website.py @@ -142,7 +142,6 @@ def ClassSearch(configfile=None): app = Flask(__name__) app.register_blueprint(blueprint, url_prefix="/search") - Bootstrap(app) #app.config["scripts"] = "./scripts" #app.config["styles"] = "./styles" return app From 37cd50f5fb6fb8a308c98f399a1e61e94469a667 Mon Sep 17 00:00:00 2001 From: wes Date: Sat, 26 Nov 2016 13:04:22 -0500 Subject: [PATCH 4/7] make IA searches a bit better --- src/archive.py | 7 ++++--- src/scripts/book.tag | 4 ++-- src/search.py | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/archive.py b/src/archive.py index 4d73ab6..5f18e17 100755 --- a/src/archive.py +++ b/src/archive.py @@ -5,14 +5,14 @@ from json import loads, dumps import requests as req -searchUrl = "https://archive.org/advancedsearch.php?q={0}&fl%5B%5D=avg_rating&fl%5B%5D=description&fl%5B%5D=identifier&fl%5B%5D=type&sort%5B%5D=&sort%5B%5D=&sort%5B%5D=&rows=50&page=1&output=json&callback=callback&save=yes#raw" +searchUrl = "https://archive.org/advancedsearch.php?q={0}&fl%5B%5D=avg_rating&fl%5B%5D=description&fl%5B%5D=identifier&fl%5B%5D=mediatype&fl%5B%5D=type&fl%5B%5D=type&sort%5B%5D=&sort%5B%5D=&sort%5B%5D=&rows=50&page=1&output=json&callback=callback&save=yes#raw" def searchIA(title, author): """ Do a search on The Internet Archive for a book """ print("running a search") - requrl = searchUrl.format(quote(title + " " + author)) + requrl = searchUrl.format(quote(title) + " AND " + quote(author)) try: results = loads(req.get(requrl).text[9:][0:-1]) except ValueError: @@ -24,7 +24,8 @@ def searchIA(title, author): return [] docs = results["response"]["docs"] urls = [] - for result in results["response"]["docs"][0:3]: + for result in [r for r in results["response"]["docs"][0:10] if r["mediatype"] == "texts"]: + print(result) urls.append("https://archive.org/details/%s" % result["identifier"]) return urls diff --git a/src/scripts/book.tag b/src/scripts/book.tag index 2c1444d..7ce82f1 100644 --- a/src/scripts/book.tag +++ b/src/scripts/book.tag @@ -9,14 +9,14 @@

-

- diff --git a/src/search.py b/src/search.py index ee04eb3..a9c67d0 100755 --- a/src/search.py +++ b/src/search.py @@ -20,8 +20,8 @@ es = elasticsearch.Elasticsearch() def summarize(text): splitted = text.split(" ") - if len(splitted) > 4: - return " ".join(splitted[0:4]) + ".." + if len(splitted) > 6: + return " ".join(splitted[0:6]) + ".." return text def sectionToJSON(section): @@ -204,7 +204,7 @@ def searchTerms(terms): if obj.books: secs["books"] = [ { - "booktitle" : summarize(book[0]), + "booktitle" : book[0], "bookauthor" : book[1], "bookprice" : book[2] } From d78b928103f77c2a6363fb65fafff586f6e71111 Mon Sep 17 00:00:00 2001 From: wes Date: Sat, 26 Nov 2016 13:06:04 -0500 Subject: [PATCH 5/7] switch default semester to Fall --- src/scripts/search.tag | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scripts/search.tag b/src/scripts/search.tag index 772337a..61f0e60 100644 --- a/src/scripts/search.tag +++ b/src/scripts/search.tag @@ -26,8 +26,8 @@

From e130ef661aa4ad219fb3e73655f3ae68aec1257e Mon Sep 17 00:00:00 2001 From: wes Date: Sat, 26 Nov 2016 13:15:05 -0500 Subject: [PATCH 6/7] add author in field --- src/scripts/book.tag | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scripts/book.tag b/src/scripts/book.tag index 7ce82f1..7632e2d 100644 --- a/src/scripts/book.tag +++ b/src/scripts/book.tag @@ -2,7 +2,7 @@

From 5afe1e61fc8b10830dbac78bff34c5fd7c88b6c4 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sun, 27 Nov 2016 17:06:10 +0000 Subject: [PATCH 7/7] fix bugs when porting to python 3 from 2 --- src/mcmaster/classes.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/mcmaster/classes.py b/src/mcmaster/classes.py index 04b8dcd..df15d09 100755 --- a/src/mcmaster/classes.py +++ b/src/mcmaster/classes.py @@ -214,7 +214,7 @@ def parseColumns(subject, html): classInfo = (list(getSectionInfo(table)) for table in islice((table for table in parsed.xpath(".//table") if table.xpath("@id") and - search(r"ICField[0-9]+\$scroll", table.xpath("@id")[0])), 1, sys.maxint)) + search(r"ICField[0-9]+\$scroll", table.xpath("@id")[0])), 1, sys.maxsize)) classNames = ((subject, span.text_content().strip()) for span in parsed.xpath(".//span") if span.xpath("@id") and @@ -245,7 +245,7 @@ class MosReq(object): self.codes_ = [] def getlist(self, subject): - sys.stderr.write("Getting " + subject + "\n") + sys.stderr.write("Getting %s\n" % subject.decode("UTF-8")) first_req = requests.get(searchurl, cookies=self.cookies).content # for some reason Mosaic wants us to request it twice, ?????????????????? self.statenum = getStateNum(first_req) @@ -259,7 +259,7 @@ class MosReq(object): self.statenum = getStateNum(first_req) except IndexError: pass - if "Your search will return over" in first_req: + if b"Your search will return over" in first_req: return requests.post(searchurl, data=payload2.format(self.statenum, self.semester), @@ -302,7 +302,8 @@ def request(codes, lists, semester): code = codes.get() try: lists.put(requester.classes(code)) - except: + except exception: + print(exception) codes.task_done() return codes.task_done() @@ -342,6 +343,7 @@ class CourseInfo(object): for cl in chain.from_iterable(sections): new_sections = [] for sec in cl[1]: + print(sec) if len(sec.day) > 1: for day in sec.day: new_sections.append(copy.deepcopy(sec))