Created
February 26, 2015 13:18
-
-
Save rod-dot-codes/7eca596f54748d3b4d86 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
import facebook | |
from readability_score.calculators.fleschkincaid import * | |
from readability_score.calculators.dalechall import * | |
import numpy as np | |
import requests | |
from nltk.collocations import * | |
import nltk | |
bigram_measures = nltk.collocations.BigramAssocMeasures() | |
trigram_measures = nltk.collocations.TrigramAssocMeasures() | |
graph = facebook.GraphAPI(access_token='HAHA NICE TRY', version='2.2') | |
PAGE_IDS = ["131727087549","34122846784"] | |
AVERAGE_AGES = {"131727087549":[],"34122846784":[]} | |
TOKENS = {"131727087549":[],"34122846784":[]} | |
count = 0 | |
for page_id in PAGE_IDS: | |
count = 0 | |
page = graph.get_object(id=page_id) | |
comments = graph.get_connections(id=page_id, connection_name='feed') | |
while True: | |
if "data" not in comments: | |
break | |
for comment in comments["data"]: | |
if "message" in comment: | |
v = comment["message"] | |
tokens = nltk.wordpunct_tokenize(v) | |
TOKENS[page_id] = TOKENS[page_id] + tokens | |
try: | |
print "---------------------------" | |
print v | |
fk = FleschKincaid(v) | |
print fk.min_age | |
AVERAGE_AGES[page_id].append(fk.min_age) | |
except: | |
pass | |
if count > 25: | |
break | |
if comments.has_key("paging") and "next" in comments["paging"]: | |
print comments["paging"]["next"] | |
comments = requests.get(comments["paging"]["next"]).json() | |
else: | |
print "Done" | |
count += 1 | |
print "COUNTS" | |
print AVERAGE_AGES | |
for bank in AVERAGE_AGES: | |
print bank | |
print "OBS", len(AVERAGE_AGES[bank]) | |
print np.mean(AVERAGE_AGES[bank]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment