473,385 Members | 1,919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 1685
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.