Beispiel #1
0
def use_NNTP():
    for server in NNTP_server_list:
        print server
    server = raw_input('Which NNTP_server do you want to go?\n')
    while True:
        if server not in NNTP_server_list:
            print 'invalid srever name,try again!'
            server = raw_input()
        else:
            break
    s = NNTP(server)
    print "s = NNTP('news.newsfan.net') is OK!"
    (resp, lst) = s.list()
    while True:
        for i, elem in enumerate(lst):
            print i, elem[0].decode('gbk')
        num = raw_input('Which group do you want to go?\n')
        try:
            rsp, ct, first, last, grp = s.group(lst[int(num)][0])
            print "Article's range is:%s to %s." % (first, last)
            (resp, subs) = s.xhdr('subject', (str(first) + '-' + str(last)))
        except:
            print format_exc()
            print 'invalid input!try again!!!'
            sleep(3)
            continue
        for subject in subs:
            try:
                print subject[0], subject[1].decode('gbk')
            except:
                print subject[0], subject[1]
        while True:
            try:
                number = raw_input('Which article do you want to read?\n')
                if number == 'q':
                    break
                f = open("NNTPfile", 'w')
                (reply, num, id, list) = s.body(str(number), f)
                f = open("NNTPfile", 'r')
                for eachLine in f:
                    try:
                        print eachLine.decode('gbk'),
                    except:
                        print eachLine
                f.close()
                print 'Press any to continue...(Press q to return...)'
                if raw_input() == 'q':
                    break
            except:
                print format_exc()
                print 'invalid input!try again!!!'
                sleep(3)
    s.quit()
    return
Beispiel #2
0
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()
Beispiel #3
0
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()
Beispiel #4
0
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
Beispiel #5
0
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
Beispiel #6
0
#s = NNTP('freenews.netfront.net', readermode=True)
s = NNTP('blaine.gmane.org', readermode=True)
#s = NNTP('news2.informatik.uni-stuttgart.de', readermode=True) - does not return groups
print "Opened connection to news server"

# Read pre-existing group list if available
if os.path.isfile('groups.txt'):
    french_groups = []
    with open('groups.txt') as f:
        for line in f:
            french_groups.append(line[:-1])
    print "- read " + str(len(french_groups)) + " French groups from file"
# Otherwise create from server
else: 
    # Read group list
    groups = s.list()
    print "- there are " + str(len(groups[1])) + " groups in total"

    # Create empty list for French groups
    french_groups = []

    # Find French groups
    for group in groups[1]:
        currgroup = group[0]
        #if currgroup[0:2] == 'fr':
        if 'french' in currgroup:
            french_groups.append(group[0])
    print "- there are " + str(len(french_groups)) + " groups in French"

    # Save French groups
    with open('groups.txt', 'w') as f:
Beispiel #7
0
#!/usr/bin/env python
# Copyright (c) 2004 Joao Prado Maia. See the LICENSE file for more information.
# $Id: check_health.py,v 1.1 2004-01-25 06:10:33 jpm Exp $

import settings
from nntplib import NNTP

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