473,769 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Random image downloader for newsgroups (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.p ictures.blah" #newsgroup will go here

# connect to server
server = nntplib.NNTP(SE RVER)

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

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_p erm):
pass # no such message (maybe it was deleted?)
else:
break # found a message!
else:
raise SystemExit

text = string.join(tex t, "\n")
file = StringIO.String IO(text)

msg = mimetools.Messa ge(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(fil e):
# <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(li ne, "=")
buffer.append(s tring.translate (data[0], yenc42))
for data in data[1:]:
data = string.translat e(data, yenc42)
buffer.append(s tring.translate (data[0], yenc64))
buffer.append(d ata[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(lin e)
#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
4 3082
Kim schrieb:
SERVER = "news.server.co .uk" #Insert news server here
GROUP = "alt.binaries.p ictures.blah" #newsgroup will go here
Just why do I imagine there will be an adult newsgroup in the end....?

SCNR,

Diez
Sep 7 '06 #2
SERVER = "news.server.co .uk" #Insert news server here
GROUP = "alt.binaries.p ictures.blah" #newsgroup will go here

Just why do I imagine there will be an adult newsgroup in the end....?
I can see the freshmeat announcement now: "Random Boob Visualizer 1.0"...

Skip
Sep 7 '06 #3

Skip Montanaro wrote:
SERVER = "news.server.co .uk" #Insert news server here
GROUP = "alt.binaries.p ictures.blah" #newsgroup will go here
Just why do I imagine there will be an adult newsgroup in the end....?

I can see the freshmeat announcement now: "Random Boob Visualizer 1.0"...

Skip
mmmmmm, boobs.

;-)

Sep 7 '06 #4
Kim wrote:
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.p ictures.blah" #newsgroup will go here

# connect to server
server = nntplib.NNTP(SE RVER)

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

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_p erm):
pass # no such message (maybe it was deleted?)
else:
break # found a message!
else:
raise SystemExit

text = string.join(tex t, "\n")
file = StringIO.String IO(text)

msg = mimetools.Messa ge(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(fil e):
# <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(li ne, "=")
buffer.append(s tring.translate (data[0], yenc42))
for data in data[1:]:
data = string.translat e(data, yenc42)
buffer.append(s tring.translate (data[0], yenc64))
buffer.append(d ata[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(lin e)
#print file
#outp.close()
The following worked for me. It printed text and even
generated viewable images when I went to a pictures group.

I cleaned it up a little. I'm sure it can be cleaner. That's partly
because I didn't want to drift too far from your original and
partly because I don't get much Python practice.

Don't use "file" as a variable name, it overwrites the built in
file object. It likely didn't matter in this case, but would
eventually cause problems.

####random group downloader####
import nntplib
import random
import StringIO
import mimetools
import rfc822
import binascii
#import base64
#import sys
#import os
#import email
#import errno
#import mimetypes
SERVER = "news.server.co .uk" #Insert news server here
GROUP = "alt.binaries.p ictures.blah" #newsgroup will go here

# connect to server
server = nntplib.NNTP(SE RVER)

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

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_p erm):
pass # no such message (maybe it was deleted?)
else:
break # found a message!
else:
raise SystemExit

msgFile = StringIO.String IO("\n".join(te xt))

# Display mime message information
msg = mimetools.Messa ge(msgFile)
msgFile.seek(0)
print "File type", "=>", msg.gettype()
print "Encoding", "=>", msg.getencoding ()
print "plist", "=>", msg.getplist()

# Display rfc822 message information
message = rfc822.Message( msgFile)
msgFile.seek(0)
for k, v in message.items() :
print k, "=", v

yenc42 = "".join([chr((i - 42) & 255) for i in range(256)])
yenc64 = "".join([chr((i - 64) & 255) for i in range(256)])

def yenc_decode(fil eIn):
# <i>find body</i>
while 1:
line = fileIn.readline ()
if not line:
return None
if line[:7] == "=ybegin":
break
# <i>extract data</i>
buffer = []
while 1:
line = fileIn.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]
splitData = line.split("=")
buffer.append(s plitData[0].translate(yenc 42))
for data in splitData[1:]:
buffer.append(d ata[0].translate(yenc 64).translate(y enc42))
buffer.append(d ata[1:].translate(yenc 42))
return buffer

def uu_decode(fileI n):
# <i>find body</i>
while 1:
line = fileIn.readline ()
if not line:
return None
if line[:6] == "begin ":
break
# <i>extract data</i>
buffer = []
while 1:
line = fileIn.readline ()
if not line or line[:3] == "end":
break
buffer.append(b inascii.a2b_uu( line))
return buffer

# Write the raw message to a text file
outp = open("text.txt" ,"w")
for line in msgFile:
outp.write(line )
outp.close()
msgFile.seek(0)

# Find and convert a yencode or uu encode binary in the message.
image = yenc_decode(msg File)
if image == None:
msgFile.seek(0)
image = uu_decode(msgFi le)

# output the decoded binary data, if any
if image != None:
outp = open("text.jpg" ,"wb")
outp.write("".j oin(image))
outp.close()

Sep 8 '06 #5

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

Similar topics

12
9709
by: bhennon | last post by:
Hey all, I have a small php script that calls a random image at the following page. http://www.2006ymcanationals.com/random.php IT WORKS IF I go directly to the above link. I am trying to call that in another page so that i get a random image the page is http://2006ymcanationals.com/index.php using <img
6
3536
by: Olly | last post by:
I've found a basic script, however I also need to add alt and title attributes as well, how would I go about doing this? Here's the script I found: Thanks <script language="JavaScript"> <!-- /*
9
12399
by: Michael Burtenshaw | last post by:
I would like to make a slide show using random images. The problem is my host is 250.com, and they don't support cgi-programs. Is there another way to accomplish random images?
5
2592
by: Linda | last post by:
Greetings: I have found a random image script that I like. It is located here: http://www.javascriptcity.com/scripts/local/simage3.htm I'd like to edit this to have 4 different slots for images with a different set of 5 images for each slot, something like this page: http://www.uchsc.edu The script says /* no need to edit past this point (unless you want to
15
5363
by: David Lozzi | last post by:
Howdy, I have a function that uploads an image and that works great. I love ..Nets built in upload, so much easier than 3rd party uploaders! Now I am making a public function that will take the path of the uploaded image, and resize it with the provided dimensions. My function is below. The current function is returning an error when run from the upload function: A generic error occurred in GDI+. Not sure what exactly that means. From what...
4
2756
by: tshad | last post by:
I am trying to set up an Image authorization where you type in the value that is in a picture to log on to our site. I found a program that is supposed to do it, but it doesn't seem to work. It should put a blue and yellow box on the page with "This is a test" as part of the picture. But what I get is a broken Gif. The other problem is that I can't view the source???? The view source is disabled for this page. What causes this?
0
1528
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 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
7
4556
by: Brian | last post by:
Hi there I have been looking for a script that can randomly rotate 8 different images on 1 page. I used to have a script that did this but can't find it now. I have found loads of script that will load a differnet image each time the page loads, or will rotate 1 image at a time, but not one that can do 8 images from a list of images Does anybody know of one?
0
10210
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10039
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9990
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8869
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6668
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5297
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5445
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3560
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2814
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.