diff --git a/console.sh b/console.sh new file mode 100755 index 0000000..d47ddc5 --- /dev/null +++ b/console.sh @@ -0,0 +1,25 @@ +#!/bin/bash +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +GEMS_DIR="${SCRIPT_DIR}/.gems" +JAVA_OPTS="--enable-native-access=ALL-UNNAMED --enable-native-access=org.jruby.dist" +JRUBY_BIN="/usr/bin/jruby" +JIRB_BIN="/usr/bin/jirb" +JRUBY_OPTIONS="-J-Xms256m -J-Xmx2g" +FILE_TO_LOAD="$1" +# +export GEM_HOME="${GEMS_DIR}" +export GEM_PATH="${GEMS_DIR}" +# +if [ -e "${JIRB_BIN}" ]; then + if [ -e "${SCRIPT_DIR}/${FILE_TO_LOAD}" ]; then + exec env JAVA_OPTS="${JAVA_OPTS}" JRUBY_OPTIONS="${JRUBY_OPTIONS}" "${JIRB_BIN}" -r "${SCRIPT_DIR}/${FILE_TO_LOAD}" + else + exec env JAVA_OPTS="${JAVA_OPTS}" JRUBY_OPTIONS="${JRUBY_OPTIONS}" "${JIRB_BIN}" + fi + exit 0 +else + echo "Error: could not locate ${JIRB_BIN}" + exit 1 +fi diff --git a/fetch_podcasts.rb b/fetch_podcasts.rb index bf4a2b5..ed97d77 100755 --- a/fetch_podcasts.rb +++ b/fetch_podcasts.rb @@ -1,4 +1,4 @@ -#!/usr/bin/env jruby +!#/usr/bin/env jruby # frozen_string_literal: true require "net/http" @@ -7,7 +7,9 @@ require "json" require "digest/sha1" require "sequel" require "nokogiri" - +unless defined?(Nokogiri::XML) + raise Exception.new "Nokogiri did NOT load" +end SCRIPT_DIR = File.expand_path(File.dirname(__FILE__)) CONFIG_PATH = File.join(SCRIPT_DIR, "config.json") @@ -137,14 +139,15 @@ def http_stream_to_file(url, dest_path, user = nil, pass = nil) unless res.is_a?(Net::HTTPSuccess) raise "HTTP #{res.code}: #{res.message}" end - + buffer = ::StringIO.new (res.read_body) + buffer.rewind File.open(tmp_dest, "wb") do |f| - res.read_body { |chunk| f.write(chunk) } + buffer.read() { |chunk| f.write(chunk) } end File.rename(tmp_dest, dest_path) success = true rescue Exception => error - log("ERROR", "Download failed for #{url}: #{error.class}: #{error.message}") + log("ERROR", "Download failed for #{url}: #{error.class}: #{error.message}, Backtrace --> #{error.backtrace}") begin File.delete(tmp_dest) if File.exist?(tmp_dest) rescue StandardError @@ -158,7 +161,7 @@ def parse_feed(opts) file_path = opts[:file_path] || raise("parse_feed: :file_path is required") feed_url = opts[:feed_url] || "" - doc = Nokogiri::XML(File.read(file_path), nil, XML::NO_NETWORK) + doc = Nokogiri::XML(File.read(file_path), nil) channel = doc.at_xpath("//channel") raise "No element found in feed" unless channel @@ -245,7 +248,7 @@ def register_show(show_title, feed_url, archive: false, opml_import: false) opml_import: opml_import ? 1 : 0, created_at: now ) - end + end log("INFO", "Registered: #{title} (#{slug})") true