From 03e1f816012a6af561ad7bd1bf1f08889b3b3a38 Mon Sep 17 00:00:00 2001 From: AJLeonardi Date: Tue, 9 Apr 2013 11:22:36 -0400 Subject: [PATCH 1/3] finished lolcat viewer class --- lolcat_viewer.rb | 4 +++- my_lolcatz.rb | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 my_lolcatz.rb diff --git a/lolcat_viewer.rb b/lolcat_viewer.rb index a01a217..7088346 100644 --- a/lolcat_viewer.rb +++ b/lolcat_viewer.rb @@ -18,4 +18,6 @@ def self.run(count=1) end nil end -end \ No newline at end of file +end + +LolcatViewer.run(2) \ No newline at end of file diff --git a/my_lolcatz.rb b/my_lolcatz.rb new file mode 100644 index 0000000..b339ebb --- /dev/null +++ b/my_lolcatz.rb @@ -0,0 +1,25 @@ +require 'nokogiri' +require 'open-uri' + +class LolcatViewer + def self.run(n = 1) + return_catz = Hash.new + url = 'http://www.lolcats.com' + links = [] + Nokogiri::HTML(open(url + "/gallery/new.html")).css('.gallery-item a').each do |link| + links << link + end + n.times do + arr_length = links.length + rand_index = rand(arr_length -1) + url_ext = links[rand_index]['href'] + image_obj = Nokogiri::HTML(open(url + url_ext)).css('.picture-container>a>img')[0] + title = image_obj['alt'] + img_url = url + image_obj['src'] + return_catz[title] = img_url + end + return_catz.each do |title, link| + puts "title: " + title +" Link: " + link + end + end +end From 6eb9c1af87b0f164fe604c4c844a417089beb796 Mon Sep 17 00:00:00 2001 From: AJLeonardi Date: Tue, 9 Apr 2013 19:01:41 -0400 Subject: [PATCH 2/3] news site class --- news_site.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 news_site.rb diff --git a/news_site.rb b/news_site.rb new file mode 100644 index 0000000..e423d9f --- /dev/null +++ b/news_site.rb @@ -0,0 +1,19 @@ +require 'nokogiri' +require 'open-uri' + +class NewOnionArticles + def self.run() + return_news = Hash.new + url = 'http://www.theonion.com' + Nokogiri::HTML(open(url)).css('section.recent-news a').each do |link| + title = link.content + link_url = link['href'] + return_news[title] = url + link_url + end + return_news.each do |title, address| + puts 'Title: ' + title + ' Link: ' + address + end + end +end + +NewOnionArticles.run() \ No newline at end of file From 350477d8431b2f19c5e4c7526d3115fe6b150398 Mon Sep 17 00:00:00 2001 From: AJLeonardi Date: Tue, 9 Apr 2013 20:53:21 -0400 Subject: [PATCH 3/3] github api confusion --- example.config.rb | 4 ---- github_info.rb | 20 +++++++++++++++++++- 2 files changed, 19 insertions(+), 5 deletions(-) delete mode 100644 example.config.rb diff --git a/example.config.rb b/example.config.rb deleted file mode 100644 index 8b815c6..0000000 --- a/example.config.rb +++ /dev/null @@ -1,4 +0,0 @@ -#Rename this file to config.rb - -USERNAME = "username" -PASSWORD = "password" \ No newline at end of file diff --git a/github_info.rb b/github_info.rb index bdb24f1..1084d65 100644 --- a/github_info.rb +++ b/github_info.rb @@ -1,4 +1,22 @@ require 'github_api' require "#{Dir.pwd}/config" -github = Github.new basic_auth: "#{USERNAME}:#{PASSWORD}" \ No newline at end of file +github = Github.new basic_auth: "#{USERNAME}:#{PASSWORD}" + +github_gen = Github.new + +repos = github_gen.repos.list 'AJLeonardi' #THIS DOES NOT DO WHAT I EXPECT, no idea where it's getting those repos from +repos.each do |repo| + puts repo['name'] +end + +repos = github.repos.list 'AJLeonardi' #This returns my repos! +repos.each do |repo| + puts repo['name'] +end + +repos = github.repos.list 'chrisvans' #this STILL returns my repos -- wtf?? +repos.each do |repo| + puts repo['name'] +end +