Determine list of open mentions to repost.
This commit is contained in:
parent
c23ef8e6ce
commit
36689d1e36
3 changed files with 27 additions and 6 deletions
|
|
@ -40,18 +40,21 @@ class RepostsController < ApplicationController
|
|||
puts "===< retrieve latest post >==="
|
||||
res = Repost.get_most_recent_user_post(access_token)
|
||||
api_res = ApiResponse.new(:raw_json => res.body)
|
||||
dump_api_response(api_res)
|
||||
latest_post = PostData.most_recent_post(api_res.data)
|
||||
puts "=== latest postid: " + latest_post.post_id.to_s + ", created at: " + latest_post.created_at.to_s
|
||||
|
||||
# TODO: select max(postid)
|
||||
|
||||
# retrieve new mentions.
|
||||
# TODO restrict to: fetch( since_id=previous max_id )
|
||||
puts "===< retrieve new mentions >==="
|
||||
res = Repost.get_mentions_stream(access_token)
|
||||
api_response = ApiResponse.new(:raw_json => res.body)
|
||||
# dump_api_response(api_response)
|
||||
api_res = ApiResponse.new(:raw_json => res.body)
|
||||
todo_posts_array = PostData.extract_not_yet_reposted(api_res.data, latest_post.post_id)
|
||||
|
||||
# tmp
|
||||
puts "===> " + todo_posts_array.length.to_s + " noch offene posts."
|
||||
todo_posts_array.each do |post_id|
|
||||
puts "--- reposten: " + post_id.to_s
|
||||
end
|
||||
|
||||
# TODO: res.body contains the mentions in JSON. Proceed from there.
|
||||
#new_mentions.each do | post |
|
||||
|
|
|
|||
|
|
@ -34,4 +34,22 @@ class PostData
|
|||
end
|
||||
post
|
||||
end
|
||||
|
||||
# in: array of posts with all (recent) mentions
|
||||
# in: ID of latest repost that has been done already
|
||||
# out: Array of post ids that haven't been reposted, yet
|
||||
def self.extract_not_yet_reposted(mentions_array, latest_post_id)
|
||||
ret = Array.new
|
||||
mentions_array.each do |line|
|
||||
line.each do |elem|
|
||||
# We only care about the post's ID. Everything else: throw away.
|
||||
if elem[0] == "id" then
|
||||
cur_id = elem[1].to_i
|
||||
puts "... cur_id = " + elem[1]
|
||||
ret << cur_id if cur_id > latest_post_id
|
||||
end
|
||||
end
|
||||
end
|
||||
ret
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ class Repost < ActiveRecord::Base
|
|||
|
||||
# http://developers.app.net/docs/resources/post/streams/#retrieve-posts-mentioning-a-user
|
||||
def self.get_mentions_stream(access_token)
|
||||
uri = "https://alpha-api.app.net/stream/0/users/me/mentions"
|
||||
uri = "https://alpha-api.app.net/stream/0/users/me/mentions?since_id=16899626"
|
||||
self.make_api_get_call(uri, access_token)
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue