ぼざクリタグ広場 https://hub.nizika.monster
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

24 lines
676 B

  1. namespace :nico do
  2. desc 'ニコニコ DB 逆連携'
  3. task export: :environment do
  4. require 'open3'
  5. mysql_user = ENV.fetch('MYSQL_USER')
  6. mysql_pass = ENV.fetch('MYSQL_PASS')
  7. nizika_nico_path = ENV.fetch('NIZIKA_NICO_PATH')
  8. videos = Post.where('url LIKE ?', '%nicovideo.jp/watch/%').pluck(:url).filter_map {
  9. _1[%r{nicovideo\.jp/watch/([^/?#]+)}, 1]
  10. }.uniq
  11. next if videos.empty?
  12. _, stderr, status = Open3.capture3(
  13. { 'MYSQL_USER' => mysql_user, 'MYSQL_PASS' => mysql_pass },
  14. 'python3', '-m', 'tracked_videos.put_bulk_upsert', *videos,
  15. chdir: nizika_nico_path)
  16. raise stderr unless status.success?
  17. end
  18. end