discourse/script/import_scripts/socialcast/title.rb
Sam Saffron 30990006a9 DEV: enable frozen string literal on all files
This reduces chances of errors where consumers of strings mutate inputs
and reduces memory usage of the app.

Test suite passes now, but there may be some stuff left, so we will run
a few sites on a branch prior to merging
2019-05-13 09:31:32 +08:00

30 lines
879 B
Ruby

# frozen_string_literal: true
require_relative './socialcast_message.rb'
require_relative './socialcast_user.rb'
require 'set'
require File.expand_path(File.dirname(__FILE__) + "/../base.rb")
MESSAGES_DIR = "output/messages"
def titles
topics = 0
total = count_files(MESSAGES_DIR)
Dir.foreach(MESSAGES_DIR) do |filename|
next if filename == ('.') || filename == ('..')
message_json = File.read MESSAGES_DIR + '/' + filename
message = SocialcastMessage.new(message_json)
next unless message.title
#puts "#{filename}, #{message.replies.size}, #{message.topic[:raw].size}, #{message.message_type}, #{message.title}"
puts "[#{message.title}](#{message.url})"
topics += 1
end
puts "", "Imported #{topics} topics. Skipped #{total - topics}."
end
def count_files(path)
Dir.foreach(path).select { |f| f != '.' && f != '..' }.count
end
titles