Skip to content

Instantly share code, notes, and snippets.

@riordan
Created November 24, 2015 16:14
Show Gist options
  • Save riordan/18cd383055b56d04ef04 to your computer and use it in GitHub Desktop.
Save riordan/18cd383055b56d04ef04 to your computer and use it in GitHub Desktop.
#!/usr/bin/python
# Copyright 2009-2010 Yelp
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Wikimedia Article Counter in Hadoopy Goodness
"""
from mrjob.job import MRJob
class MRWikipediaRequests(MRJob):
def mapper(self, _, line):
# Split a line of the wp logs
logparts = line.split(' ')
langproj = logparts[0]
pagename = logparts[1]
counts = int(logparts[2])
# Count number of pageviews per language too!
#self.increment_counter('languages', langproj[0:2], counts)
# Track the pageviews per page
yield ((langproj,pagename), counts)
def combiner(self, langproj_name, counts):
yield (langproj_name, sum(counts))
def reducer(self, langproj_name, counts):
yield (langproj_name, sum(counts))
if __name__ == '__main__':
MRWikipediaRequests.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment