update for new api
parent
94a1b78664
commit
996c7778c7
|
@ -1,141 +1,140 @@
|
||||||
USING: urls pcre sequences accessors kernel assocs parser quotations combinators.short-circuit regexp arrays unicode ;
|
USING: urls pcre sequences accessors kernel assocs parser quotations combinators.short-circuit regexp arrays unicode math ;
|
||||||
|
USING: combinators ;
|
||||||
FROM: regexp => matches? ;
|
FROM: regexp => matches? ;
|
||||||
USING: xml.syntax xml.writer ;
|
USING: xml.syntax xml.writer ;
|
||||||
USING: io io.streams.string ;
|
USING: json ;
|
||||||
|
USING: io io.streams.string io.encodings.utf8 io.encodings.string ;
|
||||||
USING: math.parser math.text.english ;
|
USING: math.parser math.text.english ;
|
||||||
USING: calendar calendar.english calendar.format ;
|
USING: calendar calendar.english calendar.format calendar.parser ;
|
||||||
USING: html.parser html.parser.analyzer ;
|
USING: html.parser html.parser.analyzer ;
|
||||||
USING: http.client ;
|
USING: http.client ;
|
||||||
|
|
||||||
USING: triangle-beer-league.entities ;
|
|
||||||
|
|
||||||
IN: triangle-beer-league.daysmart
|
IN: triangle-beer-league.daysmart
|
||||||
|
|
||||||
CONSTANT: daysmart-base-url URL" https://apps.daysmartrecreation.com/dash/index.php?company=dreamsports"
|
TUPLE: team
|
||||||
CONSTANT: datetime-regex "^(?<month>\\w{3}) (?<day>\\d{0,2}).{7}(?<hour>\\d{0,2}):(?<minute>\\d{0,2}) (?<ampm>[ap]m)$"
|
id color ;
|
||||||
|
|
||||||
: tbl-team-name? ( name -- ? )
|
TUPLE: game-summary ot? home-score away-score ;
|
||||||
R/ (maroon|white|blue|teal|green|yellow|light blue|red|orange|black)$/i matches? ;
|
|
||||||
|
|
||||||
: normalize-team-name ( name -- name' )
|
TUPLE: team-schedule
|
||||||
>lower R/ \s*team$/i "" re-replace ;
|
start end home away summary ;
|
||||||
|
|
||||||
! turns something like "Aug 23rd Wed 8:20 pm" into a timestamp
|
CONSTANT: teams
|
||||||
: parse-daysmart-schedule-time ( string -- timestamp )
|
{
|
||||||
datetime-regex findall
|
T{ team f 26398 "green" }
|
||||||
first
|
T{ team f 26400 "maroon" }
|
||||||
[
|
T{ team f 26396 "white" }
|
||||||
[ now year>> swap "month" of month-abbreviation-index ]
|
T{ team f 26397 "blue" }
|
||||||
[ "day" of string>number ] bi <date>
|
T{ team f 26403 "teal" }
|
||||||
]
|
T{ team f 26404 "yellow" }
|
||||||
[
|
T{ team f 26399 "light blue" }
|
||||||
[ "hour" of string>number ]
|
T{ team f 26402 "red" }
|
||||||
[ "minute" of string>number ]
|
T{ team f 26401 "orange" }
|
||||||
[ "ampm" of ] tri
|
T{ team f 26395 "black" }
|
||||||
] bi
|
}
|
||||||
[ 0 set-time dup hour>> ] dip
|
|
||||||
parse-word 1quotation call( ts h -- ts' ) ;
|
|
||||||
|
|
||||||
! TODO team schedules
|
CONSTANT: tbl-league-id 6551
|
||||||
! dup [ "event__date" html-class? ] find-between-all [ trim-text [ { [ name>> text = ] [ text>> empty? not ] } 1&& ] filter 2 swap remove-nth " " join ] map
|
|
||||||
: parse-team-schedule-response ( vector -- schedules )
|
|
||||||
[ "event__date" html-class? ] find-between-all
|
|
||||||
[ trim-text [ { [ name>> text = ] [ text>> empty? not ] } 1&& ] filter
|
|
||||||
2 swap remove-nth [ text>> ] map " " join ] map ;
|
|
||||||
|
|
||||||
: parse-schedule-response ( vector -- schedules )
|
CONSTANT: daysmart-base-url URL" https://apps.daysmartrecreation.com/dash/jsonapi/api/v1/"
|
||||||
[ "list-group-item" html-class? ] find-between-all
|
|
||||||
[
|
|
||||||
remove-blank-text trim-text
|
|
||||||
[ name>> text = ] filter
|
|
||||||
[ text>> ] map
|
|
||||||
[ first R/ \s*Game$/ "" re-replace ]
|
|
||||||
[ second ] [ fourth ] tri [ normalize-team-name ] bi@ team-schedule boa
|
|
||||||
] { } map-as
|
|
||||||
[ home>> tbl-team-name? ] filter ;
|
|
||||||
|
|
||||||
: <daysmart-url> ( action -- url )
|
: timestamp>filter-string ( timestamp -- str )
|
||||||
daysmart-base-url swap "Action" set-query-param ;
|
[ { YYYY-MM-DD " " hh:mm:ss } formatted ]
|
||||||
|
with-string-writer ;
|
||||||
|
|
||||||
: <daysmart-team-url> ( team-id -- url )
|
: relative-hh ( timestamp -- )
|
||||||
"team/index" <daysmart-url> swap "teamid" set-query-param ;
|
hour>> 12 mod write-00 ;
|
||||||
|
|
||||||
: <daysmart-schedule-url> ( -- url )
|
: timestamp>relative-hh:mm ( timestamp -- str )
|
||||||
"Schedule/location" <daysmart-url> ;
|
[ { relative-hh ":" mm } formatted ]
|
||||||
|
with-string-writer ;
|
||||||
|
|
||||||
: <daysmart-schedule-form-data> ( datetime -- assoc )
|
! look up a team by id in the teams sequence
|
||||||
[ { MM "/" DD "/" YYYY } formatted ] with-string-writer dup
|
: <tbl-team> ( id -- team )
|
||||||
|
teams [ id>> = ] with find nip ;
|
||||||
|
|
||||||
|
: tbl-game-events-params ( start end -- assoc )
|
||||||
|
[ timestamp>filter-string ] bi@
|
||||||
|
tbl-league-id
|
||||||
'{
|
'{
|
||||||
{ "startDate" _ }
|
{ "cache" f }
|
||||||
{ "endDate" _ }
|
{ "sort" "start" }
|
||||||
{ "facilityId" "1" } ! apex
|
{ "company" "dreamsports" }
|
||||||
{ "eventType" "g" } ! game types
|
{ "include" "resource.facility,homeTeam.league,visitingTeam.league,eventType" }
|
||||||
{ "run" "true" } ! no idea
|
{ "filter[start__gte]" _ }
|
||||||
|
{ "filter[end__lte]" _ }
|
||||||
|
{ "filter[homeTeam.league_id]" _ }
|
||||||
} ;
|
} ;
|
||||||
|
|
||||||
: <daysmart-schedule-request> ( datetime -- vector )
|
! maps the league event data to a list of team schedules
|
||||||
<daysmart-schedule-form-data> <daysmart-schedule-url> <post-request>
|
: tbl-game-events>team-schedules ( events -- team-schedules )
|
||||||
http-request nip parse-html ;
|
[
|
||||||
|
"attributes" of
|
||||||
|
{
|
||||||
|
[ "start" of rfc3339>timestamp ]
|
||||||
|
[ "end" of rfc3339>timestamp ]
|
||||||
|
[ "hteam_id" of <tbl-team> ]
|
||||||
|
[ "vteam_id" of <tbl-team> ]
|
||||||
|
[ "is_overtime" of ]
|
||||||
|
[ "hscore" of ]
|
||||||
|
[ "vscore" of ]
|
||||||
|
} cleave
|
||||||
|
dup json-null? [ 3drop f ] [ [ number>string ] bi@ game-summary boa ] if
|
||||||
|
team-schedule boa
|
||||||
|
] { } map-as ;
|
||||||
|
|
||||||
: <daysmart-request> ( url -- response )
|
: <tbl-events-url> ( params -- url )
|
||||||
<get-request> http-request nip parse-html ;
|
[ daysmart-base-url URL" events" derive-url ] dip set-query-params ;
|
||||||
|
|
||||||
: <daysmart-team-request> ( team-id -- response )
|
: tbl-game-events ( params -- seq )
|
||||||
<daysmart-team-url> scrape-html nip ;
|
<tbl-events-url> http-get nip utf8 decode json> "data" of ;
|
||||||
|
|
||||||
: tbl-games ( -- assoc )
|
: tbl-game-schedules ( -- assoc )
|
||||||
now [ wednesday ] [ thursday ] bi 2array dup
|
now [ wednesday midnight ] [ thursday end-of-day ] bi 2dup [ 2array ] 2dip
|
||||||
[ <daysmart-schedule-request> parse-schedule-response ] map
|
tbl-game-events-params tbl-game-events tbl-game-events>team-schedules
|
||||||
zip ;
|
[ start>> wednesday? ] partition 2array zip ;
|
||||||
|
|
||||||
: render-day-header ( timestamp -- xml )
|
! : render-day-header ( timestamp -- xml )
|
||||||
[ day-of-week day-name ]
|
! [ day-of-week day-name ]
|
||||||
[ month>> month-name ]
|
! [ month>> month-name ]
|
||||||
[ day>> dup number>string swap ordinal-suffix append ] tri
|
! [ day>> dup number>string swap ordinal-suffix append ] tri
|
||||||
[XML
|
! [XML
|
||||||
<h1 class="day-header">
|
! <h1 class="day-header">
|
||||||
<span class="day-name"><-></span>
|
! <span class="day-name"><-></span>
|
||||||
<span class="month"><-></span>
|
! <span class="month"><-></span>
|
||||||
<span class="day"><-></span>
|
! <span class="day"><-></span>
|
||||||
</h1>
|
! </h1>
|
||||||
XML] ;
|
! XML] ;
|
||||||
|
!
|
||||||
: render-team-times ( schedule -- xml )
|
!
|
||||||
[ away>> [ "team " prepend ] keep ]
|
! : render-team-times ( schedule -- xml )
|
||||||
[ home>> [ "team " prepend ] keep ]
|
! [ away>> color>> [ "team " prepend ] keep ]
|
||||||
[ start>> ] tri
|
! [ home>> color>> [ "team " prepend ] keep ]
|
||||||
[XML
|
! [ team-schedule>time-string ] tri
|
||||||
<div class="team-times">
|
! [XML
|
||||||
<span class="at">@</span>
|
! <div class="team-times">
|
||||||
<div class="teams">
|
! <span class="at">@</span>
|
||||||
<span class=<->><-></span>
|
! <div class="teams">
|
||||||
<span class=<->><-></span>
|
! <span class=<->><-></span>
|
||||||
</div>
|
! <span class=<->><-></span>
|
||||||
<div class="time"><-></div>
|
! </div>
|
||||||
</div>
|
! <div class="time"><-></div>
|
||||||
XML] ;
|
! </div>
|
||||||
|
! XML] ;
|
||||||
: render-no-games ( -- xml )
|
!
|
||||||
[XML
|
! : render-no-games ( -- xml )
|
||||||
<div class="team-times"><div class="none">No Scheduled TBL games</div></div>
|
! [XML <div class="team-times"><div class="none">No Scheduled TBL games</div></div> XML] ;
|
||||||
XML] ;
|
!
|
||||||
|
! : render-day-schedule ( assoc -- xml )
|
||||||
: render-day-schedule ( assoc -- xml )
|
! [ first render-day-header ]
|
||||||
[ first render-day-header ]
|
! [ second
|
||||||
[ second
|
! dup empty?
|
||||||
dup empty?
|
! [ drop render-no-games ]
|
||||||
[ drop render-no-games ]
|
! [ [ render-team-times ] map ] if
|
||||||
[ [ render-team-times ] map ] if
|
! ] bi
|
||||||
] bi
|
! [XML <section class="game"> <-> <-> </section> XML] ;
|
||||||
[XML
|
!
|
||||||
<section class="game">
|
! : tbl-games? ( -- ? )
|
||||||
<->
|
! tbl-games empty? not ;
|
||||||
<->
|
!
|
||||||
</section>
|
! : render-schedule ( -- )
|
||||||
XML] ;
|
! tbl-games [ render-day-schedule pprint-xml ] each ;
|
||||||
|
|
||||||
: tbl-games? ( -- ? )
|
|
||||||
tbl-games empty? not ;
|
|
||||||
|
|
||||||
: render-schedule ( -- )
|
|
||||||
tbl-games [ render-day-schedule pprint-xml ] each ;
|
|
||||||
|
|
|
@ -3,14 +3,19 @@
|
||||||
<t:bind-each t:name="schedule">
|
<t:bind-each t:name="schedule">
|
||||||
<section class="game">
|
<section class="game">
|
||||||
<h1 class="day-header"><t:label t:name="header"/></h1>
|
<h1 class="day-header"><t:label t:name="header"/></h1>
|
||||||
<t:bind-each t:name="schedules">
|
<t:bind-each t:name="games">
|
||||||
<div class="team-times">
|
<div class="team-times">
|
||||||
<div class="teams">
|
<div class="teams">
|
||||||
<span class="@away"><t:label t:name="away"/></span>
|
<span class="@away"><t:label t:name="away"/></span>
|
||||||
<span class="at">@</span>
|
<span class="at">@</span>
|
||||||
<span class="@home"><t:label t:name="home"/></span>
|
<span class="@home"><t:label t:name="home"/></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="time"><t:label t:name="start"/></div>
|
<t:if t:value="show-times?">
|
||||||
|
<div class="time"><t:label t:name="start-time"/></div>
|
||||||
|
</t:if>
|
||||||
|
<t:if t:value="show-summary?">
|
||||||
|
<div class="time"><t:label t:name="summary"/></div>
|
||||||
|
</t:if>
|
||||||
</div>
|
</div>
|
||||||
</t:bind-each>
|
</t:bind-each>
|
||||||
</section>
|
</section>
|
||||||
|
|
|
@ -102,7 +102,7 @@ main {
|
||||||
border-right: .25em solid red; }
|
border-right: .25em solid red; }
|
||||||
main table tr td.team.blue {
|
main table tr td.team.blue {
|
||||||
border-right: .25em solid blue; }
|
border-right: .25em solid blue; }
|
||||||
main table tr td.team.light-blue {
|
main table tr td.team.light td.team.blue {
|
||||||
border-right: .25em solid lightblue; }
|
border-right: .25em solid lightblue; }
|
||||||
main table tr td.team.orange {
|
main table tr td.team.orange {
|
||||||
border-right: .25em solid orange; }
|
border-right: .25em solid orange; }
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
USING: accessors namespaces kernel sequences arrays urls present farkup ;
|
USING: accessors namespaces kernel sequences arrays urls present farkup combinators classes ;
|
||||||
USING: math.parser math.text.english ;
|
USING: math.parser math.text.english ;
|
||||||
USING: io.sockets.secure io.servers ;
|
USING: io.sockets.secure io.servers ;
|
||||||
USING: furnace.actions furnace.boilerplate furnace.utilities furnace.chloe-tags ;
|
USING: furnace.actions furnace.boilerplate furnace.utilities furnace.chloe-tags ;
|
||||||
|
@ -12,14 +12,16 @@ IN: triangle-beer-league
|
||||||
|
|
||||||
SYMBOLS: key-password key-file dh-file ;
|
SYMBOLS: key-password key-file dh-file ;
|
||||||
|
|
||||||
! DTO
|
! DTOs
|
||||||
TUPLE: schedule header schedules ;
|
TUPLE: game start-time home away summary show-summary? show-times? ;
|
||||||
|
TUPLE: schedule header games ;
|
||||||
|
|
||||||
TUPLE: tbl < dispatcher ;
|
TUPLE: tbl < dispatcher ;
|
||||||
|
|
||||||
: <splash-action> ( -- action )
|
: team-schedule>time-string ( schedule -- str )
|
||||||
<page-action>
|
[ start>> ] [ end>> ] bi
|
||||||
{ tbl "tbl" } >>template ;
|
[ timestamp>relative-hh:mm "pm" append ] bi@
|
||||||
|
2array " - " join ;
|
||||||
|
|
||||||
: timestamp>day-header ( timestamp -- str )
|
: timestamp>day-header ( timestamp -- str )
|
||||||
[ day-of-week day-name ]
|
[ day-of-week day-name ]
|
||||||
|
@ -27,14 +29,37 @@ TUPLE: tbl < dispatcher ;
|
||||||
[ day>> dup number>string swap ordinal-suffix append ] tri
|
[ day>> dup number>string swap ordinal-suffix append ] tri
|
||||||
3array " " join ;
|
3array " " join ;
|
||||||
|
|
||||||
|
: summary>string ( summary -- str )
|
||||||
|
[
|
||||||
|
[ away-score>> ] [ home-score>> ] bi 2array " - " join
|
||||||
|
]
|
||||||
|
[ "" ] if* ;
|
||||||
|
|
||||||
|
: tbl-game-schedules>tbl-games ( game-schedules -- games )
|
||||||
|
[
|
||||||
|
{
|
||||||
|
[ team-schedule>time-string ]
|
||||||
|
[ home>> color>> ]
|
||||||
|
[ away>> color>> ]
|
||||||
|
[ summary>> summary>string ]
|
||||||
|
} cleave dup empty? not dup not game boa
|
||||||
|
] map ;
|
||||||
|
|
||||||
: tbl-games>schedule ( game-schedules -- schedules )
|
: tbl-games>schedule ( game-schedules -- schedules )
|
||||||
[ [ first timestamp>day-header ] [ second ] bi schedule boa ] map ;
|
[
|
||||||
|
[ first timestamp>day-header ]
|
||||||
|
[ second tbl-game-schedules>tbl-games ] bi schedule boa
|
||||||
|
] map ;
|
||||||
|
|
||||||
|
: <splash-action> ( -- action )
|
||||||
|
<page-action>
|
||||||
|
{ tbl "tbl" } >>template ;
|
||||||
|
|
||||||
: <schedule-action> ( -- action )
|
: <schedule-action> ( -- action )
|
||||||
<page-action>
|
<page-action>
|
||||||
[
|
[
|
||||||
t "show-header?" set-value
|
t "show-header?" set-value
|
||||||
tbl-games tbl-games>schedule "schedule" set-value
|
tbl-game-schedules tbl-games>schedule "schedule" set-value
|
||||||
] >>init
|
] >>init
|
||||||
{ tbl "schedule" } >>template ;
|
{ tbl "schedule" } >>template ;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue