Last active
December 11, 2015 01:29
-
-
Save newkedison/4524166 to your computer and use it in GitHub Desktop.
G+ summary
This file contains 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
from bs4 import BeautifulSoup | |
import re | |
import sys | |
def include_all_class(classes): | |
def check_class(tag): | |
result = True | |
for c in classes: | |
if not tag.has_key('class') or not c in tag['class']: | |
result = False | |
break | |
return result | |
return check_class | |
def show_summary(file_name): | |
total_post = 0 | |
reshare_post = 0 | |
original_post = 0 | |
public_post = 0 | |
limit_post = 0 | |
public_original_post = 0 | |
limit_original_post = 0 | |
soup = BeautifulSoup(open(file_name)) | |
posts = soup.find_all(id=re.compile('update-')) | |
total_post = len(posts) | |
for post in posts: | |
header = post.find('header') | |
time_label = header.span.span.a | |
view = header.span.contents[2].string | |
if view == "Mobile" or view[:7] == "+1'd on" or view == "Google Reader" \ | |
or view == "Hangout": | |
view = header.span.contents[4].string | |
is_public = True | |
if view[:6] == "Public" or view == "Community": | |
public_post += 1 | |
else: | |
limit_post += 1 | |
is_public = False | |
check_reshare1 = post.find_all(include_all_class(["uGbq2"])) | |
check_reshare2 = post.find_all(include_all_class(["DTMmlc"])) | |
if check_reshare1 or check_reshare2: | |
reshare_post += 1 | |
else: | |
original_post += 1 | |
if is_public: | |
public_original_post += 1 | |
else: | |
limit_original_post += 1 | |
print("summary:") | |
print(" Total : {0}".format(total_post)) | |
print(" Original: {0}".format(original_post)) | |
print(" Reshared: {0}".format(reshare_post)) | |
print(" Public: {0}".format(public_post)) | |
print(" Original: {0}".format(public_original_post)) | |
print(" Reshared: {0}".format(public_post - public_original_post)) | |
print(" Limit : {0}".format(limit_post)) | |
print(" Original: {0}".format(limit_original_post)) | |
print(" Reshared: {0}".format(limit_post - limit_original_post)) | |
if __name__ == "__main__": | |
file_name = "source" | |
if len(sys.argv) > 1: | |
file_name = sys.argv[1] | |
show_summary(file_name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment