Skip to content

Instantly share code, notes, and snippets.

@jsutterfield
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsutterfield/fde2004ffa6d55e8e320 to your computer and use it in GitHub Desktop.
Save jsutterfield/fde2004ffa6d55e8e320 to your computer and use it in GitHub Desktop.
#!/bin/python
import operator
def main():
fp = open("reportTotalVideosOnWikiaAll.csv", "r")
vids_by_provider = {}
vids_by_wiki = {}
# Lines are in the csv form provider,count,wiki
for line in fp.readlines():
vals = line.split(",")
if vals[0] not in vids_by_provider:
vids_by_provider[vals[0]] = 0
if vals[2] not in vids_by_wiki:
vids_by_wiki[vals[2]] = 0
# Keep a tally of total videos by wiki, and by provider
vids_by_provider[vals[0]] += int(vals[1])
vids_by_wiki[vals[2]] += int(vals[1])
fp.close()
# Sort both dictionaries based on number of videos creating a list of tuples
# eg [('minecraftinfinity', 1), ('lyinggame', 1), ('dope101', 1)...]
sorted_vids_wiki = sorted(vids_by_wiki.iteritems(), key=operator.itemgetter(1), reverse=True)
# eg [('youtube', 748344), ('ign', 100159), ('screenplay', 60724)...]
sorted_vids_provider = sorted(vids_by_provider.iteritems(), key=operator.itemgetter(1), reverse=True)
# Total number of videos, grouped by provider
print "\nVideos By Provider"
print "================="
sum_total = 0
for vid in sorted_vids_provider:
sum_total += vid[1]
print "%s: %s" % (vid[0], vid[1])
# Total number of videos overall
print "\nTotal vids"
print "=========="
print sum_total
# Top 10 wikis with most videos (skipping the first 2 which are video and community)
print "\nTop 10 wikis"
print "============"
for i in range(2, 12):
print "%s: %s" % (sorted_vids_wiki[i][0].strip(), sorted_vids_wiki[i][1])
print "\nTotal wikis with videos"
print "======================="
print len(sorted_vids_wiki)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment