Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #47488
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-06-09 13:15 -0700 |
| References | <cd1be83a-f560-4024-90b3-697a51bb1bb0@g7g2000vbv.googlegroups.com> <mailman.2932.1370808058.3114.python-list@python.org> |
| Message-ID | <2cb97d50-87b1-4173-a4d9-0cb4342bfd5f@g2g2000vbk.googlegroups.com> (permalink) |
| Subject | Re: problem with if then |
| From | Jean Dubois <jeandubois314@gmail.com> |
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
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[newbie] problem with if then Jean Dubois <jeandubois314@gmail.com> - 2013-06-09 12:44 -0700
Re: [newbie] problem with if then Fábio Santos <fabiosantosart@gmail.com> - 2013-06-09 21:00 +0100
Re: problem with if then Jean Dubois <jeandubois314@gmail.com> - 2013-06-09 13:15 -0700
Re: problem with if then Fábio Santos <fabiosantosart@gmail.com> - 2013-06-09 21:29 +0100
Re: problem with if then Jean Dubois <jeandubois314@gmail.com> - 2013-06-09 13:51 -0700
Re: [newbie] problem with if then Roy Smith <roy@panix.com> - 2013-06-09 16:23 -0400
Re: problem with if then Jean Dubois <jeandubois314@gmail.com> - 2013-06-09 14:00 -0700
Re: problem with if then Roy Smith <roy@panix.com> - 2013-06-09 17:35 -0400
Re: problem with if then Jean Dubois <jeandubois314@gmail.com> - 2013-06-10 00:46 -0700
Re: [newbie] problem with if then Albert Dengg <albert@fsfe.org> - 2013-06-09 22:37 +0200
csiph-web