-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
57 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
defmodule Mix.Tasks.DownloadCountryDatabase do | ||
use Mix.Task | ||
use Plausible.Repo | ||
require Logger | ||
|
||
# coveralls-ignore-start | ||
|
||
def run(_) do | ||
Application.ensure_all_started(:httpoison) | ||
Application.ensure_all_started(:timex) | ||
this_month = Timex.today() | ||
last_month = Timex.shift(this_month, months: -1) | ||
this_month = this_month |> Date.to_iso8601() |> binary_part(0, 7) | ||
last_month = last_month |> Date.to_iso8601() |> binary_part(0, 7) | ||
this_month_url = "https://download.db-ip.com/free/dbip-country-lite-#{this_month}.mmdb.gz" | ||
last_month_url = "https://download.db-ip.com/free/dbip-country-lite-#{last_month}.mmdb.gz" | ||
Logger.info("Downloading #{this_month_url}") | ||
res = HTTPoison.get!(this_month_url) | ||
|
||
res = | ||
case res.status_code do | ||
404 -> | ||
Logger.info("Got 404 for #{this_month_url}, trying #{last_month_url}") | ||
HTTPoison.get!(last_month_url) | ||
|
||
_ -> | ||
res | ||
end | ||
|
||
if res.status_code == 200 do | ||
File.mkdir("priv/geodb") | ||
File.write!("priv/geodb/dbip-country.mmdb", res.body) | ||
Logger.info("Downloaded and saved the database successfully") | ||
else | ||
Logger.error("Unable to download and save the database. Response: #{inspect(res)}") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
</div> | ||
<% end %> | ||
<div class="pt-6"></div> | ||
<div id="stats-react-container" data-domain="<%= @site.domain %>" data-offset="<%= Timex.Timezone.total_offset(Timex.Timezone.get(@site.timezone)) %>" data-has-goals="<%= @has_goals %>" data-logged-in="<%= [email protected][:current_user] %>" data-inserted-at="<%= @site.inserted_at %>" data-shared-link-auth="<%= assigns[:shared_link_auth] %>" data-embedded="<%= @conn.assigns[:embedded] %>" data-background="<%= @conn.assigns[:background] %>"></div> | ||
<div id="stats-react-container" data-domain="<%= @site.domain %>" data-offset="<%= Timex.Timezone.total_offset(Timex.Timezone.get(@site.timezone)) %>" data-has-goals="<%= @has_goals %>" data-logged-in="<%= [email protected][:current_user] %>" data-inserted-at="<%= @site.inserted_at %>" data-shared-link-auth="<%= assigns[:shared_link_auth] %>" data-embedded="<%= @conn.assigns[:embedded] %>" data-background="<%= @conn.assigns[:background] %>" data-selfhosted="<%= Application.get_env(:plausible, :is_selfhost) %>"></div> | ||
<div id="modal_root"></div> | ||
<%= if !@conn.assigns[:current_user] && @conn.assigns[:demo] do %> | ||
<div class="bg-gray-50 dark:bg-gray-850"> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters