Powered by AppSignal & Oban Pro
Would you like to see your link here? Contact us

Climbs

db/climbs.livemd

Climbs

Section

Mix.install([
  {:req, "~> 0.3.0"}
])
# some kind of for loop
defmodule Climbs do
  def get_url(board) do
    try do
    # Req.get!("https://d.apkpure.net/b/APK/com.auroraclimbing.#{board}", headers: [{"User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"}])    
      response = Req.get!("https://d.cdnpure.com/b/APK/com.auroraclimbing.#{board}?version=latest", headers: [{"User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36"}])
  
      if response.status == 200 do
         temp_dir = System.tmp_dir!()
         apk_file_content = Path.join(temp_dir, "boards.zip")
         IO.inspect(response.body)
         try do 
           File.write!(apk_file_content, response.body)
           IO.puts("it worked????")
           IO.inspect(apk_file_content)
           
           rescue e in RuntimeError ->
           IO.inspect(e)
         end
         IO.puts("writing to temp")
      else
        IO.puts("failed")
      end
    rescue e in RuntimeError ->
      IO.inspect(e)
    end
  end

  def unzip_contents(file_path) do
    case :zip.unzip('/var/folders/cj/y3rxhsps4z10_v1fzgh23jxm0000gn/T/boards.zip') do
      {:ok, _files} -> 
              sqlite_file = "assets/db.sqlite3"
              if File.exists?(sqlite_file) do
                IO.puts("yay it exists!!!!!")
                 File.rename!(sqlite_file, file_path)
              end
              
      {:error, reason} ->
              IO.inspect(reason)
    end
  end
end
board_names = [
  # "auroraboard",
  # "decoyboard",
  # "grasshopperboard",
  "kilterboard",
  # "tensionboard2",
  # "touchstoneboard",
]

Enum.each(board_names, fn climb -> Climbs.get_url(climb); end)
# idk how to make this single quotes bc zip doesn't like double quotes so I hard coded it for now lol
Climbs.unzip_contents("/var/folders/cj/y3rxhsps4z10_v1fzgh23jxm0000gn/T/climbs.sqlite3")