Skip to content

Commit

Permalink
Take care of ints in the YAML file in a cleaner way
Browse files Browse the repository at this point in the history
  • Loading branch information
pR0Ps committed Dec 3, 2014
1 parent 588fa4f commit 08f3398
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions update_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,25 @@
import sys
from navigation import SolusSession

def str_unless_none(obj):
"""Convert an object to a string unless it's None"""
if obj is not None:
return str(obj)
return obj

def iterkeyvalue(obj):
"""Make it easy to iterate over dicts, lists, and strings"""
if isinstance(obj, dict):
for k, v in obj.items():
yield k, v
yield str_unless_none(k), v
elif isinstance (obj, list):
for x in obj:
yield x, None
yield str_unless_none(x), None
else:
yield obj, None
yield str_unless_none(obj), None

def get_filter(obj):
"""Pick out the list of objects to filter by from a config item"""
# TODO: Fix str mapping once when parsing the config file
if obj is None:
return [] # Empty list = accept nothing (optimized in the parser)
elif hasattr(obj, "keys"):
Expand Down Expand Up @@ -110,7 +115,6 @@ def scrape_courses(self, courses):

# Iterate over all courses
for course, terms in iterkeyvalue(courses):
course = str(course) if course is not None else None # TODO: Fix once when parsing the config file

curr_course = all_courses.get(course)
if curr_course is None:
Expand Down Expand Up @@ -158,7 +162,6 @@ def scrape_sections(self, sections):
# Don't really need the `iterkeyvalue` but it makes the config
# parsing a litte more lax so whatever
for section, _ in iterkeyvalue(sections):
section = str(section) if section is not None else None #TODO: ugh

curr_section = all_sections.get(section)
if curr_section is None:
Expand Down

0 comments on commit 08f3398

Please sign in to comment.