Trouble with script fetching site

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stephen Boulet

    Trouble with script fetching site

    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?Ce ntral/d/-6"
    f = os.popen("lynx -dump " + url)
    lines = f.readlines()

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

    for i in range(len(s)):
    if s[i].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(comman d)
    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

  • Peter Hansen

    #2
    Re: Trouble with script fetching site

    Stephen Boulet wrote:[color=blue]
    >
    > I'm trying to parse a url to set my hardware & system clock (linux).[/color]

    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

    Comment

    • John J. Lee

      #3
      Re: Trouble with script fetching site

      Peter Hansen <peter@engcorp. com> writes:
      [color=blue]
      > Stephen Boulet wrote:[color=green]
      > >
      > > I'm trying to parse a url to set my hardware & system clock (linux).[/color]
      >
      > 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.[/color]

      Right.
      [color=blue]
      > There's a nice setclock.py script which Google can
      > point you to which does the job much more easily.[/color]

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


      John

      Comment

      • Stephen Boulet

        #4
        Re: Trouble with script fetching site

        You guys are probably right. If you have a hammer ...

        John J. Lee wrote:[color=blue]
        > Peter Hansen <peter@engcorp. com> writes:
        >
        >[color=green]
        >>Stephen Boulet wrote:
        >>[color=darkred]
        >>>I'm trying to parse a url to set my hardware & system clock (linux).[/color]
        >>
        >>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.[/color]
        >
        >
        > Right.
        >
        >[color=green]
        >>There's a nice setclock.py script which Google can
        >>point you to which does the job much more easily.[/color]
        >
        >
        > On my system, the ntpdate command works nicely. I run it my PPP
        > scripts.
        >
        >
        > John[/color]

        Comment

        • Peter Hansen

          #5
          Re: Trouble with script fetching site

          "John J. Lee" wrote:[color=blue]
          >
          > Peter Hansen <peter@engcorp. com> writes:
          >[color=green]
          > > Stephen Boulet wrote:[color=darkred]
          > > >
          > > > I'm trying to parse a url to set my hardware & system clock (linux).[/color]
          > >
          > > 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.[/color]
          >
          > Right.
          >[color=green]
          > > There's a nice setclock.py script which Google can
          > > point you to which does the job much more easily.[/color]
          >
          > On my system, the ntpdate command works nicely. I run it my PPP
          > scripts.[/color]

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

          -Peter

          Comment

          Working...