Created
September 30, 2016 11:04
-
-
Save lastknight/3cd5eff271f5c46d79a2f13ba75635a3 to your computer and use it in GitHub Desktop.
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
# Il codice delle statistiche del talk "Data Driven Bullshit" di pane Web e Salame 2016 | |
# Maggiori info qui: http://mgpf.it/2016/09/30/daradrivenbullshit2016.html | |
require "fb_graph2" | |
require "pp" | |
require "csv" | |
require "unidecoder" | |
FbGraph2.api_version = 'v2.7' | |
FbGraph2.http_config do |config| | |
config.ssl_config.ssl_version = :SSLv23 | |
end | |
# Il tuo accss token lo puoi gneerare copiando quello che trovi a: https://developers.facebook.com/tools/explorer/145634995501895/ | |
ACCESS_TOKEN = 'EAACEdEose0cBAPJjyQVOcjgFQTIReWKN7ZA4AgvJ9msiXDgEMz8ZAm20MqZBsZBqdJbZApaw4k7I3UgFCXCdoantaniandamtszaevwQfRljtZm43xw7iIX4vSgswI4JiM3dMjlPpCdLWBMB1OBdPvrCVgcgXEAsvCpLw8AvY664l1wZDZD' | |
FIELDS = 'type,id,created_time,message,attachments{type,url},shares,reactions.summary(true),comments.summary(true)' | |
POST_FIELDS = 'likes.summary(true).limit(0),comments.summary(true).limit(0),shares' | |
FEED_LIMIT = 10 | |
user = FbGraph2::User.new('me').authenticate(ACCESS_TOKEN) | |
paginated_feed = user.posts(fields: FIELDS, limit: FEED_LIMIT, since: 1441065600) | |
puts paginated_feed.size | |
feeds = [] | |
CSV.open("./export.csv", "wb", {:col_sep => ";", encoding: "utf-8"}) do |csv| | |
csv << ["id", "timestamp", "type", "message", "reactions", "comments", "url"] | |
begin | |
to_break = false | |
loop do | |
break if paginated_feed.empty? | |
paginated_feed.each do |post| | |
# pp post | |
pp "-"*80 | |
pp g = post.id | |
pp a = post.created_time | |
pp b = post.type | |
pp c = post.message.to_ascii rescue "" | |
pp d = post.raw_attributes["reactions"]["summary"][:total_count] | |
pp e = post.raw_attributes["comments"]["summary"][:total_count] | |
pp f = post.raw_attributes["attachments"]["data"][0][:url] rescue "no" | |
csv << [g, a, b, c, d, e, f] | |
#feeds << comment | |
end | |
break if to_break | |
paginated_feed = paginated_feed.next | |
# puts paginated_feed.size | |
end | |
rescue => exception | |
puts exception.to_s | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment