A.T.W.S
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

A.T.W.S

Started by c h i l l a, 15 December, 2003, 13:27:51

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

c h i l l a

i am not sure about the sylvester thing showing the cities, but theoretically it works

--Around The World Sylvester  V.1.1  by chill
--also thx to plop,tezlo,notrabidwombat
---------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------
--You need this Folder in the ScriptsFolder
ATWFolder = "txt"
--This is the ascii in the Folder
ASCIIFile = "SYLVESTER.txt"
SylYear,SylMonth,SylDay = 03,12,31
File1 = "ATWSCity.txt"
---------------------------------------------------------------------------------------------------------
host = "www.timeanddate.com"
--get = "worldclock/index.html"
get = "worldclock/full.html"
GETHTML = "GET /"..get.." HTTP/1.1\r\nHost: "..host.."\r\nUser-Agent: Mozilla/4.0 (compatible; LUA 4.0; LUA 4.0)\r\n"
CityGMT = {}
Set = 1
dofile(ATWFolder.."/"..File1)
---------------------------------------------------------------------------------------------------------
function Main()
	sylday,sylsec = jdate(SylDay,SylMonth,SylYear,24,0,0)
	if not LGMT then
		GetCityGMT()
	else
		if (tonumber(date("%M"))~=0) then
			SetTimer((60 - tonumber(date("%M"))) *60*1000 - tonumber(date("%S"))*1000)
		else
			SetTimer(1)
		end
	end
	ASCII = ReadFile()
	StartTimer()
end

function OnTimer()
	if (tonumber(date("%d")) == SylDay or (tonumber(date("%d")) == 1 and tonumber(date("%y")) == SylYear + 1)) and Set == 1 then
		SetTimer(60*60*1000)
		for i,v in CityGMT do
			if (tonumber(date("%H")) + GMT + i == 0) or (tonumber(date("%H")) + GMT + i == 24) then
				local cities = ""
				for i2 = 1,getn(CityGMT[i]) do
					cities = cities..CityGMT[i][i2]..", "
				end
				SendToAll("Happy New Year to :\r\n"..cities)
			end
		end
	end
	local curday,cursec = jdate(tonumber(date("%d")),tonumber(date("%m")),tonumber(date("%y")),tonumber(date("%H")),tonumber(date("%M")),tonumber(date("%S")))
	local tmp = sylsec-cursec
	local hours, minutes,seconds = floor(mod(tmp/3600, 60)), floor(mod(tmp/60, 60)), floor(mod(tmp/1, 60))
	if sylday-curday > 0 then
		SendToAll(" *** Still "..sylday-curday.." Days till Sylvester.")
		SetTimer(60*60*1000)
	elseif sylday-curday == 0 and hours ~= 0 then
		SendToAll(" *** Still "..sylday-curday.." Days and "..hours.." till Sylvester.")
		SetTimer(60*60*1000)
	elseif sylday-curday == 0 and hours == 0 and minutes ~= 0 then
		SendToAll(" *** Still "..sylday-curday.." Days, "..hours.." Hours and "..minutes.." Minutes till Sylvester.")
		Set = 0
		SetTimer(60*1000)
	elseif sylday-curday == 0 and hours == 0 and minutes == 0 and sec > 20 then
		SendToAll(" *** Still "..sylday-curday.." Days, "..hours.." Hours, "..minutes.." Minutes and "..seconds.." Seconds till Sylvester.")
		Set = 0
		SeTimer(10*1000)
	elseif sylday-curday == 0 and hours == 0 and minutes == 0 and sec <= 20 then
		SendToAll(" *** Still "..sylday-curday.." Days, "..hours.." Hours, "..minutes.." Minutes and "..seconds.." Seconds till Sylvester.")
		Set = 0
		SeTimer(1*1000)
	elseif sylday-curday == 0 and hours == 0 and minutes == 0 and sec == 0 then
		SendToAll(ASCII)
		Set = 1
		SetTimer(1000)
	end
end

