Sha256: d0fe1845de6b2a9239e9552eca1ad5d005aaccdaa92f813f828fceb26daf2bfb

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

# -*- coding: utf-8 -*-
require 'arxutils'
require 'arxutils/store'
require 'csv'
require 'pp'
require 'feedlr'
require 'awesome_print'

module Feedlrop
  class Feedlrop
    
    def initialize( token , kind, hs  )
      @oauth_access_token = token
      @dbmgr = Arxutils::Store.init(kind , hs ){ | register_time |
        Dbutil::DbMgr.new( register_time )
      }
      
      @client = Feedlr::Client.new(sandbox: false ,  oauth_access_token: @oauth_access_token)
      @profile = @client.user_profile
      @categories = @client.user_categories
    end

    def get_output_file( ext )
      n = Time.now
      fname = %Q!#{n.year}-#{n.month}-#{n.day}-#{n.hour}-#{n.min}-#{n.sec}.#{ext}!
      File.open( fname , "w")
    end

    def get_all_unread_count
      @categories.each do | x |
        #  f.puts "id=#{x.id.split('/')[-1]}"
        f = true
        if x.class != String
          category_id = x.id.split('/')[-1]
        else
          f = false
        end
        next unless f

        en = @client.user_unread_counts( {:streamId => x.id } )
        en.unreadcounts.each do |y|
          puts "y.id=#{y.id}"
          if y.id =~ /^feed\/(.+)/
            url = $1
            csv_add( category_id , url , y[:count] )
            @dbmgr.add(  category_id , url , y[:count] )
          end
        end
      end
    end

    def print_user_profile
      pp @profile
    end

    def print_subscription
      option = {:plain => true }
      puts @client.user_subscriptions.size
      @client.user_subscriptions.map{|m|  puts m.id}
      puts "==============="
      @client.user_subscriptions.map{|m|  ap m , option }
    end
    
    def csv_open
      @csv = CSV.new(get_output_file("csv") , {
                       :headers => %w!category_id id count!,
                       :write_headers => true
                     } )
    end

    def csv_add(category_id , id , count)
      @csv << [category_id , id , count ]
    end

    def csv_close
      @csv.close
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
feedlrop-0.1.21 lib/feedlrop/feedlrop.rb