Community discussions

MikroTik App
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Tool fetch url

Tue Oct 11, 2022 2:42 am

I have the following script made by REXTENDED, it hasn't worked for several weeks, the problem is in "https://showcase.api.linx.twenty57.net/ ... 3Fdate=now" the page doesn't work, you can change for another URL, I leave the script

{
:local intGoff [:tonum [/system clock get gmt-offset]]
:if ($intGoff > 93600) do={:set intGoff ((4294967296 - $intGoff) * -1)}
:local epochNow (([/tool fetch url="https://showcase.api.linx.twenty57.net/UnixTime/tounix\3Fdate=now" as-value output=user])->"data")
:set epochNow [:pick $epochNow 1 ([:len $epochNow] - 1)]
:local upTime [/system resource get uptime]
:local wPos   [:find $upTime "w" -1]
:local dPos   [:find $upTime "d" -1]
:local utLen  [:len $upTime]
:local utSec  [:pick $upTime ($utLen - 2) $utLen]
:local utMin  [:pick $upTime ($utLen - 5) ($utLen - 3)]
:local utHou  [:pick $upTime ($utLen - 8) ($utLen - 6)]
:local utDay  0
:local utWee  0
:if (([:typeof $wPos] = "nil") and ([:typeof $dPos] = "num")) do={:set utDay [:pick $upTime 0 $dPos] }
:if (([:typeof $wPos] = "num") and ([:typeof $dPos] = "num")) do={:set utDay [:pick $upTime ($wPos + 1) $dPos] }
:if ([:typeof $wPos] = "num") do={:set utWee [:pick $upTime 0 $wPos] }
:local totUtSec ($utSec + (60 * $utMin) + (60 * 60 * $utHou) + (60 * 60 * 24 * $utDay) + (60 * 60 * 24 * 7 * $utWee))
:local epochStart ($epochNow - $totUtSec + $intGoff)
:local datetimeStart (([/tool fetch url="https://showcase.api.linx.twenty57.net/UnixTime/fromunix\3Ftimestamp=$epochStart" as-value output=user])->"data")
:set datetimeStart [:pick $datetimeStart 1 ([:len $datetimeStart] - 1)]
:put "RouterBOARD is started $datetimeStart"
}


EL DONCITO.
 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Tool fetch url

Tue Oct 11, 2022 8:21 am

Make a request to MikroTik to implement Epoch time and also to use standard time format (ISO:8601) everywhere in the RouterOS.
Should not need to be dependent of external programs.
 
kangarie
just joined
Posts: 24
Joined: Mon Apr 17, 2017 7:28 am

Re: Tool fetch url

Tue Oct 11, 2022 12:01 pm

 
User avatar
Jotne
Forum Guru
Forum Guru
Posts: 3279
Joined: Sat Dec 24, 2016 11:17 am
Location: Magrathean

Re: Tool fetch url

Tue Oct 11, 2022 2:15 pm

And that do work inside RouterOS?
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Tool fetch url

Tue Oct 11, 2022 7:31 pm

maybe this can be used
completly useless on first use, the URL must return current UNIX timestamp without provide a date,
but can be used on 2nd call for convert timestamp to date
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Tool fetch url

Tue Oct 11, 2022 10:14 pm

Thanks for answering friend REX, and how do I use it in the second call to convert the timestamp to the date, please help me




EL DONCITO.
Last edited by BartoszP on Sun Jan 15, 2023 10:30 pm, edited 1 time in total.
Reason: no need to quote whole previous post ... we can follow the stream of discussion
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Tool fetch url

Wed Oct 12, 2022 1:53 am

If you can't have a timestamp first, how to convert something to date?
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Tool fetch url

Wed Oct 12, 2022 5:52 pm

I understand REX, and you don't have any solution?






EL DONCITO.
 
kangarie
just joined
Posts: 24
Joined: Mon Apr 17, 2017 7:28 am

Re: Tool fetch url

Thu Oct 13, 2022 6:31 pm

to get current timestamp
https://helloacm.com/api/unix-timestamp-converter/?s=now
to convert timestamp to date string
https://helloacm.com/api/unix-timestamp-converter/?s=1665674782
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Tool fetch url

Thu Oct 13, 2022 7:37 pm

to get current timestamp
https://helloacm.com/api/unix-timestamp-converter/?s=now
to convert timestamp to date string
https://helloacm.com/api/unix-timestamp-converter/?s=1665674782
this is the answer
failure: closing connection: <404 Not Found> 104.26.14.89:443 (4)


Thanks for your help kangarie, let's wait to see what answer rextended gives us.



EL DONCITO.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Tool fetch url  [SOLVED]

Fri Oct 14, 2022 12:40 am

I replace all occurrencies of "showcase" on this forum, except this topic, with the correct versions, thanks to @kangarie

The correct version for this topic is:
viewtopic.php?p=930833#p930465

Thanks again to @kangarie
Last edited by rextended on Sat Dec 24, 2022 12:23 pm, edited 6 times in total.
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Tool fetch url

Wed Oct 26, 2022 11:54 pm

REXTENDED,
if the router restarts in the afternoon because it takes the time as if it were in the morning, that is, if the router restarts at 9 am there if it takes the time well (09:00:00), but if it restarts at 3 pm takes the time 03:00:00, what is wrong?

It's 12 hours late.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Tool fetch url

Thu Oct 27, 2022 10:12 am

You right, the remote site have a bug
subtracting 12h to the time, do not show am/pm or the right 24h time

https://helloacm.com/api/unix-timestamp ... 1666314750 "2022-10-21 01:12:30"
https://helloacm.com/api/unix-timestamp ... 1666271550 "2022-10-20 01:12:30" (must be 13:12:30)

I search again another working URL.
Last edited by rextended on Fri Jan 13, 2023 1:21 am, edited 1 time in total.
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Tool fetch url

Sun Oct 30, 2022 7:32 pm

Guys,
does anyone have any url to calculate in UNIX time.
Thanks for the help.
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Tool fetch url

Wed Nov 16, 2022 8:07 pm

Someone got a url.
 
kangarie
just joined
Posts: 24
Joined: Mon Apr 17, 2017 7:28 am

Re: Tool fetch url

Thu Nov 17, 2022 3:42 am

from timestamp
 https://api.kangarie.com/time/str/1666314750 
from date string
 https://api.kangarie.com/time/str/2022-10-22%2001:12:30 
hope this will worked
 
kangarie
just joined
Posts: 24
Joined: Mon Apr 17, 2017 7:28 am

Re: Tool fetch url

Thu Nov 17, 2022 4:27 am

new code will be

{
:local intGoff [:tonum [/system clock get gmt-offset]]
:if ($intGoff > 93600) do={:set intGoff ((4294967296 - $intGoff) * -1)}
:local epochNow (([/tool fetch url="https://api.kangarie.com/time/str/now" as-value output=user])->"data")
:local upTime [/system resource get uptime]
:local wPos   [:find $upTime "w" -1]
:local dPos   [:find $upTime "d" -1]
:local utLen  [:len $upTime]
:local utSec  [:pick $upTime ($utLen - 2) $utLen]
:local utMin  [:pick $upTime ($utLen - 5) ($utLen - 3)]
:local utHou  [:pick $upTime ($utLen - 8) ($utLen - 6)]
:local utDay  0
:local utWee  0
:if (([:typeof $wPos] = "nil") and ([:typeof $dPos] = "num")) do={:set utDay [:pick $upTime 0 $dPos] }
:if (([:typeof $wPos] = "num") and ([:typeof $dPos] = "num")) do={:set utDay [:pick $upTime ($wPos + 1) $dPos] }
:if ([:typeof $wPos] = "num") do={:set utWee [:pick $upTime 0 $wPos] }
:local totUtSec ($utSec + (60 * $utMin) + (60 * 60 * $utHou) + (60 * 60 * 24 * $utDay) + (60 * 60 * 24 * 7 * $utWee))
:local epochStart ($epochNow - $totUtSec + $intGoff)
:local datetimeStart (([/tool fetch url="https://api.kangarie.com/time/str/$epochStart" as-value output=user])->"data")
:put "RouterBOARD is started $datetimeStart"
}

 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Tool fetch url

Thu Nov 17, 2022 1:42 pm

new code will be
thanks it's working

updated the script:
viewtopic.php?p=961763#p961763
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Tool fetch url

Thu Nov 17, 2022 3:31 pm

Thanks again to @kangarie and @Rextended.
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Tool fetch url

Wed Jan 11, 2023 4:05 pm

Again the same problem with the URL, does anyone have one please.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Tool fetch url

Wed Jan 11, 2023 4:13 pm

For me works, you are banned because you use too much the service?
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Tool fetch url

Wed Jan 11, 2023 4:19 pm

works, but has a 07-hour advance
Last edited by eldoncito2019 on Wed Jan 11, 2023 5:58 pm, edited 1 time in total.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Tool fetch url

Wed Jan 11, 2023 4:26 pm

(be more precise next time...)

Probably the remote PC have lost sync on time, contact me@kangarie.com
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Tool fetch url

Wed Jan 11, 2023 4:53 pm

I'll wait to see what @kangarie responds.
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Tool fetch url

Fri Jan 13, 2023 12:56 am

Continue on original topic here:
viewtopic.php?t=185616
 
kangarie
just joined
Posts: 24
Joined: Mon Apr 17, 2017 7:28 am

Re: Tool fetch url

Fri Jan 13, 2023 3:31 am

hmm, the different 7 hours i think because my server is on Jakarta, which is GMT+7

i've modify my script, please check on your side
 
User avatar
rextended
Forum Guru
Forum Guru
Posts: 11968
Joined: Tue Feb 25, 2014 12:49 pm
Location: Italy
Contact:

Re: Tool fetch url

Fri Jan 13, 2023 4:17 am

now is synced, thanks!
 
eldoncito2019
Member
Member
Topic Author
Posts: 332
Joined: Fri Jun 14, 2019 1:07 pm

Re: Tool fetch url

Fri Jan 13, 2023 3:32 pm

now it is synced

Who is online

Users browsing this forum: No registered users and 20 guests