post.py

Testing at python.nntp.script Testing at python.nntp.script
Sun Aug 15 17:05:27 EDT 2021


Just got done writing this nice little posting script. Its my first python script ecer
so be nice lol.

#!/usr/bin/python3
import nntplib
import sys

NAME = 'testbunny'
EMAIL = 'testy at test.com'
SIG = 'Testbunny'
ORG = 'Python Pirates'
SERVER = 'nntp.aioe.org'
GROUPS = 'alt.test'

SUBJECT = input("What is the subject? ")

print("Enter/Paste your content. Ctrl-D or Ctrl-Z ( windows ) to save it.")
contents = []
while True:
    try:
        BODY = input()
        contents.append(BODY)
    except EOFError:
        break

text = '\n'.join(contents)

open('article.txt', 'w').close()

with open('article.txt', 'a') as f:
    f.write('From: ' + NAME + " <" + EMAIL + ">")
    f.write("\n")
    f.write('Subject: ' + SUBJECT)
    f.write("\n")
    f.write('Newsgroups: ' + GROUPS)
    f.write("\n")
    f.write('Organization: ' + ORG)
    f.write("\n")
    f.write('User-Agent: Python3')
    f.write("\n")
    f.write("\n")
    f.writelines(text)
    f.write("\n")
    f.write("\n")
    f.write('--')
    f.write("\n")
    f.write(SIG)
    f.write("\n")
    f.write('.')
    print("Sending article....")

s = nntplib.NNTP(SERVER)
f = open('article.txt', 'rb')
s.post(f)
print("done")
s.quit()

--
Python Test Script
.


More information about the Python-list mailing list