# -*- encoding: utf-8 -*- # Ёметер /YoMeter/ # # Tool for investigation of use of "Ё" cyrillic letter # in posts of your LiveJournal friends :) # # To use: # 0. Rename to yometer.py # 1. setup your LJ username and other properties # 2. run the following: # python yometer.py # # (C) 2008 Ivan N. Veselov aka dying_sphynx # import urllib import xml.etree.ElementTree as ET # set to your LJ nickname USERNAME = "dying_sphynx" # set False to analyze users which have friended you ANALYZE_MY_FRIENDS = True # do not count users which has less than SIGNIFICANCE_BIAS posts SIGNIFICANCE_BIAS = 1 FRIENDS_URL = 'http://www.livejournal.com/misc/fdata.bml?user=%s' POSTS_RSS_URL = 'http://%s.livejournal.com/data/rss' def read_raw_friends(): fh = urllib.urlopen(FRIENDS_URL % USERNAME) friends = fh.read() return friends def parse_friends(raw_friends_text): raw_list = raw_friends_text.splitlines() inout_char = ANALYZE_MY_FRIENDS and '>' or '<' f_list = [el[2:] for el in raw_list if len(el) > 0 and el[0] == inout_char] return f_list def make_friend_url(friend): name = friend.replace('_', '-') return POSTS_RSS_URL % name def get_rss_items(xml_data): tree = ET.parse(xml_data) return tree.getiterator('item') def calculate_yos(items): total_yos = yo_posts = yo_count = 0 total_posts = len(items) for item in items: descr = item.findtext("description") yo_count = descr.count(u"ё") yo_posts += bool(yo_count) total_yos += yo_count if total_posts < SIGNIFICANCE_BIAS and yo_count == 0: print "insignificant user (total posts = %d)" % total_posts return -1 else: ratio = float(yo_posts) / total_posts print "total yos = %d, ratio = %.2f" % (total_yos, ratio) return ratio def get_yos_percent_for_friend(nick): print "---------------------------" print "analyzing %s" % nick url = make_friend_url(nick) items = get_rss_items(urllib.urlopen(url)) ratio = calculate_yos(items) return ratio if __name__ == "__main__": raw = read_raw_friends() f_list = map(get_yos_percent_for_friend, parse_friends(raw)) yo_users_quantity = len(filter(lambda x: x > 0, f_list)) significant_users_quantity = len(filter(lambda x: x != -1, f_list)) try: users_ratio = float(yo_users_quantity) / significant_users_quantity except ZeroDivisionError: print "There were no significant users in friendlist" print "total users = %d, significant users = %d, yo users = %d, ratio = %.2f" % ( len(f_list), significant_users_quantity, yo_users_quantity, users_ratio)