Trouble with script fetching site

Discussion in 'Python' started by Stephen Boulet, Sep 3, 2003.

  1. I'm trying to parse a url to set my hardware & system clock (linux).

    Perhaps the best way to do this would be to use the urllib2 module to
    convert a site to text, but since I haven't found that option yet, I did
    this instead (which sometimes works, sometimes doesn't, and when it doesn't
    seems to get hung up on line 4 -- os.popen oddity?):

    #/usr/bin/env python
    import os,sys

    url = "http://www.time.gov/timezone.cgi?Central/d/-6"
    f = os.popen("lynx -dump " + url)
    lines = f.readlines()

    i = 0
    for line in lines:
    lines = line.strip()
    i += 1

    for i in range(len(s)):
    if s.find("Right now") > -1:
    break

    time = s[1]
    day,month,year = s[2].split(',')
    month = month.strip()
    month = month.split(' ')
    month = ' '.join([month[0][0:3],month[1]])
    year = year.strip()

    result = ' '.join([day, month, time, "CDT", year])
    print "result is %s.\n" % result
    command = 'date -u -s "' + result + '";hwclock --systohc'
    print "Command is: \n\n%s.\n" % command

    f = os.popen(command)
    print f.read()

    # updatetime.py
    import: Unable to open file (os,sys).
    /usr/local/bin/updatetime.py: line 4: url: command not found
    /usr/local/bin/updatetime.py: line 5: syntax error near unexpected token `('
    /usr/local/bin/updatetime.py: line 5: `f = os.popen("lynx -dump " + url)'

    I'm fetching a site


    --
    Stephen
    From here to there
    and there to here,
    funny things are everywhere. -- Dr Seuss
    Stephen Boulet, Sep 3, 2003
    #1
    1. Advertising

  2. Stephen Boulet

    Peter Hansen Guest

    Stephen Boulet wrote:
    >
    > I'm trying to parse a url to set my hardware & system clock (linux).


    I can't help with the problem at hand, but I also don't see the
    reason to do it. Why not just access an NTP server and grab the
    time the "proper" way? Using a web page is a roundabout way of
    doing it. There's a nice setclock.py script which Google can
    point you to which does the job much more easily.

    -Peter
    Peter Hansen, Sep 3, 2003
    #2
    1. Advertising

  3. Stephen Boulet

    John J. Lee Guest

    Peter Hansen <> writes:

    > Stephen Boulet wrote:
    > >
    > > I'm trying to parse a url to set my hardware & system clock (linux).

    >
    > I can't help with the problem at hand, but I also don't see the
    > reason to do it. Why not just access an NTP server and grab the
    > time the "proper" way? Using a web page is a roundabout way of
    > doing it.


    Right.

    > There's a nice setclock.py script which Google can
    > point you to which does the job much more easily.


    On my system, the ntpdate command works nicely. I run it my PPP
    scripts.


    John
    John J. Lee, Sep 3, 2003
    #3
  4. You guys are probably right. If you have a hammer ...

    John J. Lee wrote:
    > Peter Hansen <> writes:
    >
    >
    >>Stephen Boulet wrote:
    >>
    >>>I'm trying to parse a url to set my hardware & system clock (linux).

    >>
    >>I can't help with the problem at hand, but I also don't see the
    >>reason to do it. Why not just access an NTP server and grab the
    >>time the "proper" way? Using a web page is a roundabout way of
    >>doing it.

    >
    >
    > Right.
    >
    >
    >>There's a nice setclock.py script which Google can
    >>point you to which does the job much more easily.

    >
    >
    > On my system, the ntpdate command works nicely. I run it my PPP
    > scripts.
    >
    >
    > John
    Stephen Boulet, Sep 3, 2003
    #4
  5. Stephen Boulet

    Peter Hansen Guest

    "John J. Lee" wrote:
    >
    > Peter Hansen <> writes:
    >
    > > Stephen Boulet wrote:
    > > >
    > > > I'm trying to parse a url to set my hardware & system clock (linux).

    > >
    > > I can't help with the problem at hand, but I also don't see the
    > > reason to do it. Why not just access an NTP server and grab the
    > > time the "proper" way? Using a web page is a roundabout way of
    > > doing it.

    >
    > Right.
    >
    > > There's a nice setclock.py script which Google can
    > > point you to which does the job much more easily.

    >
    > On my system, the ntpdate command works nicely. I run it my PPP
    > scripts.


    And once one knows it exists, one should probably prefer that
    method. As I now do. <grin>

    -Peter
    Peter Hansen, Sep 3, 2003
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steve
    Replies:
    0
    Views:
    443
    Steve
    Nov 27, 2003
  2. Hypo
    Replies:
    6
    Views:
    393
  3. =?Utf-8?B?UGhhbmlkaGFy?=

    Problem in Fetching Session Variable

    =?Utf-8?B?UGhhbmlkaGFy?=, Apr 1, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    383
    bruce barker
    Apr 1, 2004
  4. =?ISO-8859-1?Q?=D8ystein_Johansen?=

    fetching a cvs repository directory from a cgi script

    =?ISO-8859-1?Q?=D8ystein_Johansen?=, Sep 28, 2003, in forum: Python
    Replies:
    0
    Views:
    287
    =?ISO-8859-1?Q?=D8ystein_Johansen?=
    Sep 28, 2003
  5. Replies:
    4
    Views:
    286
    ccc31807
    Jul 29, 2011
Loading...

Share This Page