September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,39 +0,0 @@
|
|||
http = require 'http'
|
||||
|
||||
CONFIG =
|
||||
host: 'tycho.usno.navy.mil'
|
||||
path: '/cgi-bin/timer.pl'
|
||||
|
||||
# Web scraping code tends to be brittle, and this is no exception.
|
||||
# The tycho time page does not use highly structured markup, so
|
||||
# we do a real dirty scrape.
|
||||
scrape_tycho_ust_time = (text) ->
|
||||
for line in text.split '\n'
|
||||
matches = line.match /(.*:\d\d UTC)/
|
||||
if matches
|
||||
console.log matches[0].replace '<BR>', ''
|
||||
return
|
||||
throw Error("unscrapable page!")
|
||||
|
||||
# This is low-level-ish code to get data from a URL. It's
|
||||
# pretty general purpose, so you'd normally tuck this away
|
||||
# in a library (or use somebody else's library).
|
||||
wget = (host, path, cb) ->
|
||||
options =
|
||||
host: host
|
||||
path: path
|
||||
headers:
|
||||
"Cache-Control": "max-age=0"
|
||||
|
||||
req = http.request options, (res) ->
|
||||
s = ''
|
||||
res.on 'data', (chunk) ->
|
||||
s += chunk
|
||||
res.on 'end', ->
|
||||
cb s
|
||||
req.end()
|
||||
|
||||
# Do our web scrape
|
||||
do ->
|
||||
wget CONFIG.host, CONFIG.path, (data) ->
|
||||
scrape_tycho_ust_time data
|
||||
|
|
@ -1,2 +0,0 @@
|
|||
> coffee web_scrape.coffee
|
||||
Jan. 09, 19:19:07 UTC
|
||||
17
Task/Web-scraping/Gambas/web-scraping.gambas
Normal file
17
Task/Web-scraping/Gambas/web-scraping.gambas
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
Public Sub Main()
|
||||
Dim sWeb, sTemp, sOutput As String 'Variables
|
||||
|
||||
Shell "wget -O /tmp/web http://tycho.usno.navy.mil/cgi-bin/timer.pl" Wait 'Use 'wget' to save the web file in /tmp/
|
||||
|
||||
sWeb = File.Load("/tmp/web") 'Open file and store in sWeb
|
||||
|
||||
For Each sTemp In Split(sWeb, gb.NewLine) 'Split the file by NewLines..
|
||||
If InStr(sTemp, "UTC") Then 'If the line contains "UTC" then..
|
||||
sOutPut = sTemp 'Extract the line into sOutput
|
||||
Break 'Get out of here
|
||||
End If
|
||||
Next
|
||||
|
||||
Print Mid(sOutput, 5) 'Print the result without the '<BR>' tag
|
||||
|
||||
End
|
||||
19
Task/Web-scraping/Kotlin/web-scraping.kotlin
Normal file
19
Task/Web-scraping/Kotlin/web-scraping.kotlin
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
// version 1.1.3
|
||||
|
||||
import java.net.URL
|
||||
import java.io.InputStreamReader
|
||||
import java.util.Scanner
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val url = URL("http://tycho.usno.navy.mil/cgi-bin/timer.pl")
|
||||
val isr = InputStreamReader(url.openStream())
|
||||
val sc = Scanner(isr)
|
||||
while (sc.hasNextLine()) {
|
||||
val line = sc.nextLine()
|
||||
if ("UTC" in line) {
|
||||
println(line.drop(4).take(17))
|
||||
break
|
||||
}
|
||||
}
|
||||
sc.close()
|
||||
}
|
||||
23
Task/Web-scraping/MIRC-Scripting-Language/web-scraping.mirc
Normal file
23
Task/Web-scraping/MIRC-Scripting-Language/web-scraping.mirc
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
alias utc {
|
||||
sockclose UTC
|
||||
sockopen UTC tycho.usno.navy.mil 80
|
||||
}
|
||||
|
||||
on *:SOCKOPEN:UTC: {
|
||||
sockwrite -n UTC GET /cgi-bin/timer.pl HTTP/1.1
|
||||
sockwrite -n UTC Host: tycho.usno.navy.mil
|
||||
sockwrite UTC $crlf
|
||||
}
|
||||
|
||||
on *:SOCKREAD:UTC: {
|
||||
sockread %UTC
|
||||
while ($sockbr) {
|
||||
if (<BR>*Universal Time iswm %UTC) {
|
||||
echo -ag $remove(%UTC,<BR>,$chr(9),Universal Time)
|
||||
unset %UTC
|
||||
sockclose UTC
|
||||
return
|
||||
}
|
||||
sockread %UTC
|
||||
}
|
||||
}
|
||||
23
Task/Web-scraping/OoRexx/web-scraping.rexx
Normal file
23
Task/Web-scraping/OoRexx/web-scraping.rexx
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
/* load the RexxcURL library */
|
||||
Call RxFuncAdd 'CurlLoadFuncs', 'rexxcurl', 'CurlLoadFuncs'
|
||||
Call CurlLoadFuncs
|
||||
|
||||
url = "http://tycho.usno.navy.mil/cgi-bin/timer.pl"
|
||||
|
||||
/* get a curl session */
|
||||
curl = CurlInit()
|
||||
if curl \= ''
|
||||
then do
|
||||
call CurlSetopt curl, 'URL', Url
|
||||
if curlerror.intcode \= 0 then exit
|
||||
call curlSetopt curl, 'OUTSTEM', 'stem.'
|
||||
if curlerror.intcode \= 0 then exit
|
||||
call CurlPerform curl
|
||||
|
||||
/* content is in a stem - lets get it all in a string */
|
||||
content = stem.~allItems~makestring('l')
|
||||
/* now parse out utc time */
|
||||
parse var content content 'Universal Time' .
|
||||
utcTime = content~substr(content~lastpos('<BR>') + 4)
|
||||
say utcTime
|
||||
end
|
||||
1
Task/Web-scraping/PowerShell/web-scraping-2.psh
Normal file
1
Task/Web-scraping/PowerShell/web-scraping-2.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
[System.DateTime]::UtcNow
|
||||
1
Task/Web-scraping/PowerShell/web-scraping-3.psh
Normal file
1
Task/Web-scraping/PowerShell/web-scraping-3.psh
Normal file
|
|
@ -0,0 +1 @@
|
|||
[System.DateTime]::Now
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
<@ DEFAREPRS>Rexx Parse</@>
|
||||
<@ DEFPRSLIT>Rexx Parse|'<BR>' UTCtime 'UTC'</@>
|
||||
<@ LETVARURL>timer|http://tycho.usno.navy.mil/cgi-bin/timer.pl</@>
|
||||
<@ ACTRPNPRSVAR>Rexx Parse|timer</@>
|
||||
<@ SAYVAR>UTCtime</@>
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
<# DEFINE WORKAREA PARSEVALUES>Rexx Parse</#>
|
||||
<# DEFINE PARSEVALUES LITERAL>Rexx Parse|'<BR>' UTCtime 'UTC'</#>
|
||||
<# LET VARIABLE URLSOURCE>timer|http://tycho.usno.navy.mil/cgi-bin/timer.pl</#>
|
||||
<# ACT REPLACEBYPATTERN PARSEVALUES VARIABLE>Rexx Parse|timer</#>
|
||||
<# SAY VARIABLE>UTCtime</#>
|
||||
|
|
@ -1 +0,0 @@
|
|||
<@ SAY AFT BEF URL LIT LIT LIT >http://tycho.usno.navy.mil/cgi-bin/timer.pl| UTC|<BR></@>
|
||||
14
Task/Web-scraping/Zkl/web-scraping.zkl
Normal file
14
Task/Web-scraping/Zkl/web-scraping.zkl
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
const HOST="tycho.usno.navy.mil", PORT=80, dir="/cgi-bin/timer.pl";
|
||||
get:="GET %s HTTP/1.0\r\nHost: %s:%s\r\n\r\n".fmt(dir,HOST,PORT);
|
||||
server:=Network.TCPClientSocket.connectTo(HOST,PORT);
|
||||
server.write(get); // send request to web serer
|
||||
data:=server.read(True); // read data from web server
|
||||
|
||||
data.seek(data.find("UTC")); // middle of line
|
||||
c:=data.seek(Void,0); // start of line
|
||||
line:=data[c,data.seek(Void,1)-c].text;
|
||||
line.print(); // the HTML UTC line
|
||||
|
||||
re:=RegExp(0'|.*(\d\d:\d\d:\d\d)|); // get time
|
||||
re.search(line);
|
||||
re.matched[1].println();
|
||||
Loading…
Add table
Add a link
Reference in a new issue