Skip to content

Commit

Permalink
updates importer to handle new data structure returned by TwitterTime…
Browse files Browse the repository at this point in the history
…line
  • Loading branch information
aceofbassgreg committed Aug 4, 2015
1 parent dea61eb commit d9db2b4
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions lib/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,20 @@ def initialize
@tweet_grabber = DurhamScraper::TwitterTimeline.create!
end

def tweets_by_username
tweet_grabber.recent_durham_tweets_by_username
def tweets_by_category
tweet_grabber.recent_durham_tweets_by_category
end

def onboard_data_for_api
tweets_by_username.map { |username, array|
onboarder = DurhamScraper::Onboarder.new(array)
processed_tweets = onboarder.process_payload
processed_tweets.map {|h| h[:author] = "@#{username.to_s}"}
processed_tweets
tweets_by_category.map {|category_hash|
category = category_hash[:category]

category_hash[:tweets].map { |tweets_by_username|
process_tweets_by(tweets_by_username,category)
}
}.flatten
end


def upload_to_api
data = onboard_data_for_api
data.map {|entry|
Expand All @@ -50,4 +50,18 @@ def service_url
@service_url ||= YAML::load(File.open("config/services.yml"))[ENV["ENV"]]
end

private

def process_tweets_by(tweets_by_username,category)
tweets_by_username.map { |username, array|
onboarder = DurhamScraper::Onboarder.new(array)
processed_tweets = onboarder.process_payload
processed_tweets.map { |h|
h[:author] = "@#{username.to_s}"
h[:tags] << category unless h[:tags].include?(category)
}
processed_tweets
}.flatten
end

end

0 comments on commit d9db2b4

Please sign in to comment.