Generating Filenames from Feeds

C

Chuck

HI all,

I am trying to write a podcast catcher for fun, and I am trying to come up with a way to generate a destination filename to use in the function urlretrieve(url, destination). I would like the destination filename to end in a .mp3 extension.

My first attempts were parsing out the <pubdate> and stripping the whitespace characters, and joining with os.path.join. I haven't been able to make that work for some reason. Whenever I put the .mp3 in the os.path.join I get syntax errors. I am wondering if there is a better way?

I was doing something like os.path.join('C:\\Users\\Me\\Music\\Podcasts\\',pubdate.mp3), where pubdate has been parsed and stripped of whitespace. Ikeep getting an error around the .mp3.

Any ideas?

Thanks!!
Chuck
 
J

Joel Goldstick

HI all,

I am trying to write a podcast catcher for fun, and I am trying to come up
with a way to generate a destination filename to use in the function
urlretrieve(url, destination). I would like the destination filename to
end in a .mp3 extension.

My first attempts were parsing out the <pubdate> and stripping the
whitespace characters, and joining with os.path.join. I haven't been able
to make that work for some reason.


The reason is apparently a syntax error.

Whenever I put the .mp3 in the os.path.join I get syntax errors. I am
wondering if there is a better way?

Yes, don't write code with syntax errors!
I was doing something like
os.path.join('C:\\Users\\Me\\Music\\Podcasts\\', pubdate.mp3), where
pubdate has been parsed and stripped of whitespace. I keep getting an
error around the .mp3.

Any ideas?

Seriously, if you don't post a minimal code example that shows the problem
and with a full traceback you are asking strangers to do magic tricks for
your pleasure.
 
M

MRAB

HI all,

I am trying to write a podcast catcher for fun, and I am trying to
come up with a way to generate a destination filename to use in the
function urlretrieve(url, destination). I would like the
destination filename to end in a .mp3 extension.

My first attempts were parsing out the <pubdate> and stripping the
whitespace characters, and joining with os.path.join. I haven't been
able to make that work for some reason. Whenever I put the .mp3 in
the os.path.join I get syntax errors. I am wondering if there is a
better way?

I was doing something like
os.path.join('C:\\Users\\Me\\Music\\Podcasts\\', pubdate.mp3), where
pubdate has been parsed and stripped of whitespace. I keep getting
an error around the .mp3.

Any ideas?
The filename referred to by pubdate is a string, and you want to append
an extension, also a string, to it. Therefore:

os.path.join('C:\\Users\\Me\\Music\\Podcasts\\', pubdate + '.mp3')
 
C

Chuck

Seriously, if you don't post a minimal code example that shows the problem and with a full traceback you are asking strangers to do magic tricks for your pleasure.

I'm asking more for a better way of generating destination filenames, not so much debugging questions. I only put my attempts there to show people that I was actually trying something, and not just relying on people to do my thinking for me.

I'm trying to take a feed such as this

http://www.theskepticsguide.org/feed/rss.aspx?feed=SGU

and parse some useful data out of it for a destination filename. The solution should be general, and not just for this particular feed.

Thanks!
 
C

Chuck

Seriously, if you don't post a minimal code example that shows the problem and with a full traceback you are asking strangers to do magic tricks for your pleasure.

I'm asking more for a better way of generating destination filenames, not so much debugging questions. I only put my attempts there to show people that I was actually trying something, and not just relying on people to do my thinking for me.

I'm trying to take a feed such as this

http://www.theskepticsguide.org/feed/rss.aspx?feed=SGU

and parse some useful data out of it for a destination filename. The solution should be general, and not just for this particular feed.

Thanks!
 
S

Steven D'Aprano

I'm asking more for a better way of generating destination filenames,
not so much debugging questions. I only put my attempts there to show
people that I was actually trying something, and not just relying on
people to do my thinking for me.

I'm trying to take a feed such as this

http://www.theskepticsguide.org/feed/rss.aspx?feed=SGU

and parse some useful data out of it for a destination filename. The
solution should be general, and not just for this particular feed.

There is no such general solution, because "some useful data" will depend
on what you intend to do with it, what the feed is, and what *you*
consider "useful".

Your earlier approach is probably fine, once you fix the syntax error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,001
Messages
2,570,254
Members
46,850
Latest member
VMRKlaus8

Latest Threads

Top