Created
March 27, 2015 08:11
-
-
Save breim/e6e4a4f2b9b9e74b4fae to your computer and use it in GitHub Desktop.
Crawling on reddi
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| task :add_posts => :environment do | |
| require 'nokogiri' | |
| require 'mechanize' | |
| require 'json' | |
| # 88198 | |
| def dados(categoria) | |
| j = 0 | |
| 4.times do |i| | |
| agent = Mechanize.new | |
| page = agent.get "http://imgur.com/r/#{categoria}/page/#{i}.json" | |
| json = JSON.parse page.body | |
| # Todas as propriedases da imagem | |
| #json['data'][0] | |
| #Saber quantas fotos tem no acesso do link | |
| #json['data'][0].count | |
| #Contar a quantidade de imagens e repetir o laço do times | |
| repeat = json['data'].count | |
| # Esta parte do programa ele para se o link que ele acessou do json e da categoria não tiver nenhuma informação | |
| # daà ele para e continua na outra categoria :) | |
| break if repeat == 0 | |
| # Nome da imagem | |
| #json['data'][0]['title'] #Campo 'name' | |
| # Hash da image, ou seja onde vamos acessar ela | |
| #json['data'][0]['hash'] #Campo 'img_name' | |
| # Extensão da imagem, se é jpg, gif ou png | |
| #json['data'][0]['ext'] #Campo 'ext' | |
| # Subreddit - nome da categoria da qual ele pertence no reddit(milf,bigtits) | |
| #json['data'][0]['subreddit'] #Campo 'subreddit' | |
| #puts category(teste) | |
| # Tamanho das imagens | |
| #json['data'][0]['width'] #Campo 'width' | |
| #json['data'][0]['height'] #Campo 'height' | |
| repeat.times do |i| | |
| hash = json['data'][i]['hash'] | |
| title = json['data'][i]['title'] | |
| width = json['data'][i]['width'] | |
| height = json['data'][i]['height'] | |
| subreddit = json['data'][i]['subreddit'] | |
| ext = json['data'][i]['ext'] | |
| # Se o hash já existir no sitema não inserimos novamente no banco | |
| existente = Post.find_by(:img_name => hash) | |
| if existente == nil | |
| Post.create!(:name => title[0..100], :img_name => hash, :status => 0, :ext => ext, :subreddit => subreddit, :width => width, :height => height) | |
| end | |
| end | |
| j += 1 | |
| end | |
| puts "Terminado #{categoria} total de #{j} paginas" | |
| end | |
| dados('adultgifs') | |
| #dados('AmateurArchives') | |
| dados('asstastic') | |
| #dados('BBW') | |
| #dados('BBWGW') | |
| dados('bigasses') | |
| dados('boobbounce') | |
| dados('boobgifs') | |
| dados('booty') | |
| dados('BubbleButts') | |
| dados('burstingout') | |
| dados('bustybabes') | |
| dados('buttplug') | |
| dados('cfnf') | |
| dados('ChangingRooms') | |
| dados('chubby') | |
| dados('CollegeAmateurs') | |
| dados('collegensfw') | |
| dados('curvy') | |
| dados('facedownassup') | |
| dados('facesitting') | |
| #dados('feet') | |
| #dados('feetish') | |
| dados('FFSocks') | |
| dados('Fisting') | |
| #dados('FootFetish') | |
| dados('funsized') | |
| dados('ginger') | |
| dados('GirlsinLaceFishnets') | |
| dados('GirlsinStripedSocks') | |
| dados('GirlswithGlasses') | |
| dados('gonewild') | |
| dados('gonewildaudio') | |
| dados('gonewildcurvy') | |
| dados('GoneWildPlus') | |
| dados('Gravure') | |
| dados('HappyEmbarrassedGirls') | |
| dados('heavyhangers') | |
| dados('HighResNSFW') | |
| dados('homegrowntits') | |
| dados('homemadexxx') | |
| dados('hugeboobs') | |
| dados('hugenaturals') | |
| dados('iWantToFuckHer') | |
| dados('jilling') | |
| dados('juicyasians') | |
| dados('latinas') | |
| dados('legs') | |
| dados('legsup') | |
| dados('londonandrews') | |
| dados('milf') | |
| dados('nakedcelebs') | |
| dados('nsfw2') | |
| dados('NSFW_GIF') | |
| dados('nsfwhardcore') | |
| dados('nsfwoutfits') | |
| dados('O_Faces') | |
| dados('OnOff') | |
| dados('Orgasms') | |
| dados('PiercedNSFW') | |
| #dados('PreggoPorn') | |
| dados('RealGirls') | |
| dados('realolderwomen') | |
| dados('SceneGirls') | |
| dados('sex') | |
| dados('sexypantyhose') | |
| dados('sexystories') | |
| dados('shewantstofuck') | |
| dados('squirting') | |
| dados('Stacked') | |
| dados('stockings') | |
| dados('sweatermeat') | |
| dados('TallGirls') | |
| dados('tanlines') | |
| dados('TheUnderboob') | |
| dados('thick') | |
| dados('thighhighs') | |
| dados('tights') | |
| dados('TittyDrop') | |
| dados('torpedotits') | |
| dados('TwinGirls') | |
| dados('voluptuous') | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment