<commit_before>module RSS
  def self.fetch(url, limit = 10)
    cache_key = 'rss::' + url
    items = Cache.get( cache_key )
    return items if items

    begin
      puts 'fetch rss...'
      response = Net::HTTP.get_response( URI.parse(url) )
      if response.code.to_s != '200'
        return
      end
      rss     = SimpleRSS.parse response.body
      items   = []
      fetched = 0
      rss.items.each { |item|
        record = {
          :id        => item.id,
          :title     => Encode.conv( 'utf8', item.title ),
          :summary   => Encode.conv( 'utf8', item.summary ),
          :link      => item.link,
          :published => item.published
        }<commit_msg>Added support for http redirects.<commit_after>module RSS
  def self.fetch(url, limit = 10)
    cache_key = 'rss::' + url
    items = Cache.get( cache_key )
    return items if items

    begin
      puts 'fetch rss...'
      response = Net::HTTP.get_response( URI.parse(url) )

      # check if redirect is needed
      if response.code.to_s == '301' || response.code.to_s == '302'
        url = response.header['location']
        response = Net::HTTP.get_response( URI.parse( url ) )
      end
      if response.code.to_s != '200'
        raise "Can't fetch '#{url}', http code: #{response.code.to_s}"
        return
      end
      rss     = SimpleRSS.parse response.body
      items   = []
      fetched = 0
      rss.items.each { |item|
        record = {
          :id        => item.id,
          :title     => Encode.conv( 'utf8', item.title ),
          :summary   => Encode.conv( 'utf8', item.summary ),
          :link      => item.link,
          :published => item.published
        }
{'fraction_non_alphanumeric': 0.132858837485172, 'fraction_numerical': 0.013048635824436536, 'mean_word_length': 1.783828382838284, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '700591', 'n_tokens_mistral': 545, 'n_tokens_neox': 522, 'n_words': 130}