sparuj Posted October 15, 2020 Posted October 15, 2020 Hello everyone, This seems out of the world thing for me and would like to ask for help if possible. The thing that I want to accomplish is to set a script that can check what day is today depending on the timezone, for example EDT and move the files in folders accordingly. Something like this: Launch the script > check what day it is today by using timeanddate's website or something else (not my pc) > Move filename.jpg to /Thursday/filename.jpg | filename2.jpg to /Friday/filename2.jpg | filename3.jpg to /Sunday/filename3.jpg and so on... Is something like this actually possible? Cheers!
mikell Posted October 15, 2020 Posted October 15, 2020 Yes of course it is Just use InetRead with a simple free time API (for example worldtimeapi.org) to get the time in json or txt format, then build a pretty little code to achieve the rest using the integrated AutoIt functions
JockoDundee Posted October 15, 2020 Posted October 15, 2020 @TheXman has some code that will pull time from a NTP server. is your reason for not relying on your pc clock because of accuracy issues or because you need to retrieve time for arbitrary time zones? Code hard, but don’t hard code...
sparuj Posted October 15, 2020 Author Posted October 15, 2020 Thank you for the help guys. I'll see what I can do. @JockoDundee, on second thought I don't mind using my pc if it's possible to set a different timezone for the script, since I would like to use the timezone where I live on my pc.
Guest Posted October 15, 2020 Posted October 15, 2020 57 minutes ago, sparuj said: set a different timezone for the script Here is an example which takes up the suggestion of @mikell (using worldtimeapi.org) : Global $aDay[8] = [7, "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"] Global $sWorldTimeAPIResponse, $aDayOfTheWeek, $iError = 0 ; full list of timezones, see ==> http://worldtimeapi.org/timezones $sWorldTimeAPIResponse = GetDateFromWorldTimeAPI('Europe/Berlin') If @error Then ConsoleWrite("Error connecting to the internet!" & @CRLF) Else $aDayOfTheWeek = StringRegExp($sWorldTimeAPIResponse,"(?i)\Qday_of_week: \E(\d)", 3) MsgBox(0, 'Day : ', 'Day of the week = ' & $aDay[$aDayOfTheWeek[0]] & @CRLF) MsgBox(0, 'Full Response : ', $sWorldTimeAPIResponse) ; *** only for test EndIf Func GetDateFromWorldTimeAPI($sTimezone, $bProxy = False, $sProxy = "", $sURL = "http://worldtimeapi.org/api/timezone/") Local $oHTTP = ObjCreate("winhttp.winhttprequest.5.1") If $iError Then Return SetError(1, 0, 0) If $bProxy Then $oHttp.SetProxy(2, $sProxy) $oHTTP.Open("GET", $sURL & $sTimezone & '.txt', False) $oHTTP.Send() If $iError Then Return SetError(2, 0, 0) Local $sDate = $oHTTP.ResponseText $oHTTP = Null Return $sDate EndFunc
JockoDundee Posted October 15, 2020 Posted October 15, 2020 2 hours ago, sparuj said: on second thought I don't mind using my pc if it's possible to set a different timezone for the script, since I would like to use the timezone where I live on my pc. How do you intend to specify which time zone the script should be using at any moment? by time zone code, or description, or a bias from UTC, or other? Code hard, but don’t hard code...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now