Closed spring1018 closed 5 years ago
def get_user_name id return nil if id.nil? user = db.xquery(%| SELECT * FROM users WHERE id = ? |, id).first user['name'] end def htmlify text text ||= '' text .gsub('&', '&') .gsub('<', '<') .gsub('>', '>') .gsub('\'', ''') .gsub('"', '"') .gsub(/#(\S+)(\s|$)/, '<a class="hashtag" href="/hashtag/\1">#\1</a>\2') end end get '/' do @name = get_user_name session[:userId] if @name.nil? @flush = session[:flush] session.clear return erb :index, layout: :layout end url = URI.parse "#{ISUTOMO_ENDPOINT}/#{@name}" req = Net::HTTP::Get.new url.path res = Net::HTTP.start(url.host, url.port) do |http| http.request req end friends = JSON.parse(res.body)['friends'] friends_name = {} @tweets = [] get_all_tweets(params[:until]).each do |row| row['html'] = htmlify row['text'] row['time'] = row['created_at'].strftime '%F %T' friends_name[row['user_id']] ||= get_user_name row['user_id'] row['name'] = friends_name[row['user_id']] @tweets.push row if friends.include? row['name'] break if @tweets.length == PERPAGE end