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


Python NNTP.quit方法代码示例

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


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

示例1: main

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import quit [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

示例2: get_items

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import quit [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

示例3: getItems

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import quit [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

示例4: add_new_jobs

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

示例5: getItems

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

示例6: NNTPConnector

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import quit [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: NewsWatcher

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import quit [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

示例8: localtime

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import quit [as 别名]
#coding=utf-8
#
from nntplib import NNTP
from time import strftime, time, localtime

day = 24 * 60 * 60 # Number of seconds in one day
yesterday = localtime(time() - day)
date = strftime('%y%m%d', yesterday)
hour = strftime('%H%M%S', yesterday)

servername = 'news.mixmin.net'
group = 'talk.euthanasia'
server = NNTP(servername)
ids = server.newnews(group, date, hour)[1]

for id in ids:
    head = server.head(id)[3]
    for line in head:
        if line.lower().startswith('subject:'):
            subject = line[9:]
            break

    body = server.body(id)[3]
    print subject 
    print '-'*len(subject)
    print '\n'.join(body)

server.quit()
开发者ID:ruanima,项目名称:TenTinyPythonProject,代码行数:30,代码来源:newsagent1.py

示例9: NNTP

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import quit [as 别名]
    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
        if raw_input('=> Show body?') in ['y', 'Y']:
            reply, num, tid, list = connection.body(id)
            for line in list:
                print line[:80]
    print
print connection.quit( )
开发者ID:wintergalt,项目名称:canilla,代码行数:32,代码来源:code_idol.py

示例10: NNTP

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

示例11: print

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import quit [as 别名]
    groupname  = 'comp.lang.python'          # 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 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
        if input('=> Show body?') in ['y', 'Y']:
            reply, num, tid, list = connection.body(id)
            for line in list:
                print(line[:80])
    print()
print(connection.quit())
开发者ID:liubiggun,项目名称:PP4E,代码行数:32,代码来源:readnews.py

示例12:

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

示例13: DanskGruppenArchive

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import quit [as 别名]
class DanskGruppenArchive(object):
    """Class that provides an interface to Dansk-gruppens emails archive on
    gmane
    """

    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()

    def close(self):
        """Quit the NNTP session and save the cache"""
        self.nntp.quit()
        if self.cache_file:
            with open(self.cache_file, 'wb') as file_:
                pickle.dump(self.article_cache, file_)
                logging.info('Wrote %i items to cache file',
                             len(self.article_cache))

    @property
    def last(self):
        """Return the last NNTP ID as an int"""
        return self.nntp.group('gmane.comp.internationalization.dansk')[3]

    def _get_article(self, message_id):
        """Get an article (cached)

        Args:
            message_id (int): The NNTP ID of the message

        Returns:
            list: List of byte strings in the message
        """
        # Clear excess cache
        if len(self.article_cache) > self.article_cache_size:
            self.article_cache.popitem(last=False)

        # Check if article is in cache and if not, put it there
        if message_id not in self.article_cache:
            # nntp.article() returns: response, information
            # pylint: disable=unbalanced-tuple-unpacking
            _, info = self.nntp.article(message_id)
            self.article_cache[message_id] = info
        return self.article_cache[message_id]

    @staticmethod
    def _article_to_email(article):
        """Convert a raw article to an email object

        Args:
            article (namedtuple): An article named tuple as returned by NNTP

        Returns:
            email.message: An email message object
        """
        # article lines are a list of byte strings
        decoded_lines = [line.decode('ascii') for line in article.lines]
        article_string = '\n'.join(decoded_lines)
        # Make an email object
        return email.message_from_string(article_string)

    def get_subject(self, message_id):
        """Get the subject of an message

        Args:
            message_id (int): The NNTP ID of the the message

        Returns:
            str: The subject of the article
        """
        article = self._get_article(message_id)
        mail = self._article_to_email(article)
        # The subject may be encoded by NNTP, so decode it
        return decode_header(mail['Subject'])

    def get_body(self, message_id):
        """Get the body of a message

        Args:
            message_id (int): The NNTP ID of the the message

        Returns:
            str: The body of the article as a str or None if no body could be
                found or succesfully decoded
        """
        article = self._get_article(message_id)
#.........这里部分代码省略.........
开发者ID:KennethNielsen,项目名称:translation_status_page_common,代码行数:103,代码来源:archive.py

示例14: DownloadSpots

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import quit [as 别名]
class DownloadSpots(object):
    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;
        ''')

    def __del__(self):
        print 'quit!'
        if hasattr(self, 'news'):
            self.news.quit()
        if hasattr(self, 'cur'):
            self.cur.close()
        if hasattr(self, 'conn'):
            self.conn.close()

    def make_table(self):
        sql = '''\
        CREATE TABLE IF NOT EXISTS spots (
            id int PRIMARY KEY,
            full_id str,
            cat int,
            title str,
            poster str,
            date int,
            size int,
            erotiek int,
            subcats str,
            modulus int,
            keyid int,
            c_count int
        );
        
        CREATE TABLE IF NOT EXISTS comments (
            id int PRIMARY KEY,
            full_id str,
            spot_full_id str
        );
        
        CREATE INDEX IF NOT EXISTS spots_full_id_index on spots(full_id);
        '''
        self.cur.executescript(sql)
        self.conn.commit()

    def download_detail(self, id):
        '''Get information about a spot.
        
        Args:
            id (int/string): the nntp id of the spot. Can be:
                - a short id: 123456
                - a long id: '[email protected]'
        Returns:
            a dict with the following keys:
                - nzb: a list of nntp id's of the nzb file
                - image: the location of the image file: url or nntp id
                - website: url of the website
                - desc: a description of the spot
                - title2: the title of the spot
                  (is called title2 to avoid a conflict)
        '''

        id = str(id)
        self.news.group('free.pt')
        print id
        head = self.news.head(id)[-1]
        xmltext = ''.join(item[7:] for item in head if
                          item.startswith('X-XML:'))
        xml = etree.XML(xmltext)
        xmldict = defaultdict(list)

        xmldict['nzb'] = [i.text for i in xml.find('.//NZB').iter('Segment')]

        imgfind = xml.find('.//Image')
        if imgfind is not None:
            if imgfind.find('.//Segment') is not None:
                xmldict['image'] = imgfind.find('.//Segment').text
            else:
                xmldict['image'] = imgfind.text
        else:
            xmldict['image'] = None

        webfind = xml.find('.//Website')
        if webfind is not None:
            xmldict['website'] = webfind.text
        else:
            xmldict['website'] = None
#.........这里部分代码省略.........
开发者ID:BartLH,项目名称:PySpotQt,代码行数:103,代码来源:download_spots.py

示例15: identify

# 需要导入模块: from nntplib import NNTP [as 别名]
# 或者: from nntplib.NNTP import quit [as 别名]
def identify(host):
    h = NNTP(host)
    w = h.getwelcome()
    h.quit()
    return patterns.match(w)
开发者ID:bruceg,项目名称:siteinfo,代码行数:7,代码来源:nntp.py


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