#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()
def getItems(self): start = localtime(time() - self.window * day) date = strftime('%y%m%d', start) hour = strftime('%H%M%S', start) full_date = date + time server = NNTP(self.servername) ids = server.newnews( self.group, datetime.datetime.strptime(full_date, '%y%m%d%H%M%S'))[1] for id in ids: lines = server.article(id)[3] message = message_from_string('\n'.join(lines)) title = message['subject'] body = message.get_payload() if message.is_multipart(): body = body[0] yield NewsItem(title, body) server.quit()
def main_func(year): nntp = NNTP('news.alaska-software.com') print(year) for month in range(1, 12): for day in range(1, 28): date = datetime.date(year, month, day) groups = nntp.newgroups(date)[1] for group in groups: try: news = nntp.newnews(group, date) except nntplib.NNTPPermanentError: continue else: print(news)
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()
def getItems(self): # 新闻生成器 yesterday = date.today() - timedelta(days=self.window) # 计算新闻获取的起始时间 server = NNTP(self.server_name) # 创建服务器连接对象 ids = server.newnews(self.group, yesterday)[1] # 获取新闻id列表 count = 0 # 创建计数变量 for id in ids: # 循环获取新闻id count += 1 # 计数递增 if count <= 10: # 如果计数小于10 article = server.article(id)[1][2] # 获取指定id的新闻文章 lines = [] # 创建每行新闻内容的列表 for line in article: # 从新闻文章中读取每一行内容 lines.append(line.decode()) # 将每行新闻内容解码,添加到新闻内容列表。 message = message_from_string('\n'.join(lines)) # 合并新闻列表内容为字符串并转为消息对象 title = message['subject'].replace('\n', '') # 从消息对象中获取标题 body = message.get_payload() # 从消息对象中获取到新闻主体内容 if message.is_multipart(): # 如果消息对象包含多个部分 body = body[0] # 获取到的内容中第1个部分获取新闻主体内容 yield NewsItem(title, body) # 生成1个新闻内容对象 else: # 如果超出10条内容 break # 跳出循环 server.quit() # 关闭连接
#!/usr/bin/python from nntplib import NNTP from time import time, localtime, strftime day = 24 * 60 * 60 yesterday = localtime(time() - day) date = strftime('%y%m%d', yesterday) t = strftime('%H%M%S', yesterday) s = NNTP('web.aioe.org') g = 'comp.lang.python.announce' ids = s.newnews(g, date, t)[1] for id in ids: head = s.head(id)[3] for line in head: if line.lower().startswith('subject:'): subject = line[9:] break body = s.body(id)[3] print subject print '-' * len(subject) print '\n'.join(body) s.quit()
logging.getLogger('').addHandler(console) day = 24 * 60 * 60 yesterday = localtime(time() - day) date = strftime('%y%m%d', yesterday) hour = strftime('%H%M%S', yesterday) servername = 'news.aioe.org' group = 'comp.lang.python' server = NNTP(servername) ids = server.newnews(group, date, hour)[1] logging.info('this is ids') logging.info(ids) for id in ids: print 'this is id', id 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)
def __str__(self): return self._file_str.getvalue() week = 7 * 24 * 60 * 60 # Number of seconds in one day start = localtime(time() - week) date = strftime('%y%m%d', start) time = strftime('%H%M%S', start) full_date = date + time servername = 'news.aioe.org' group = 'comp.lang.python.announce' server = NNTP(servername) ids = server.newnews(group, datetime.datetime.strptime(full_date, '%y%m%d%H%M%S'))[1] content = StringBuilder() content.Append(''' <html> <head> <title>Week's News - Python Announce</title> </head> <body> <h1>Week's News - Python Announce</h1> ''') content.Append(''' <ul> ''')
#!/usr/bin/env python # -*- coding: utf-8 -*- from nntplib import NNTP from time import strftime, time, localtime day = 24 * 60 * 60 # 一天的秒数 yesterday = localtime(time() - day) date = strftime('%y%m%d', yesterday) hour = strftime('%H%M%S', yesterday) servername = 'news2.neva.ru' group = 'comp.lang.python.announce' server = NNTP(servername) ids = server.newnews(group, date, hour)[1] # 获取文章的id列表 for id in ids: head = server.head(id)[3] for line in head: if line.lower().startswith('subject:'): subject = line[9:] break # 找到subject后没有必要继续 body = server.body(id)[3] print subject print '-' * len(subject) print '\n'.join(body) server.quit()