<commit_before>#!/usr/bin/env python
"""
CLI wrapper around get_tweets and classifier.write
"""

import datetime
import json
import os
from weather_report import Classifiers, Readers
import yaml

class Jaco(object):

    def __init__(self, credsfile, key_name, secret_name, cities, output, classifier_list):
        with open(credsfile, 'r') as f:
            self.key = yaml.load(f).get(key_name)
            self.secret = yaml.load(f).get(secret_name)
        with open(cities,'r') as f:
            self.cities = json.load(f)
        self.output=output
        self.classifier_list = classifier_list

    @staticmethod
    def city_attrs(city):
        return city[0], str(int(round((city[1]/3.14)**.5,0)))

    def run(self):
        for city in self.cities:
            loc, radius = city_attrs(city)
            query = {'geocode' : loc + ',' + radius + 'mi'}
            tweetReader = Readers.tweetReader(self.key, self.secret)
            tweets = tweetReader.get(now=now, pages=50, limit=100, **query)
            for classifier in classifier_list:
                if classifier == 'count_dict':
                    data = Classifiers.count_dict()
                if classifier == 'polar_summary':
                    data = Classifiers.polar_summary()
                data.now = now
                data.city = city
                data = data.classify(tweets)
                data.write(filepath=output)

if __name__ == '__main__':
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument('credsfile')
    parser.add_argument('key-name')
    parser.add_argument('secret-name')
    parser.add_argument('cities', type=str,
        choices=['top_50_us, top_10_us'])
    parser.add_argument('output', type=str, default='counts.csv')
    parser.add_argument('--classifiers', type=str,
        nargs='+', required=True,
        choices=['count_dict', 'polar_summary'])

    args = parser.parse_args()
    args.cities = os.path.join('data', args.cities + '.json')

    Jaco(**vars(args)).run()
<commit_msg>naming<commit_after>#!/usr/bin/env python
"""
CLI wrapper around get_tweets and classifier.write
"""

import datetime
import json
import os
from weather_report import classifiers, readers
import yaml

class Jaco(object):

    def __init__(self, credsfile, key_name, secret_name, cities, output, classifier_list):
        with open(credsfile, 'r') as f:
            self.key = yaml.load(f).get(key_name)
            self.secret = yaml.load(f).get(secret_name)
        with open(cities,'r') as f:
            self.cities = json.load(f)
        self.output=output
        self.classifier_list = classifier_list

    @staticmethod
    def city_attrs(city):
        return city[0], str(int(round((city[1]/3.14)**.5,0)))

    def run(self):
        for city in self.cities:
            loc, radius = city_attrs(city)
            query = {'geocode' : loc + ',' + radius + 'mi'}
            tweetReader = Readers.tweetReader(self.key, self.secret)
            tweets = tweetReader.get(now=now, pages=50, limit=100, **query)
            for classifier in classifier_list:
                if classifier == 'count_dict':
                    data = Classifiers.count_dict()
                if classifier == 'polar_summary':
                    data = Classifiers.polar_summary()
                data.now = now
                data.city = city
                data = data.classify(tweets)
                data.write(filepath=output)

if __name__ == '__main__':
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument('credsfile')
    parser.add_argument('key-name')
    parser.add_argument('secret-name')
    parser.add_argument('cities', type=str,
        choices=['top_50_us, top_10_us'])
    parser.add_argument('output', type=str, default='counts.csv')
    parser.add_argument('--classifiers', type=str,
        nargs='+', required=True,
        choices=['count_dict', 'polar_summary'])

    args = parser.parse_args()
    args.cities = os.path.join('data', args.cities + '.json')

    Jaco(**vars(args)).run()

{'fraction_non_alphanumeric': 0.13031718711581017, 'fraction_numerical': 0.007868207523973445, 'mean_word_length': 2.534317984361425, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5057957', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1237, 'n_words': 256}