Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/gigex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ defmodule Gigex do
"""

@doc """
Get the latest gigs from Songkick in Berlin
Get the latest gigs from configured sources (songkick, lido, jazzity)

## Example

Expand Down
24 changes: 21 additions & 3 deletions lib/scraper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,36 @@ defmodule Gigex.Scraper do

alias __MODULE__

@spec run_for(site :: :all | :songkick | :lido, opts :: list()) :: concert :: list()
@spec run_for(site :: :all | :songkick | :lido | :jazzity, opts :: list()) :: concert :: list()
def run_for(:all, opts) do
# Get all the gigs from the scrapers and sort them by date so that they
# appear like one stream of data.

Enum.sort_by(
Scraper.Songkick.get(opts) ++ Scraper.Lido.get(opts),
&Date.from_iso8601!(&1.date),
Scraper.Songkick.get(opts) ++ Scraper.Lido.get(opts) ++ Scraper.Jazzity.get(opts),
fn item ->
case Map.get(item, :date) || Map.get(item, "date") do
nil ->
Date.utc_today()

date when is_binary(date) ->
case Date.from_iso8601(date) do
{:ok, d} -> d
_ -> Date.utc_today()
end

%Date{} = d ->
d

_ ->
Date.utc_today()
end
end,
Date
)
end

def run_for(:songkick, opts), do: Scraper.Songkick.get(opts)
def run_for(:lido, opts), do: Scraper.Lido.get(opts)
def run_for(:jazzity, opts), do: Scraper.Jazzity.get(opts)
end
Loading