472,371 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,371 software developers and data experts.

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?Central/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(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

Jul 18 '05 #1
4 1628
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
Jul 18 '05 #2
Peter Hansen <pe***@engcorp.com> 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
Jul 18 '05 #3
You guys are probably right. If you have a hammer ...

John J. Lee wrote:
Peter Hansen <pe***@engcorp.com> 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


Jul 18 '05 #4
"John J. Lee" wrote:

Peter Hansen <pe***@engcorp.com> 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
Jul 18 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andres Baravalle | last post by:
Hi, I have a problem using a URL fetching algorithm (HTTP 1.0). To download an image, I used to use this algorithm: <?php Header("Content-type: image/gif"); $referer =...
9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
0
by: keith_h | last post by:
I am primarily a front-end designer and not familiar with ASP beyond breaking up pages into include files. Recently, one of my freelance clients wanted to display an RSS feed from his blog on his...
1
by: eyal.susser | last post by:
Hi, I'm trying to write a script that uses diffxml along with 4xupdate to merge XML files. So far, I'm having trouble with even the most basic files. I have tried different versions of the...
22
by: Sandman | last post by:
So, I have this content management system I've developed myself. The system has a solid community part where members can register and then participate in forums, write weblogs and a ton of other...
9
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
2
by: Gilles Ganault | last post by:
Hello I need to write a script to automate fetching data from a web site: 1. using the POST method, log on, with login/password saved as cookies 2. download page and extract relevent information...
5
matheussousuke
by: matheussousuke | last post by:
Hi guys, good morning. I've just get this script for converting mysql tables from wordpress, and I want to use it in my server, but no with wordpress, with oscommerce, a friend of mine told me a...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
2
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.