Sponsored Content
Top Forums Shell Programming and Scripting Getting current time from wolfram.com using python Post 302385820 by frozensmilz on Sunday 10th of January 2010 06:39:19 AM
Old 01-10-2010
Bug Getting time from internet and updating the windows time using python

Ok !, I did it myself. Here is the code.

Python (Modified from actual source: java2s.com)

Code:
# mytime2  - SYNC TIME WITH WOLFRAM ALPHA VERSION 2

import sys
import HTMLParser
import urllib

mode = sys.argv
url = "http://www.wolframalpha.com/input/?i=time"
urlText = []
TZ = "MYT"

class parseText(HTMLParser.HTMLParser):
    def handle_data(self, data):
        if data != '\n':
            urlText.append(data)


lParser = parseText()
lParser.feed(urllib.urlopen(url).read())
lParser.close()

htm_str_1 = []

for htm_str in urlText:
	htm_str = htm_str.split();	
	wrdLoc = 1
	for htm_str_2 in htm_str:		
		if htm_str_2 == TZ:
			
			# TIME
			time = htm_str[37]
			timeChk = htm_str[37].find(":")
			if timeChk != -1:
				time = time.split('"')
				time = time[1]+" "+htm_str[38].upper()
			
			#DATE
			day = htm_str[43].split(',')

			month = htm_str[42].lower()
			
			if month == "january":
				month = "01"		
			if month == "february":
				month = "02"
			if month == "march":
				month = "03"
			if month == "april":
				month = "04"
			if month == "may":
				month = "05"
			if month == "june":
				month = "06"
			if month == "july":
				month = "07"		
			if month == "august":
				month = "08"
			if month == "september":
				month = "09"
			if month == "october":
				month = "10"
			if month == "november":
				month = "11"
			if month == "december":
				month = "12"

			year = htm_str[44].split('"')			
			date = month+"/"+day[0]+"/"+year[0]

			break
		wrdLoc = wrdLoc + 1

if mode[1] == '1':
	if date != "":
		print date
	else:
		print ""

if mode[1] == '2':
	if time != "":
		print time
	else:
		print ""

Batch Script (Windows)

Code:
@echo off
REM set period=%1
mytime.py 2 > TIM.TEMP
set /p var= < TIM.TEMP
REM set mtime=%var% %period%
set mtime=%var%
echo %mtime%
time %mtime%
mytime.py 1 > DAT.TEMP
set /p var= < DAT.TEMP
set mdate=%var%
echo %mdate%
date %mdate%
echo BASIL B.C. 2009


Internet connection is necessary. Change the value for 'TZ' timezone variable accordingly. Place both of them in one folder say 'bin'. Add 'bin' path to environment variables and execute 'mytime' from command line or its shortcut. If wolframalpha changes the HTML source code style, this script wont work.

I use this script to set time & date in my laptop that has no battery.
 

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Need help for AWK output with current time

Hi, Any suggestion to get the AWK output with time in each line ? I want to have the vmstat in solaris with time append to everyline like this: kthr memory page disk faults cpu r b w swap free re mf pi po fr de sr s0 s1 s3 sd in sy cs... (2 Replies)
Discussion started by: roxy2k
2 Replies

2. Shell Programming and Scripting

How far is given date from current time?

give a date and time: Jun 12 21:05:16 06-12-2012 21:05:16 2012/06/12 21:05:16 How can i subtract these dates and times from the current date and time and get back the difference in seconds? a one liner like: echo "Jun 12 21:05:16" | some perl/awk programming 90900s (2 Replies)
Discussion started by: SkySmart
2 Replies

3. Shell Programming and Scripting

How to display current time in the prompt

Hello All, I would like to display the current time in prompt. I tried using following command: export PS1="$(date +%k:%M:%S) $ " but it gave me a fixed time in prompt whereas my objective is to get the current time everytime. $ export PS1="$(date +%k:%M:%S) $ " 17:42:42 $ 17:42:42 $... (32 Replies)
Discussion started by: manishdivs
32 Replies

4. Shell Programming and Scripting

Displaying current date time of EDT in IST time

Hi Folks, My server time is in EDT. And i am sending automated mails from that server in which i need to display the current date time as per IST (GMT+5:30). Please advice how to display the date time as per IST. IST time leads 9:30 mins to EDT. and i wrote something like below. ... (6 Replies)
Discussion started by: Showdown
6 Replies

5. Shell Programming and Scripting

Add current date and time

i have file 1.txt asdas|csada|13|03|10|04|23|A1|canberra sdasd|sfdsf|13|04|26|23|28|A1|sydney i want to add today's date and time in the end of each row expected output asdas|csada|13|03|10|04|23|A1|canberra|130430|1358 sdasd|sfdsf|13|04|26|23|28|A1|sydney|130430|1358 todays date... (10 Replies)
Discussion started by: radius
10 Replies

6. Shell Programming and Scripting

To get the time exactly 24hrs from the current time

Hi guys, I am having file which contains below data. 2012-04-24 08:40:13 10739022730 1027699274PersonInfoShipTO details missing FirstName,LastName, 2012-04-24 08:40:13 10739022730 1027699274PersonInfoShipTO details missing FirstName,LastName, 2012-04-24 08:40:13 ... (2 Replies)
Discussion started by: mohanalakshmi
2 Replies

7. Shell Programming and Scripting

Convert UTC time into current UNIX sever time zone

Hi guys thanks for the help for my previous posts.Now i have a requirement that i download a XMl file which has UTC time stamp.I need to convert UTC time into Unix server timezone. For ex if the time zone of unix server is CDT then i need to convert into CDT.whatever may be the system time... (5 Replies)
Discussion started by: mohanalakshmi
5 Replies

8. Programming

Arduino UNIX Time - Syncing Computer UNIX Time to Arduino Time with Python

Just finished a quick Python script to send the current unix time over to the Arduino from macOS, so in the absence of GPS or some other way to get the unix timestamp (epoch time) to the Arduino, I can get my macOS and Arduino UNO synced to within a second. Normally, when the Arduino starts... (9 Replies)
Discussion started by: Neo
9 Replies
CAL_FROM_JD(3)								 1							    CAL_FROM_JD(3)

cal_from_jd - Converts from Julian Day Count to a supported calendar

SYNOPSIS
array cal_from_jd (int $jd, int $calendar) DESCRIPTION
cal_from_jd(3) converts the Julian day given in $jd into a date of the specified $calendar. Supported $calendar values are CAL_GREGORIAN, CAL_JULIAN, CAL_JEWISH and CAL_FRENCH. PARAMETERS
o $jd - Julian day as integer o $calendar - Calendar to convert to RETURN VALUES
Returns an array containing calendar information like month, day, year, day of week, abbreviated and full names of weekday and month and the date in string form "month/day/year". EXAMPLES
Example #1 cal_from_jd(3) example <?php $today = unixtojd(mktime(0, 0, 0, 8, 16, 2003)); print_r(cal_from_jd($today, CAL_GREGORIAN)); ?> The above example will output: Array ( [date] => 8/16/2003 [month] => 8 [day] => 16 [year] => 2003 [dow] => 6 [abbrevdayname] => Sat [dayname] => Saturday [abbrevmonth] => Aug [monthname] => August ) SEE ALSO
cal_to_jd(3), jdtofrench(3), jdtogregorian(3), jdtojewish(3), jdtojulian(3), jdtounix(3). PHP Documentation Group CAL_FROM_JD(3)
All times are GMT -4. The time now is 05:04 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy