On 9 jun, 22:00, Fábio Santos <fabiosantos...@gmail.com> wrote: > On 9 Jun 2013 20:49, "Jean Dubois" <jeandubois...@gmail.com> wrote: > > > > > I'm writing some code to check whether an url is available or not, > > therefore I make use of a wget-command in Linux and then check whether > > this is successful (returning a 0) or not returning an 8 > > However the if then statement seems to give the same result in both > > cases: > > Which result? Failure, or success? In case of failure I expect it to answer: stream not available In case of success I expect it to answer: stream is available But I get a "stream is available" in both cases even though the command os.system(checkavailablestring) does give different answers: 0 and 8 >Have you tried printing the > checkavailablestring string and running that command exactly? yes I did, no problem there >There may be something wrong with the command or URL in some way, and calling >os.system I have added a line to the script and the results below so you can see better what's going wrong:
Here's the script once again, this time with an extra line: #!/usr/bin/env python import sys import os from datetime import datetime, timedelta today=datetime.now() yesterday= datetime.now() - timedelta(days=1) daybeforeyesterday= datetime.now() - timedelta(days=2) collection = [daybeforeyesterday,yesterday,today] for thisday in collection: checkavailablestring='wget -q -O - http://www.deredactie.be/cm/vrtnieuws/videozone/programmas/journaal/EP_'+thisday.strftime("%y%m%d")+'_JO7 >/dev/null ; echo $?' print checkavailablestring if os.system(checkavailablestring)==0: print thisday, 'stream is available' else: print thisday, 'stream is not available' And here is the result: jean@antec4:~$ ./try.py wget -q -O - http://www.deredactie.be/cm/vrtnieuws/videozone/programmas/journaal/EP_130607_JO7 >/dev/null ; echo $? 8 2013-06-07 22:07:00.016807 stream is available wget -q -O - http://www.deredactie.be/cm/vrtnieuws/videozone/programmas/journaal/EP_130608_JO7 >/dev/null ; echo $? 8 2013-06-08 22:07:00.016795 stream is available wget -q -O - http://www.deredactie.be/cm/vrtnieuws/videozone/programmas/journaal/EP_130609_JO7 >/dev/null ; echo $? 0 2013-06-09 22:07:00.016763 stream is available -- http://mail.python.org/mailman/listinfo/python-list