This repository has been archived by the owner on Sep 10, 2020. It is now read-only.
/
party.rb
57 lines (53 loc) · 1.68 KB
/
party.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
require "ruby_reddit_api"
require "pp"
require_relative 'model'
def query_reddit(subreddit,start_point)
#if count.nil?
# url = "http://www.reddit.com/r/guitar/new/.json?limit=100"
#else
# url = "http://www.reddit.com/r/guitar/new/.json?limit=100&count=#{count}&after=#{start_point}" #t3_nlz9o
#end
#response = JSON.parse HTTParty.get(url).response.body
#pp response
#end_point = response["data"]["after"]
#response = response["data"]["children"]
#response.sort! { |a,b| b["data"]["created_utc"].to_i <=> a["data"]["created_utc"].to_i}
end_point = nil
r = Reddit::Api.new @reddit_username, @reddit_password
r.login
if start_point.empty?
response = r.browse "#{subreddit}/new", {:limit => 100, :sort => "new"}
else
response = r.browse "#{subreddit}/new", {:limit => 100, :sort => "new", :after => start_point}
end
end_point = response.first[:after]
p "Query: " + start_point
p "Next page: " + end_point
response.each do |submission|
begin
p submission.title
Submission.create(
:title => submission.title,
:subreddit => submission.subreddit,
:name => submission.name,
:ups => submission.ups,
:downs => submission.downs,
:score => submission.score,
:author => submission.author,
:domain => submission.domain,
:selftext => submission.selftext,
:media => submission.media,
:url => submission.url,
:thumbnail => submission.thumbnail,
:num_comments => submission.num_comments,
:created_utc => submission.created_utc)
rescue
end
end
return end_point
end
next_seed = "t3_nlmry"
subreddit = "all"
100.times do
next_seed = query_reddit(subreddit,next_seed)
end