@@ -0,0 +1,2732 @@
+#!/usr/bin/env python%0A# -*- coding: UTF-8 -*-%0A__author__=%22Josh Montague%22%0A__license__=%22Simplified BSD%22%0A%0Aimport sys%0Aimport json%0Aimport acscsv%0A%0A# for custom twitter output, import both the fields module and the code module%0Afrom twitter_acs_fields import *%0Aimport twitter_acs%0A%0A# change the parent class if needed%0Aclass TestCSV( twitter_acs.TwacsCSV ):%0A    %22%22%22%0A    Test class for experimenting with new output combinations. This class should inherit%0A    from the appropriate module.class in the core library. Compliance and invalid records %0A    are handled by the parent class' procRecord() method. This class should only define a %0A    new get_output_list() method which overrides the parent method and determines the %0A    custom output. %0A    %22%22%22       %0A    %0A    def get_output_list(self, d):%0A        %22%22%22%0A        This method overwrites the output method in the parent class. Append values from %0A        desired payload fields to the output list, which is returned at the end of this method. %0A        %0A        Take a JSON Activity Streams payload as a Python dictionary. %0A        %22%22%22%0A        output_list = %5B%5D %0A%0A        # twitter country code%0A        output_list.append( field_location_twitter_country_code(d).value )%0A%0A        # activity id %0A        output_list.append( field_id(d).value )%0A%0A        # username %0A        output_list.append( field_actor_preferredusername(d).value )%0A%0A        # geo-tag coords (returns a list, cast to str)%0A        output_list.append( str(field_geo_coordinates(d).value) )%0A%0A%0A        # done building output list %0A        return output_list %0A%0A%0A%0Aif __name__ == %22__main__%22:%0A    %22%22%22%0A    Receive data from stdin (decompressed JSON-lines only) and process using the existing %0A    code, but let this module's get_output_list() method define the output fields. %0A    %22%22%22%0A%0A    # Get the appropriate object by mocking the constructor in the main gnacs.py code. most %0A    #   common command-line options (flags) don't matter since we're explicitly defining the %0A    #   fields to be printed in the method above %0A    processing_obj = TestCSV(%22%7C%22, None, *%5BTrue%5D*7) %0A%0A    line_number = 0 %0A    for r in sys.stdin: %0A        line_number += 1%0A        try:%0A            recs = %5Bjson.loads(r.strip())%5D%0A        except ValueError:%0A            try:%0A                # maybe a missing line feed?%0A                recs = %5Bjson.loads(x) for x in r.strip().replace(%22%7D%7B%22, %22%7DGNIP_SPLIT%7B%22).split(%22GNIP_SPLIT%22)%5D%0A            except ValueError:%0A                sys.stderr.write(%22Invalid JSON record (%25d) %25s, skipping%5Cn%22%25(line_number, r.strip()))%0A                continue%0A        for record in recs:%0A            if len(record) == 0:%0A                continue%0A            sys.stdout.write(%22%25s%5Cn%22%25processing_obj.procRecord(record, emptyField=%22None%22))%0A%0A

add custom_output.py module for experiment template