function GetCityGMT()
	socket, e = connect(host, 80)
	if not e then
		local line1 = ""
		socket:timeout(2)
		socket:send(GETHTML..strchar(13,10))
		local da,ho,mi = "",0,0
		while not e do
			line1, e = socket:receive("*l")
			local line = gsub(gsub(line1,"%b<>","$"),"%s%*+","")
			if strfind(line1,"Date:%s+(%w+),%s+%d+%s+%w+%s%d+%s(%d+):(%d+):%d+%s+GMT") then
				_,_,da,ho,mi = strfind(line1,"Date:%s+(%w+),%s+%d+%s+%w+%s%d+%s(%d+):(%d+):%d+%s+GMT")
			elseif strfind(line,"$$$([^$]*)$$$(%w+)%s+(%d+):(%d+)%s+(%w+)$$$([^$]*)$$$(%w+)%s+(%d+):(%d+)%s+(%w+)$$$([^$]*)$$$(%w+)%s+(%d+):(%d+)%s+(%a+)") then
				_,_,city1,day1,ho1,mi1,PA1,city2,day2,ho2,mi2,PA2,city3,day3,ho3,mi3,PA3 = strfind(line,"$$$([^$]*)$$$(%w+)%s+(%d+):(%d+)%s+(%w+)$$$([^$]*)$$$(%w+)%s+(%d+):(%d+)%s+(%w+)$$$([^$]*)$$$(%w+)%s+(%d+):(%d+)%s+(%a+)")
				for i = 1,3 do
					dostring("city,day,hou,min,PA = city"..i..",day"..i..",ho"..i..",mi"..i..",PA"..i)
					if (min == mi) or ((min-mi)==-30) or ((min-mi)==30) then
						if PA == "PM"  and tonumber(hou)~=12 then
							hou = hou + 12
						elseif PA == "AM" and tonumber(hou)==12 then
							hou = 0
						end
						local diff = 0
						if da ~= day and tonumber(ho) >= 12 then
							diff = 24 - ho + hou
						elseif da~=day and tonumber(ho) < 12 then
							diff = -24 + hou - ho
						else
							diff = hou - ho
						end
						if not CityGMT[diff] then
							CityGMT[diff] = {}
						end
						tinsert(CityGMT[diff],city)
					end
				end
			elseif line1 == "" then
				break
			end
		end
		socket:close()
		for i,v in CityGMT do
			sort(CityGMT[i])
		end
		
		if da ~= date("%a") and tonumber(ho) >= 12 then
			LGMT = 24 - ho + tonumber(date("%H"))
		elseif da~=date("%a") and tonumber(ho) < 12 then
			LGMT = -24 + tonumber(date("%H")) - ho
		else
			LGMT = tonumber(date("%H")) - ho
		end
		if (tonumber(date("%M"))~=0) then
			SetTimer((60 - tonumber(date("%M"))) *60*1000 - tonumber(date("%S"))*1000)
		else
			SetTimer(1)
		end
		WriteFile(CityGMT,"CityGMT",File1)
	end
end
----------------------------------------------------------------------------------------------------------------------------------------------
function WriteFile(table,tablename,file)
	local handle = openfile("txt/"..file,"w")
	Serialize(table,tablename,handle)
	write(handle,"\r\nLGMT = "..LGMT)
  	closefile(handle)
end
----------------------------------------------------------------------------------------------------------------------------------------------
function Serialize(tTable,sTableName,hFile,sTab)
	sTab = sTab or "";
	write(hFile,sTab..sTableName.." = {\n");
	for key,value in tTable do
		local sKey = (type(key) == "string") and format("[%q]",key) or format("[%d]",key);
		if(type(value) == "table") then
			Serialize(value,sKey,hFile,sTab.."\t");
		else
			local sValue = (type(value) == "string") and format("%q",value) or tostring(value);
			write(hFile,sTab.."\t"..sKey.." = "..sValue);
		end
		write(hFile,",\n");
	end
	write(hFile,sTab.."}");
end
----------------------------------------------------------------------------------------------------------------------------------------------
function jdate(d, m, y,ho,mi,se)
	local a, b, c = 0, 0, 0
	if m <= 2 then
		y = y - 1
		m = m + 12
	end
	if (y*10000 + m*100 + d) >= 15821015 then
		a = floor(y/100)
		b = 2 - a + floor(a/4)
	end
	if y <= 0 then c = 0.75 end
	return floor(365.25*y - c) + floor(30.6001*(m+1) + d + 1720994 + b),ho*3600+mi*60+se
end
----------------------------------------------------------------------------------------------------------------------------------------------
function ReadFile()
	local handle = openfile(ATWFolder.."/"..ASCIIFile, "r")
	if handle then
		local contents = gsub(read(handle, "*a"),strchar(10), "\r\n")
		closefile (handle)
		return contents
	end
end

SMF spam blocked by CleanTalk