当前位置: 首页>>代码示例>>Python>>正文


Python NNTP.group方法代码示例

本文整理汇总了Python中nntplib.NNTP.group方法的典型用法代码示例。如果您正苦于以下问题:Python NNTP.group方法的具体用法?Python NNTP.group怎么用?Python NNTP.group使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nntplib.NNTP的用法示例。


在下文中一共展示了NNTP.group方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: gmane

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import group [as 别名]
 def gmane(self):
     try:
         gmane = NNTP("news.gmane.org")
     except:
         return self.gmane
     gmane.group(self.group)
     return gmane
开发者ID:collective,项目名称:mr.cabot,代码行数:9,代码来源:gmane.py

示例2: main

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import group [as 别名]
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,代码行数:13,代码来源:check_health.py

示例3: get_items

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import group [as 别名]
 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,代码行数:14,代码来源:listing23-2.py

示例4: download_group

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import group [as 别名]
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,代码行数:15,代码来源:test.py

示例5: getItems

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import group [as 别名]
	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,代码行数:17,代码来源:newsagent3.py

示例6: NNTPConnector

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import group [as 别名]
class NNTPConnector(BaseConnector):  
    @logit(log,'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,代码行数:43,代码来源:nntpconnector.py

示例7: __init__

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import group [as 别名]
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,代码行数:23,代码来源:newsgrep.py

示例8: NewsWatcher

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import group [as 别名]
class NewsWatcher(MessageWatcher):
    def __init__(self, server, groups,
                 user=None, pw=None, port=None, tag=None):
        MessageWatcher.__init__(self)
        self.server = server
        self.groups = groups
        self.nntp = None  # the NNTP connection object
        self.user = user
        self.pw = pw
        self.port = port
        self.tag = tag
        self.last = {}
        self.timeout = None
        self.pollInterval = 60
        self.debug = 0

    def __repr__(self):
        return "<NewsWatcher %s:%s (%s)>" % (self.server, self.port,
                                             ",".join(self.groups))
    def __getstate__(self):
        d = MessageWatcher.__getstate__(self)
        d['nntp'] = None # just in case
        return d

    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)

    def stop(self):
        self.nntp.quit()
        self.nntp = None
        if self.timeout:
            gtk.timeout_remove(self.timeout)
            self.timeout = None

    def doTimeout(self):
        self.poll()
        return gtk.TRUE # keep going

    def poll(self):
        #print "polling", self
        for g in self.groups:
            resp, count, first, last, name = self.nntp.group(g)
            for num in range(self.last[g]+1, int(last)+1):
                try:
                    resp, num, id, lines = self.nntp.article("%d" % num)
                except NNTPError:
                    continue
                name = "%s:%d" % (g, int(num))
                if self.debug: print "got", name
                if self.tag:
                    if not filter(lambda line, tag=tag: line.find(tag) != -1,
                                  lines):
                        continue
                self.parseMessage(name, name, time.time(), lines)
            self.last[g] = int(last)
开发者ID:barak,项目名称:mailcrypt,代码行数:69,代码来源:watcher.py

示例9: Client

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import group [as 别名]
class Client(Context):
    def __init__(self, log,
    hostname, port=None, username=None, password=None, *,
    debuglevel=None, **timeout):
        self.log = log
        self.hostname = hostname
        self.port = port
        self.username = username
        self.password = password
        self.debuglevel = debuglevel
        self.timeout = timeout
        Context.__init__(self)
        self.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()
    
    def body(self, id, *pos, **kw):
        id = "<{}>".format(id)
        retry = 0
        while True:
            try:
                with self.handle_abort():
                    self.nntp.body(id, *pos, **kw)
                break
            except failure_responses as err:
                [code, *msg] = err.response.split(maxsplit=1)
                if code == "400":
                    [msg] = msg or (None,)
                    if not msg:
                        msg = "Server shut down connection"
                elif code[1] == "0" and not retry:
                    msg = err.response
                else:
                    raise
            self.log.write(msg + "\n")
            self.log_time()
            if retry >= 60:
                raise TimeoutError()
            self.close()
            time.sleep(retry)
            if not retry:
                start = time.monotonic()
            self.connect()
            if retry:
                retry *= 2
            else:
                retry = time.monotonic() - start
                if retry <= 0:
                    retry = 0.5
    
    def group(self, *pos, **kw):
        with self.handle_abort():
            return self.nntp.group(*pos, **kw)
    def over(self, *pos, **kw):
        with self.handle_abort():
            return self.nntp.over(*pos, **kw)
    def hdr(self, *pos, **kw):
        with self.handle_abort():
            return self.nntp.xhdr(*pos, **kw)
    
    @contextmanager
    def handle_abort(self):
        try:
            yield
        except failure_responses:
            raise  # NNTP connection still intact
        except:
            # Protocol is disrupted so abort the connection straight away
            self.close()
            raise
    
    def close(self):
        if not self.nntp:
            return
        
        # Ignore failure of inappropriate QUIT command
        with suppress(NNTPError), self.nntp:
            pass
        self.nntp = None
    
#.........这里部分代码省略.........
开发者ID:vadmium,项目名称:usenet-downloader,代码行数:103,代码来源:nntp.py

示例10: int

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import group [as 别名]
listonly = 0
showhdrs = ['From', 'Subject', 'Date', 'Newsgroups', 'Lines']
try:
    import sys
    servername, groupname, showcount = sys.argv[1:]
    showcount  = int(showcount)
except:
    servername = 'news.gmane.org'
    groupname  = 'gmane.comp.python.general'          # cmd line args or defaults
    showcount  = 10                          # show last showcount posts

# connect to nntp server
print 'Connecting to', servername, 'for', groupname
from nntplib import NNTP
connection = NNTP(servername)
(reply, count, first, last, name) = connection.group(groupname)
print '%s has %s articles: %s-%s' % (name, count, first, last)

# get request headers only
fetchfrom = str(int(last) - (showcount-1))
(reply, subjects) = connection.xhdr('subject', (fetchfrom + '-' + last))

# show headers, get message hdr+body
for (id, subj) in subjects:                  # [-showcount:] if fetch all hdrs
    print 'Article %s [%s]' % (id, subj)
    if not listonly and raw_input('=> Display?') in ['y', 'Y']:
        reply, num, tid, list = connection.head(id)
        for line in list:
            for prefix in showhdrs:
                if line[:len(prefix)] == prefix:
                    print line[:80]; break
开发者ID:wintergalt,项目名称:canilla,代码行数:33,代码来源:code_idol.py

示例11: localtime

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import group [as 别名]
from nntplib import NNTP
from time import strftime,time,localtime
day = 24*60*60
window = 7
yesterday = localtime(time()-window*day)
date = strftime('%y%m%d',yesterday)
time = strftime('%H%M%S',yesterday)

servername = 'news.gmane.org'
# 18289
groupname = 'gmane.comp.python.apple'
s = NNTP(servername)

# group
'Return a tuple (response, count, first, last, name) where count is the (estimated) number of articles in the group, first is the first article number in the group, last is the last article number in the group, and name is the group name. The numbers are returned as strings.'
resp,count,first,last,name = s.group(groupname)
print('Group', name, 'has', count, 'articles, range', first, 'to', last)

# over
'Return a pair (response, overviews). overviews is a list of (article_number, overview) tuples, one for each article selected by message_spec'
resp,overviews = s.over((last-1,last))
for num,over in overviews:
	print(num)# 1-100
	#print(over)
	# print(over.keys())
	# ['xref', 'from', ':lines', ':bytes', 'references', 'date', 'message-id', 'subject']
	print(over.get('date'))
	print(nntplib.decode_header(over.get('from')))
	print(over.get('message-id'))
	print(over.get('subject'))
开发者ID:justasabc,项目名称:python_tutorials,代码行数:32,代码来源:newsagent.py

示例12: NNTP

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import group [as 别名]
#!/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,代码行数:28,代码来源:nntp_client.py

示例13: strftime

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import group [as 别名]
import textwrap
import re

# print strftime('%y%m%d')
# start = localtime(time()-60*60*24*365)
# print strftime('%y%m%d',start)

class SimpleWebSource:

    def __init__(self, url, titlePattern, bodyPattern):
        self.url = url
        self.titlePattern = re.compile(titlePattern)
        self.bodyPattern = re.compile(bodyPattern)

    def getItems(self):
        text = urlopen(self.url).read()
        titles = self.titlePattern.findall(text)
        bodies = self.bodyPattern.findall(text)
        for title in titles:
            print title[1].decode('utf-8')
        print bodies

bbc_url = 'http://news.sina.com.cn'
bbc_title = r'<a target="_blank" href="(.*?)">(.*?)</a>'
bbc_body = r'(?s)</a>\s*<br />\s*(.*?)\s*<'
# bbc = SimpleWebSource(bbc_url,bbc_title,bbc_body)
# bbc.getItems()

server = NNTP('129.69.1.59')
server.group('camp.lang.python')[0]
开发者ID:JamesPei,项目名称:PythonProjects,代码行数:32,代码来源:utilTest.py

示例14: NNTP

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import group [as 别名]
import sqlite3
from nntplib import NNTP

group = 'alt.binaries.movies.x264'
chunk_size = 100000
sql = sqlite3.connect('usenet.db')

print "About to start dumping articles from " + group
serv = NNTP('news.astraweb.com', 119, 'arealmuto', 'stock1114')

resp = serv.group(group)
count = int(resp[1])
first = int(resp[2])
last = int(resp[3])

print "There are " + str(count) + " articles to get"
print "First: " + str(first)
print "Last: " + str(last)
print "Using chunks size of: " + str(chunk_size)
print "It should take " + str(count/chunk_size) + " requests to finish"

id = int(first)

i = 0
master_list = []
while id < last:
	print str(i) +": Getting id's " + str(id) + " - " + str(id + chunk_size)
	resp, list = serv.xover(str(id), str(id+ chunk_size))
	print "Done fetching"
	print "Adding to master list"
	for line in list:
开发者ID:rrealmuto,项目名称:usenet,代码行数:33,代码来源:dump.py

示例15: NNTP

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import group [as 别名]

from nntplib import NNTP

server = NNTP('news2.neva.ru')
print server.group('alt.sex.telephone')
开发者ID:baocaixiong,项目名称:learnPy,代码行数:7,代码来源:test.py


注:本文中的nntplib.NNTP.group方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。