473,414 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Random news downloader (first script!)

Kim
Random image downloader for specified newsgroup. Hi I'm writing a small script that will download random images from a specified newsgroup. I've imported yenc into the script but I can't open the image or save it. This is my first script so be gentle!

Heres the script
####random group downloader####
import nntplib
import string, random
import mimetools
import StringIO
import rfc822
import sys, base64
import os
import email
import errno
import mimetypes
SERVER = "news.server.co.uk" #Insert news server here
GROUP = "alt.binaries.pictures.blah" #newsgroup will go here

# connect to server
server = nntplib.NNTP(SERVER)

resp, count, first, last, name = server.group(GROUP)

for i in range(10):
try:
id = random.randint(int(first), int(last))
resp, id, message_id, text = server.article(str(id))
except (nntplib.error_temp, nntplib.error_perm):
pass # no such message (maybe it was deleted?)
else:
break # found a message!
else:
raise SystemExit

text = string.join(text, "\n")
file = StringIO.StringIO(text)

msg = mimetools.Message(file)

#display message information
#print "File type", "=>", msg.gettype()
#print "Encoding", "=>", msg.getencoding()
#print "plist", "=>", msg.getplist()

message = rfc822.Message(file)

for k, v in message.items():
print k, "=", v

file = message.fp.read()

def yenc_decode(file):
# <i>find body</i>
while 1:
line = file.readline()
if not line:
return None
if line[:7] == "=ybegin":
break
# <i>extract data</i>
buffer = []
while 1:
line = file.readline()
if not line or line[:5] == "=yend":
break
if line[-2:] == "\r\n":
line = line[:-2]
elif line[-1:] in "\r\n":
line = line[:-1]
data = string.split(line, "=")
buffer.append(string.translate(data[0], yenc42))
for data in data[1:]:
data = string.translate(data, yenc42)
buffer.append(string.translate(data[0], yenc64))
buffer.append(data[1:])
return buffer
#the following should write to a text file
#inp = ("file","r")
#outp = open("text.txt","w")
#for line in file:
#outp.write(line)
#print file
#outp.close()

--------------= Posted using GrabIt =----------------
------= Binary Usenet downloading made easy =---------
-= Get GrabIt for free from http://www.shemes.com/ =-
Sep 7 '06 #1
0 1502

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: loic_e_bertrand | last post by:
Hi, I created an HTML page with the following code: <html> <body> <form action="everif.php" method="post"> Name: <input type="text" name="name" size="12"><br> First name: <input type="text"...
12
by: xeys_00 | last post by:
#include<iostream> #include<cstdlib> //This program will be a number guessing game int main() { //variables for the game
6
by: Rtritell | last post by:
Please can you find out what's wrong, fix the script and tell me what was wrong. Im just beginning <html> <head> <title>Random Mad Lib!</title> <script language="JavaScript"> <!-- Hide
13
by: Pedro Graca | last post by:
I'm sure this isn't very pythonic; comments and advice appreciated def curious(text): """ Return the words in input text scrambled except for the first and last letter. """ new_text = "" word...
4
by: Kim | last post by:
Random image downloader for specified newsgroup. Hi I'm writing a small script that will download random images from a specified newsgroup. I've imported yenc into the script but I can't open the...
3
by: simonharrison | last post by:
Hello everyone. Hopefully someone can point me in the right direction here. I'm wanting to write a script to open microsoft word and adobe pdf documents . Here is a little background: At the...
1
by: bn4 | last post by:
I have been trying to modify a script that i had working in the past but have lost.. ORIGINAL URL: http://www.thescripts.com/forum/thread147097.html STEPS: I want it to do the following:...
12
by: Phillip B Oldham | last post by:
I'm keen on learning python, with a heavy lean on doing things the "pythonic" way, so threw the following script together in a few hours as a first-attempt in programming python. I'd like the...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.