def insert_db():
	"""
	Save the notices in Notice sqlite database
	"""
	logging.debug("called : %s", __name__)

	notices = extract.get_notice_list(False)
	if notices is None:
		logging.error("error getting notice list")
		return None

	count = 0
	for notice in notices:
		if NoticeWrapper.insert_dict_safe(notice):
			count += 1
			print "Added notice dated '{}' titled '{}'.".format(
					notice['time'], notice['title'])
			logging.info("Added notice dated %s titled %s",
					notice['time'], notice['title'])
			pass
		else:
			continue

	print "{} notices inserted".format(count)
	logging.info("%d notices inserted", count)
	return count
Esempio n. 2
0
def insert_db():
    """
	Save the notices in Notice sqlite database
	"""
    logging.debug("called : %s", __name__)

    notices = extract.get_notice_list(False)
    if notices is None:
        logging.error("error getting notice list")
        return None

    count = 0
    for notice in notices:
        if NoticeWrapper.insert_dict_safe(notice):
            count += 1
            print "Added notice dated '{}' titled '{}'.".format(
                notice['time'], notice['title'])
            logging.info("Added notice dated %s titled %s", notice['time'],
                         notice['title'])
            pass
        else:
            continue

    print "{} notices inserted".format(count)
    logging.info("%d notices inserted", count)
    return count
def insert(root = None):
	logging.debug("called : %s", __name__)
	logging.debug("argument root : %s", root)

	if root is None:
		logging.debug("empty root is received")
		root = os.path.abspath(os.path.dirname(__file__)) + "/gen/json"
	if not os.path.isdir(root):
		logging.debug("making directory : %s", root)
		os.makedirs(root)

	notices = extract.get_notice_list(False)
	if notices is None:
		logging.error("error getting notice list")
		return None
	count = 0
	for notice in notices:
		timestamp = str(notice['timestamp'])
		path = root + '/' + timestamp + '.json'
		if os.path.isfile(path):
			continue;
		else:
			count += 1
			print "Saved notice dated '{}' titled '{}'.".format(notice['time'], notice['title'])
			logging.info("Saved notice dated %s titled %s",
					notice['time'], notice['title'])

			n = Notice(timestamp)
			n.save_json(notice)

	logging.info("%d notices inserted", count)
	return count
Esempio n. 4
0
def insert(root=None):
    logging.debug("called : %s", __name__)
    logging.debug("argument root : %s", root)

    if root is None:
        logging.debug("empty root is received")
        root = os.path.abspath(os.path.dirname(__file__)) + "/gen/json"
    if not os.path.isdir(root):
        logging.debug("making directory : %s", root)
        os.makedirs(root)

    notices = extract.get_notice_list(False)
    if notices is None:
        logging.error("error getting notice list")
        return None
    count = 0
    for notice in notices:
        timestamp = str(notice['timestamp'])
        path = root + '/' + timestamp + '.json'
        if os.path.isfile(path):
            continue
        else:
            count += 1
            print "Saved notice dated '{}' titled '{}'.".format(
                notice['time'], notice['title'])
            logging.info("Saved notice dated %s titled %s", notice['time'],
                         notice['title'])

            n = Notice(timestamp)
            n.save_json(notice)

    logging.info("%d notices inserted", count)
    return count