import configparser, csv, datetime, html.parser, itertools, os, sys class SetupException(Exception): def __str__(self): return "Seems like config.cfg has not been created yet or contains serious errors. Run setup.py to create it." def getSetting(section, setting, path = "config.cfg"): config = configparser.RawConfigParser() config.read(path) return config.get(section, setting) def riuser(): try: return getSetting("Read.it", "user") except: raise SetupException() def ripass(): try: return getSetting("Read.it", "pass") except: raise SetupException() def fileExists(path): return os.path.isfile(path) def getDate(date): try: return datetime.datetime.strptime(date, '%Y-%m-%d') except ValueError: raise ValueError("Dates must be in YYYY-MM-DD format.") def paginate(iterable, page_size): while True: i1, i2 = itertools.tee(iterable) iterable, page = (itertools.islice(i1, page_size, None), list(itertools.islice(i2, page_size))) if len(page) == 0: break yield page def printCSV(inlist): writer = csv.writer(sys.stdout) writer.writerows(inlist) def unescapeText(text): return html.parser.HTMLParser().unescape(text).replace("'","''")