[Tutor] subprocess adds %0A to end of string

David david at abbottdavid.com
Mon Dec 22 00:51:48 CET 2008


Hi everyone.
Just learning :) I have one program to parse a podcast feed and put it 
into a file.

#!/usr/bin/python
"""Get feed date and link details"""
import feedparser
import sys

def getFeed():
     url = raw_input("Please enter the feed: ")
     data = feedparser.parse(url)
     for entry in data.entries:
         sys.stdout = open("podcast.txt", "a")
         print '%s: %s' % (entry.updated, entry.link)
         sys.stdout.close()
     for entry in data.entries:
         sys.stdout = open("podcast_links.txt", "a")
         print '%s' % (entry.link)
         sys.stdout.close()
getFeed()

next to get the latest item;

#!/usr/bin/python
"""read the last entry and download podcast"""
import subprocess
fname = "podcast.txt"
f = open(fname, 'r')
print "The Latest Podcast", f.readline()
print f.readline()
f.close()
lname = "podcast_links.txt"
L = open(lname, 'r')
print "The Latest Link\n"
download = L.readline()
print download

answer = raw_input("Do you want to download the podcast? ")
if answer == "y":
     wget = "wget"
     subprocess.call([wget, download])
else:
     print "oops"

and here is the output;

david [06:37 PM] opteron ~ $ ./py_read_podcast.py
The Latest Podcast

Sat, 20 Dec 2008 01:52:00 GMT: http://linuxcrazy.com/podcasts/LC-44-arne.mp3

The Latest Link

http://linuxcrazy.com/podcasts/LC-44-arne.mp3

Do you want to download the podcast? y
--2008-12-21 18:38:46--  http://linuxcrazy.com/podcasts/LC-44-arne.mp3%0A
Resolving linuxcrazy.com... 74.220.207.171
Connecting to linuxcrazy.com|74.220.207.171|:80... connected.
HTTP request sent, awaiting response... 404 Not Found
2008-12-21 18:38:46 ERROR 404: Not Found.

See how it adds the %0A to the end ?

I am just trying to get it to work, I know it needs a lot of work, error 
checking etc. And I am sure there are better ways, I am new.

thanks
-david


-- 
Powered by Gentoo GNU/LINUX
http://www.linuxcrazy.com
pgp.mit.edu



More information about the Tutor mailing list