示例#1
0
def updateGroup(socket, sqldb, group, articles=100):
    # Only updates headers for now
    '''Update group and dump info into sql. Arguments:
	- socket: valid nntp socket (obj)
	- sqldb: valid sqlite3 location (str)
	- group: valid gropu (str)
	- articles: num articles to fetch (int)
	Returns:
	- ???'''
    _check_sock(socket)
    reach = 1000
    # Get the last article we have in the DB
    last_id = db.get_last_article(sqldb, group)
    if last_id == 0:
        # if we haven't indexed this group then go back var(reach) articles
        last_id = group_last(socket, group) - reach

    # The last article on the server
    last_article = group_last(socket, group)
    total = last_article - last_id
    if total == 0:
        return 'No articles to fetch. Up to date.'

    conn = sqlite3.connect(sqldb)
    c = conn.cursor()
    # Set the group
    socket.group(group)

    print 'Getting %s articles starting at article ID #%d in %s.' % (
        total, last_id, group)
    multiple_rows = []
    errors = 0
    startTime = datetime.now()
    resp, overviews = socket.over((str(last_id), str(last_article)))
    print 'Time to fetch articles: %s.' % (datetime.now() - startTime)
    for article_num, over in overviews:
        multiple_rows.append(
            [group, article_num, over['message-id'], over['subject']])

    print 'Grabbed all headers, inserting %d rows into DB' % (
        len(multiple_rows))
    startTime = datetime.now()
    c.executemany(
        'INSERT INTO parts (group_name, article_id, message_id, subject) VALUES (?, ?, ?, ?)',
        multiple_rows)
    print 'Time to insert articles into DB: %s.' % (datetime.now() - startTime)
    conn.commit()
    conn.close()
    return 'Server replied %d articles out of %d articles.' % (
        (total - errors), total)
示例#2
0
def groupFirst(socket, group):
    '''Get first group article number. Arguments:
	- socket: valid NNTP socket (object)
	- group: valid group name (str)
	Returns:
	- integer'''
    _check_sock(socket)
    resp, count, first, last, name = socket.group(group)
    return int(first)
示例#3
0
文件: helper.py 项目: rcconvict/usepy
def groupFirst(socket, group):
	'''Get first group article number. Arguments:
	- socket: valid NNTP socket (object)
	- group: valid group name (str)
	Returns:
	- integer'''
	_check_sock(socket)
	resp, count, first, last, name = socket.group(group)
	return int(first)
示例#4
0
文件: helper.py 项目: rcconvict/usepy
def updateGroup(socket, sqldb, group, articles=100):
	# Only updates headers for now
	'''Update group and dump info into sql. Arguments:
	- socket: valid nntp socket (obj)
	- sqldb: valid sqlite3 location (str)
	- group: valid gropu (str)
	- articles: num articles to fetch (int)
	Returns:
	- ???'''
	_check_sock(socket)
	reach = 1000
	# Get the last article we have in the DB
	last_id = db.get_last_article(sqldb, group)
	if last_id == 0:
		# if we haven't indexed this group then go back var(reach) articles
		last_id = group_last(socket, group) - reach

	# The last article on the server
	last_article = group_last(socket, group)
	total = last_article - last_id
	if total == 0:
		return 'No articles to fetch. Up to date.'

	conn = sqlite3.connect(sqldb)
	c = conn.cursor()
	# Set the group
	socket.group(group)

	print 'Getting %s articles starting at article ID #%d in %s.' % (total, last_id, group)
	multiple_rows = []
	errors = 0
	startTime = datetime.now()
	resp, overviews = socket.over((str(last_id), str(last_article)))
	print 'Time to fetch articles: %s.' % (datetime.now() - startTime)
	for article_num, over in overviews:
		multiple_rows.append([group, article_num, over['message-id'], over['subject']])
	
	print 'Grabbed all headers, inserting %d rows into DB' % (len(multiple_rows))
	startTime = datetime.now()
	c.executemany('INSERT INTO parts (group_name, article_id, message_id, subject) VALUES (?, ?, ?, ?)', multiple_rows)
	print 'Time to insert articles into DB: %s.' % (datetime.now() - startTime)
	conn.commit()
	conn.close()
	return 'Server replied %d articles out of %d articles.' % ((total - errors), total)
示例#5
0
文件: helper.py 项目: rcconvict/usepy
def groupOverview(socket, group):
	'''Process Group Overview. Arguments:
	- socket: valid NNTP socket (object)
	- group: valid group name (str)
	Returns:
	- string'''
	_check_sock(socket)
	resp, count, first, last, name = socket.group(group)
	count = "{:,}".format(int(count))
	return 'Group %s has a total of %s articles. The oldest article is %s and the newest article is %s.' % (name, count, first, last)
示例#6
0
def groupOverview(socket, group):
    '''Process Group Overview. Arguments:
	- socket: valid NNTP socket (object)
	- group: valid group name (str)
	Returns:
	- string'''
    _check_sock(socket)
    resp, count, first, last, name = socket.group(group)
    count = "{:,}".format(int(count))
    return 'Group %s has a total of %s articles. The oldest article is %s and the newest article is %s.' % (
        name, count, first, last)