Skip to content

Commit 0e234bc

Browse files
committed
fix(event scrape): simplify bookings parsing
1 parent 934633c commit 0e234bc

File tree

2 files changed

+8
-13
lines changed

2 files changed

+8
-13
lines changed

drivers/place/event_scrape.cr

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ class Place::EventScrape < PlaceOS::Driver
66

77
default_settings({
88
zone_ids: ["placeos-zone-id"],
9-
internal_domains: ["PlaceOS.com"],
10-
poll_interval: 5
9+
internal_domains: ["PlaceOS.com"]
1110
})
1211

1312
accessor staff_api : StaffAPI_1
1413

1514
@zone_ids = [] of String
1615
@internal_domains = [] of String
17-
@poll_interval : Time::Span = 5.minutes
1816

1917
alias Event = PlaceCalendar::Event
2018

@@ -30,24 +28,19 @@ class Place::EventScrape < PlaceOS::Driver
3028
end
3129

3230
def on_update
33-
schedule.clear
34-
3531
@zone_ids = setting?(Array(String), :zone_ids) || [] of String
3632
@internal_domains = setting?(Array(String), :internal_domains) || [] of String
37-
@poll_interval = (setting?(UInt32, :poll_interval) || 5).minutes
3833
end
3934

40-
def get_bookings
35+
def todays_bookings
4136
response = {
4237
internal_domains: @internal_domains,
4338
systems: {} of String => SystemWithEvents
4439
}
4540

46-
logger.debug { "Getting bookings for zones" }
47-
logger.debug { @zone_ids.inspect }
48-
49-
start_epoch = Time.utc.at_beginning_of_day.to_unix
50-
end_epoch = start_epoch + 86400 # seconds in a day
41+
now = Time.local
42+
start_epoch = now.at_beginning_of_day.to_unix
43+
end_epoch = now.at_end_of_day.to_unix
5144

5245
@zone_ids.each do |z_id|
5346
staff_api.systems(zone_id: z_id).get.as_a.each do |sys|
@@ -70,7 +63,7 @@ class Place::EventScrape < PlaceOS::Driver
7063
booking_module = staff_api.modules_from_system(sys_id).get.as_a.find { |mod| mod["name"] == "Bookings" }
7164
# If the system has a booking module with bookings
7265
if booking_module && (bookings = staff_api.get_module_state(booking_module["id"].as_s).get["bookings"]?)
73-
bookings = JSON.parse(bookings.as_s).as_a.map { |b| Event.from_json(b.to_json) }
66+
bookings = Array(Event).from_json(bookings.as_s)
7467

7568
# If both start_epoch and end_epoch are passed
7669
if start_epoch && end_epoch

drivers/place/event_scrape_spec.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class StaffAPI < DriverSpecs::MockDriver
1212

1313
sys_1 = {
1414
id: "sys-1",
15+
name: "Room 1",
1516
zones: ["placeos-zone-id"]
1617
}
1718

@@ -22,6 +23,7 @@ class StaffAPI < DriverSpecs::MockDriver
2223
sys_1,
2324
{
2425
id: "sys-2",
26+
name: "Room 2",
2527
zones: ["zone-1"]
2628
}
2729
]

0 commit comments

Comments
 (0)