def send_name(filename):
	'''Send the notification for the notice of given json filename'''
	logging.debug("called : %s", __name__)
	logging.debug("argument filename : %s", filename)

	if filename is None:
		logging.error("empty filename received")
		return

	n = Notice(filename)
	notice = n.get_json()

	# If the notice is not updated, update it.
	logging.debug("checking if notice is updated")
	if not notice['updated']:
		update.update_json(filename)
		notice = n.get_json()

	# If the notice is not sent, send it.
	logging.debug("checking if notice is sent")
	if not notice['sent']:
		if send_json(notice):
			# If notice is sent, save it locally. So that it is not
			# sent again.
			logging.debug("notice is sent - saving it locally")
			notice['sent'] = True
			n.save_json(notice)
			return True
		else:
			logging.error("failed sending notice")
			return False
	else:
		logging.debug("notice is already sent")
		return False
Example #2
0
def send_name(filename):
    '''Send the notification for the notice of given json filename'''
    logging.debug("called : %s", __name__)
    logging.debug("argument filename : %s", filename)

    if filename is None:
        logging.error("empty filename received")
        return

    n = Notice(filename)
    notice = n.get_json()

    # If the notice is not updated, update it.
    logging.debug("checking if notice is updated")
    if not notice['updated']:
        update.update_json(filename)
        notice = n.get_json()

    # If the notice is not sent, send it.
    logging.debug("checking if notice is sent")
    if not notice['sent']:
        if send_json(notice):
            # If notice is sent, save it locally. So that it is not
            # sent again.
            logging.debug("notice is sent - saving it locally")
            notice['sent'] = True
            n.save_json(notice)
            return True
        else:
            logging.error("failed sending notice")
            return False
    else:
        logging.debug("notice is already sent")
        return False
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
Example #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
def sent_false():
	logging.debug('called : sent_false')
	root = os.path.abspath(os.path.dirname(__file__))
	path = root + '/gen/json/'
	listfile = os.listdir(path)
	if 'old' in listfile:
		listfile.remove('old')
	for fl in listfile:
		n = Notice(fl)
		notice = n.get_json()
		if not notice['sent']:
			notice['sent'] = True
			n.save_json(notice)
Example #6
0
def update_json(name):
    logging.debug("called : %s", __name__)
    logging.debug("argument name : %s", name)

    path = jsondir + name
    if not os.path.isfile(path):
        logging.error("json file '%s' is not present.", path)
        return

    n = Notice(name)
    notice = n.get_json()

    # If the json is erroneous, i.e, has empty fields like topic etc, start
    # fresh by removing the json file. This way the json will be reloaded at
    # next cron update.
    if erroneous_json(notice):
        logging.error("Encountered errnoneous json %s. Deleting.", str(path))
        os.remove(path)
        return False

    # If notice is updated, do not update it once more.
    if notice['updated']:
        logging.info("notice %s is already updated", name)
        return False

    details = get_details_url(notice['url'], notice['num_attachments'] == 1)

    logging.debug(
        "Notice has been updated with information from the notice	page")
    notice['updated'] = True
    notice['text'] = details['text']
    if notice['num_attachments'] == 1:
        notice['attachments'] = details['attachments']
        notice['num_attachments'] = len(details['attachments'])

    logging.debug('Saving the updated notice')
    n.save_json(notice)

    return True
def update_json(name):
    logging.debug("called : %s", __name__)
    logging.debug("argument name : %s", name)

    path = jsondir + name
    if not os.path.isfile(path):
        logging.error("json file '%s' is not present.", path)
        return

    n = Notice(name)
    notice = n.get_json()

    # If the json is erroneous, i.e, has empty fields like topic etc, start
    # fresh by removing the json file. This way the json will be reloaded at
    # next cron update.
    if erroneous_json(notice):
        logging.error("Encountered errnoneous json %s. Deleting.", str(path))
        os.remove(path)
        return False

        # If notice is updated, do not update it once more.
    if notice["updated"]:
        logging.info("notice %s is already updated", name)
        return False

    details = get_details_url(notice["url"], notice["num_attachments"] == 1)

    logging.debug("Notice has been updated with information from the notice	page")
    notice["updated"] = True
    notice["text"] = details["text"]
    if notice["num_attachments"] == 1:
        notice["attachments"] = details["attachments"]
        notice["num_attachments"] = len(details["attachments"])

    logging.debug("Saving the updated notice")
    n.save_json(notice)

    return True