本文整理汇总了Python中nntplib.NNTP类的典型用法代码示例。如果您正苦于以下问题:Python NNTP类的具体用法?Python NNTP怎么用?Python NNTP使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了NNTP类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: gmane
def gmane(self):
try:
gmane = NNTP("news.gmane.org")
except:
return self.gmane
gmane.group(self.group)
return gmane
开发者ID:collective,项目名称:mr.cabot,代码行数:7,代码来源:gmane.py
示例2: download_group
def download_group(name):
if not os.path.exists(name):
os.mkdir(name)
s = NNTP('news.gmane.org')
resp, count, first, last, name = s.group(name)
print 'Group', name, 'has', count, 'articles, range', first, 'to', last
resp, subs = s.xhdr('subject', first + '-' + last)
for id, sub in subs:
print id
with open(os.path.join(name, str(id)), 'wb') as fp:
pprint.pprint(s.article(id), stream=fp)
开发者ID:zopyx,项目名称:plone-social-analytics,代码行数:13,代码来源:test.py
示例3: __init__
def __init__(self, group, server):
self.conn = NNTP(server)
resp, count, first, last, name = self.conn.group(group)
self.group = group
self.server = server
self.first = int(first)
self.last = int(last)
开发者ID:ConradIrwin,项目名称:git-fetch-series,代码行数:8,代码来源:git-fetch-series.py
示例4: add_new_jobs
def add_new_jobs(group_name):
db = Connection().usenet
max_h = db.control.find({"group": group_name}).sort('end', DESCENDING).limit(1)[0]['end'] + 1
if not max_h: max_h = 0
news = NNTP('eu.news.astraweb.com', user='vasc', password='dZeZlO89hY6F')
group = dict_group(news, group_name)
news.quit()
i = max(group['first'], max_h)
if max_h > group['last']: return
while(i+100000 < group['last']):
db.control.insert({'init': i, 'end': i+99999, 'done':False, "group": group_name})
i += 100000
db.control.insert({'init': i, 'end': group['last'], 'done':False, "group": group_name})
开发者ID:vasc,项目名称:couchee,代码行数:17,代码来源:headers.py
示例5: getItems
def getItems(self):
start = localtime(time()-self.window*day)
date = strftime('%y%m%d',start)
hour = strftime('%H%M%S',start)
server = NNTP(self.servername)
ids = server.newnews(self.group,date,hour)[1]
for id in ids:
lines = server.article(id)[3]
message = message_from_string('\n'.join(lines))
title = memssage['subject']
body = message.get_payload()
if message.is_multipart():
body = body[0]
yield NewsItem(title,body)
server.quit()
开发者ID:jjyy4sun,项目名称:pTest1,代码行数:18,代码来源:newsagent.py
示例6: __init__
class NewsGrep:
def __init__(self,server,username,password):
self.server = NNTP(server, 119,username,password)
def __del__(self):
pass
def __str__(self):
pass
def list(self):
resp, groups = self.server.list()
for group, last, first, flag in groups:
print group
def ls(self,group_name):
resp, count, first, last, name = self.server.group(group_name)
print 'Group', name, 'has', count, 'articles, range', first, 'to', last
resp, subs = self.server.xhdr('subject', first + '-' + last)
for id, sub in subs[-10:]:
print id, sub
开发者ID:astrangeguy,项目名称:zendump,代码行数:21,代码来源:newsgrep.py
示例7: start
def start(self):
port = self.port
if not port:
port = NNTP_PORT
self.nntp = NNTP(self.server, port, self.user, self.pw,
readermode=1)
# only look for messages that appear after we start. Usenet is big.
if not self.last: # only do this the first time
for g in self.groups:
resp, count, first, last, name = self.nntp.group(g)
self.last[g] = int(last)
if self.debug: print "last[%s]: %d" % (g, self.last[g])
self.timeout = gtk.timeout_add(self.pollInterval*1000,
self.doTimeout)
开发者ID:barak,项目名称:mailcrypt,代码行数:14,代码来源:watcher.py
示例8: main
def main():
s = NNTP(settings.nntp_hostname, settings.nntp_port)
resp, groups = s.list()
# check all of the groups, just in case
for group_name, last, first, flag in groups:
resp, count, first, last, name = s.group(group_name)
print "\nGroup", group_name, 'has', count, 'articles, range', first, 'to', last
resp, subs = s.xhdr('subject', first + '-' + last)
for id, sub in subs[-10:]:
print id, sub
s.quit()
开发者ID:jgrassler,项目名称:papercut,代码行数:11,代码来源:check_health.py
示例9: main
def main():
tree = {}
# Check that the output directory exists
checkopdir(pagedir)
try:
print 'Connecting to %s...' % newshost
if sys.version[0] == '0':
s = NNTP.init(newshost)
else:
s = NNTP(newshost)
connected = True
except (nntplib.error_temp, nntplib.error_perm), x:
print 'Error connecting to host:', x
print 'I\'ll try to use just the local list.'
connected = False
开发者ID:AbnerChang,项目名称:edk2-staging,代码行数:17,代码来源:newslist.py
示例10: get_items
def get_items(self):
server = NNTP(self.servername)
resp, count, first, last, name = server.group(self.group)
start = last - self.howmany + 1
resp, overviews = server.over((start, last))
for id, over in overviews:
title = decode_header(over['subject'])
resp, info = server.body(id)
body = '\n'.join(line.decode('latin')
for line in info.lines) + '\n\n'
yield NewsItem(title, body)
server.quit()
开发者ID:BrandonSherlocking,项目名称:beginning-python-3ed,代码行数:12,代码来源:listing23-2.py
示例11: __init__
def __init__(self, article_cache_size=300, cache_file=None):
"""Initialize local variables"""
# Connect to news.gmane.org
self.nntp = NNTP('news.gmane.org')
# Setting the group returns information, which right now we ignore
self.nntp.group('gmane.comp.internationalization.dansk')
# Keep a local cache in an OrderedDict, transferred across session
# in a pickled version in a file
self.article_cache_size = article_cache_size
self.cache_file = cache_file
if cache_file and path.isfile(cache_file):
with open(cache_file, 'rb') as file_:
self.article_cache = pickle.load(file_)
logging.info('Loaded %i items from file cache',
len(self.article_cache))
else:
self.article_cache = OrderedDict()
开发者ID:KennethNielsen,项目名称:translation_status_page_common,代码行数:18,代码来源:archive.py
示例12: __init__
def __init__(self):
try:
self.news = NNTP(NEWS_SERVER, NNTP_PORT, NNTP_USERNAME,
NNTP_PASSWORD)
except NNTPTemporaryError as e:
raise SpotError('NNTP', e)
except socket.error as e:
raise SpotError('Connection', e)
self.conn = sqlite3.connect(NEWS_SERVER + '.db')
self.conn.row_factory = sqlite3.Row
self.cur = self.conn.cursor()
self.cur.executescript('''\
PRAGMA synchronous = OFF;
PRAGMA journal_mode = MEMORY;
PRAGMA temp_store = MEMORY;
PRAGMA count_changes = OFF;
''')
开发者ID:BartLH,项目名称:PySpotQt,代码行数:19,代码来源:download_spots.py
示例13: getItems
def getItems(self):
# yesterday = localtime(time()-self.window*day)
# date = strftime('%y%m%d',yesterday)
# time = strftime('%H%M%S',yesterday)
# create a nntp server
s = NNTP(self.servername)
resp,count,first,last,name = s.group(self.groupname)
resp,overviews = s.over((last-1,last))
for num,over in overviews:
title = over.get('subject')
resp,body = s.body(num)
# create a generator to iterate news
if title and body:
yield NewsItem(title,body)
s.quit()
开发者ID:justasabc,项目名称:python_tutorials,代码行数:15,代码来源:newsagent3.py
示例14: connect
def connect(self):
address = net.format_addr((self.hostname, self.port))
self.log.write("Connecting to {}\n".format(address))
if self.port is None:
port = ()
else:
port = (self.port,)
self.connect_time = time.monotonic()
self.nntp = NNTP(self.hostname, *port, **self.timeout)
with ExitStack() as cleanup:
cleanup.push(self)
if self.debuglevel is not None:
self.nntp.set_debuglevel(self.debuglevel)
self.log.write("{}\n".format(self.nntp.getwelcome()))
if self.username is not None:
self.log.write("Logging in as {}\n".format(self.username))
with self.handle_abort():
self.nntp.login(self.username, self.password)
self.log.write("Logged in\n")
cleanup.pop_all()
开发者ID:vadmium,项目名称:usenet-downloader,代码行数:21,代码来源:nntp.py
示例15: fetch
def fetch(self):
"""
Fetches all the messages for a given news group uri and return Fetched staus depending
on the success and faliure of the task
"""
try:
#eg. self.currenturi = nntp://msnews.microsoft.com/microsoft.public.exchange.setup
#nntp_server = 'msnews.microsoft.com'
#nntp_group = 'microsoft.public.exchange.setup'
self.genre = 'review'
try:
nntp_server = urlparse(self.currenturi)[1]
except:
log.exception(self.log_msg("Exception occured while connecting to NNTP server %s"%self.currenturi))
return False
nntp_group = urlparse(self.currenturi)[2][1:]
self.server = NNTP(nntp_server)
try:
self.__updateParentSessionInfo()
resp, count, first, last, name = self.server.group(nntp_group)
last_id = int(last)
first_id = self.__getMaxCrawledId(last_id)+1
log.debug("first_id is %d:"%first_id)
log.debug("last_id is %d:"%last_id)
if last_id >= first_id:
resp, items = self.server.xover(str(first_id), str(last_id))
log.debug(self.log_msg("length of items:%s"%str(len(items))))
for self.id, self.subject, self.author, self.date, self.message_id,\
self.references, size, lines in items:
self.__getMessages(self.task.instance_data['uri'])
self.server.quit()
return True
except:
log.exception(self.log_msg("Exception occured in fetch()"))
self.server.quit()
return False
except Exception,e:
log.exception(self.log_msg("Exception occured in fetch()"))
return False
开发者ID:jsyadav,项目名称:CrawlerFramework,代码行数:39,代码来源:nntpconnector.py
示例16: NNTP
#! /usr/bin/python
from sys import stdin
from nntplib import NNTP
from os import environ
s = NNTP(environ["NNTPSERVER"])
s.post(stdin)
s.quit()
开发者ID:jautero,项目名称:post-sao-faq,代码行数:9,代码来源:inews.py
示例17: len
args = sys.argv
if len(args) == 2:
print "Resetting lastread and seen.."
resetLastread()
exit
seen = []
newdate = None
print "Reading date and seen files"
date,seen = loadLastread()
for serverentry in servers:
server = serverentry[0]
newsgroups = serverentry[2]
print "Connecting to: " + server
s = NNTP(server)
for newsgroup in newsgroups:
feedGroup(server, newsgroup, date, seen)
serverdate = s.date()
date = serverdate[1]
time = serverdate[2]
year = 2000 + int(serverdate[1][0:2]) ## So I got a Y3K problem here. Deal.
month = int(serverdate[1][2:4])
day = int(serverdate[1][4:])
hour = int(serverdate[2][0:2])
minute = int(serverdate[2][2:4])
second = int(serverdate[2][4:])
newdate = datetime.datetime(year,month,day,hour,minute,second)
print "Server time is " + str(newdate)
开发者ID:alekhin0w,项目名称:Pyffle-BBS,代码行数:31,代码来源:nntp.py
示例18: Archive
class Archive(object):
@staticmethod
def is_diff(body):
return bool([line for line in body if line.startswith("diff ")])
def __init__(self, group, server):
self.conn = NNTP(server)
resp, count, first, last, name = self.conn.group(group)
self.group = group
self.server = server
self.first = int(first)
self.last = int(last)
def get_number_from_user(self, msg_id):
"""
Convert something the user might input into a message id.
These are:
# An NNTP message number
# A gmane link that includes the NNTP message number
# The original Message-Id header of the message.
NOTE: gmane's doesn't include the message number in STAT requests
that involve only the Message-Id (hence the convolution of getting
all the headers).
"""
msg_id = re.sub(r".*gmane.org/gmane.comp.version-control.git/([0-9]+).*", r"\1", str(msg_id))
_, n, id, result = self.conn.head(msg_id)
for header in result:
m = re.match(r"Xref: .*:([0-9]+)\s*$", header, re.I)
if m:
return int(m.group(1))
else:
raise FatalError("No (or bad) Xref header for message '%s'" % msg_id)
def get_patch_series(self, user_input, search_limit=100):
"""
Given an NNTP message number or a Message-Id header return
an mbox containing the patches introduced by the author of that message.
This handles the case where the threading is right *and* the patches
are numbered in a simple scheme:
[PATCH] this patch has no replies and stands on its own
[PATCH 0/2] this is an introduction to the series
|- [PATCH 1/2] the first commit
|- [PATCH 2/2] the second commit
[PATCH 1/3] this is the first commit
|- [PATCH 2/3] and this is the second
|- [PATCH 3/3] and this is the third
TODO: it would be nice to make the search more efficient, we can
use the numbers in [PATCH <foo>/<bar>] to stop early.
"""
start_id = self.get_number_from_user(user_input)
messages = limit(self.messages_starting_from(start_id), search_limit)
try:
thread = Thread(messages.next())
except StopIteration:
raise FatalError("No message at id '%s' using XOVER")
n_since_last = 0
for message in messages:
if n_since_last > 5:
break
elif thread.should_include(message):
n_since_last = 0
thread.append(message)
else:
n_since_last += 1
else:
raise FatalError('did not find end of series within %s messages', search_limit)
for message in self.xover(start_id - 5, start_id -1):
if thread.should_include(message):
thread.append(message)
return self.mboxify(thread)
def mboxify(self, thread):
"""
Convert a thread into an mbox for application via git-am.
"""
lines = []
for message in thread.in_order():
_, number, msg_id, body = self.conn.body(str(message.number))
# git-am doesn't like empty patches very much, and the 0/X'th patch is
# often not a patch, we skip it here. (TODO, warn the user about this)
#.........这里部分代码省略.........
开发者ID:ConradIrwin,项目名称:git-fetch-series,代码行数:101,代码来源:git-fetch-series.py
示例19: NNTP
#!/usr/bin/env python
# -*- coding: UTF-8 *-*
from nntplib import NNTP
n = NNTP('your.nntp.server')
rsp, ct, fst, lst, grp = n.group('comp.lang.python')
rsp, anum, mid, data = n.article('110457')
for eachLine in data:
print eachLine
From: "Alex Martelli" <[email protected]> Subject: Re: Rounding Question
Date: Wed, 21 Feb 2001 17:05:36 +0100
"Remco Gerlich" <[email protected]> wrote:
Jacob Kaplan-Moss <[email protected]> wrote in comp.lang.python:
So I've got a number between 40 and 130 that I want to round up to
the nearest 10. That is:
40 --> 40, 41 --> 50, ..., 49 --> 50, 50 --> 50, 51 --> 60
Rounding like this is the same as adding 5 to the number and then
rounding down. Rounding down is substracting the remainder if you were
to divide by 10, for which we use the % operator in Python.
This will work if you use +9 in each case rather than +5 (note that he doesn't
really want rounding -- he wants 41 to 'round' to 50, for ex).
Alex
>>> n.quit()
'205 closing connection - goodbye!'
开发者ID:warscain,项目名称:sa,代码行数:26,代码来源:nntp_client.py
示例20: NNTP
from nntplib import NNTP
servername = 'news.foo.bar'
group = 'comp.lang.python.announce'
server = NNTP(servername)
howmany = 10
resp, count, first, last, name = server.group(group)
start = last - howmany + 1
resp, overviews = server.over((start, last))
for id, over in overviews:
subject = over['subject']
resp, info = server.body(id)
print(subject)
print('-' * len(subject))
for line in info.lines:
print(line.decode('latin1'))
print()
server.quit()
开发者ID:BrandonSherlocking,项目名称:beginning-python-3ed,代码行数:23,代码来源:listing23-1.py
注:本文中的nntplib.NNTP类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论