Exemplo n.º 1
0
def run_db():
    # Login and save the html file to gen
    logging.info('Login and saving notice board html to gen')
    tpo = TpoSession()
    tpo.login()

    NoticeWrapper.init_db()

    # From the html file, extract and save the notices
    logging.info('Saving the notices to database.')
    num = insert.insert_db()
    if num is None:
        logging.error("Error encountered during extraction. Exiting.")
        exit()
    logging.info("Inserted %d notices.", num)

    # Update the json files to include the notice details and attachments
    logging.info('Updating json files')
    update.update_db()

    # Send the unsent notices
    logging.info('Sending unsent notices.')
    send.send_unsent_db()

    NoticeWrapper.deinit_db()

    logging.info("Finished running script.")
Exemplo n.º 2
0
def run_db():
	# Login and save the html file to gen
	logging.info('Login and saving notice board html to gen')
	tpo = TpoSession()
	tpo.login()

	NoticeWrapper.init_db()

	# From the html file, extract and save the notices
	logging.info('Saving the notices to database.')
	num = insert.insert_db()
	if num is None:
		logging.error("Error encountered during extraction. Exiting.")
		exit()
	logging.info("Inserted %d notices.", num)

	# Update the json files to include the notice details and attachments
	logging.info('Updating json files')
	update.update_db()

	# Send the unsent notices
	logging.info('Sending unsent notices.')
	send.send_unsent_db()

	NoticeWrapper.deinit_db()

	logging.info("Finished running script.")
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
Exemplo n.º 4
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
Exemplo n.º 5
0
def view_db(num=25):
	"""
	Print all the notices present in the Notice database.
	"""
	logging.debug("called : %s", __name__)
	notices = NoticeWrapper.get_last(num)
	for notice in notices:
		print "="*80
		print get_text_notice(notice)
		print "="*80
Exemplo n.º 6
0
def view_db(num=25):
    """
	Print all the notices present in the Notice database.
	"""
    logging.debug("called : %s", __name__)
    notices = NoticeWrapper.get_last(num)
    for notice in notices:
        print "=" * 80
        print get_text_notice(notice)
        print "=" * 80
Exemplo n.º 7
0
def send_unsent_db():
    """
	Send notification for all the unsent notices from the database
	"""
    notices = NoticeWrapper.get_unsent()

    send_count = 0
    for notice in notices:
        if send_notice(notice):
            NoticeWrapper.sent(notice)
            send_count += 1
            tprint("\r{} notifications sent.".format(send_count))

    if send_count == 0:
        tprint("0 notifications sent.")
    else:
        print ""

    logging.info("%d notifications sent", send_count)
    return send_count
Exemplo n.º 8
0
def send_unsent_db():
	"""
	Send notification for all the unsent notices from the database
	"""
	notices = NoticeWrapper.get_unsent()

	send_count = 0
	for notice in notices:
		if send_notice(notice):
			NoticeWrapper.sent(notice)
			send_count += 1
			print "\r%d notifications sent."%send_count

	if send_count == 0:
		print "0 notifications sent."
	else:
		print ""

	logging.info("%d notifications sent", send_count)
	return send_count
def update_db():
    """
	Perform an update operation for all unupdated notices in the database
	"""
    logging.debug("called : %s", __name__)

    logging.info("Updating notices")
    notices = NoticeWrapper.get_unupdated()

    count = 0
    for notice in notices:
        url = notice.url
        attach = notice.num_attachments == 1

        details = get_details_url(url, attach)

        NoticeWrapper.update(notice, details)
        count += 1
        print "Updated notice dated {} titled {}.".format(notice.print_time, notice.title)
        logging.info("Updated notice dated %s titled %s.", notice.print_time, notice.title)
    print "{} notices updated.".format(count)
    logging.info("%d notices updated.", count)
Exemplo n.º 10
0
def update_db():
    """
	Perform an update operation for all unupdated notices in the database
	"""
    logging.debug("called : %s", __name__)

    logging.info('Updating notices')
    notices = NoticeWrapper.get_unupdated()

    count = 0
    for notice in notices:
        url = notice.url
        attach = (notice.num_attachments == 1)

        details = get_details_url(url, attach)

        NoticeWrapper.update(notice, details)
        count += 1
        tprint("Updated notice dated {} titled {}.".format(
            notice.print_time, notice.title))
        logging.info('Updated notice dated %s titled %s.', notice.print_time,
                     notice.title)
    tprint("{} notices updated.".format(count))
    logging.info('%d notices updated.', count)