Basic NNTP Server in Twisted
| ## | |
| # Basic wrapper for twisted.news | |
| # | |
| # This is a self-contained server with a hard-coded list of groups. | |
| # It requires Twisted Python and Python 2 | |
| ## | |
| from twisted.internet import reactor | |
| from twisted.news import database, news, nntp | |
| class Category: | |
| """Can have subcategories.""" | |
| def __init__(self, name='', parent=None, description=''): | |
| if parent: | |
| self.name = '.'.join((parent.name, name)) | |
| parent.children.append(self) | |
| else: | |
| self.name = name | |
| self.children = [] | |
| self.description = description | |
| def __str__(self): | |
| return self.name | |
| def to_list(self, out=[]): | |
| if not self.children: | |
| out.append(self.name) | |
| for c in self.children: | |
| c.to_list(out) | |
| return out | |
| # example of some groups: | |
| sci = Category('sci', None, 'Scientific and Research issues') | |
| for x in ['astro', 'chem', 'crypt', 'fractals', 'math']: | |
| c = Category(x, sci, 'sci.%s newsgroup' % x) | |
| GROUPS = sci.to_list() | |
| SMTP_SERVER = 'YOUR_DOMAIN.COM' | |
| STORAGE_DIR = 'storage' | |
| newsStorage = database.NewsShelf(SMTP_SERVER, STORAGE_DIR) | |
| for group in GROUPS: | |
| newsStorage.addGroup(group, []) | |
| factory = news.NNTPFactory(newsStorage) | |
| reactor.listenTCP(119, factory) | |
| reactor.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment