<commit_before>#!/usr/bin/env python2

import urllib2      # for fetching weather data
import json         # for parsing weather data
import re           # for parsing the format string
import argparse     # for parsing CLI args
import os.path      # for getting the path to the profiles

# Current version information
PROGRAM_NAME = 'winfo'
MAJOR_VERSION = '0'
MINOR_VERSION = '4'
COPYRIGHT = 'Copyright (c) 2014 <NAME> <<EMAIL>>'

VERSTR      = MAJOR_VERSION + '.' + MINOR_VERSION
FULLVERSION = PROGRAM_NAME + ' ' + VERSTR + ', ' + COPYRIGHT



def main():
    args = parseargs()

    profname = args.profile if args.profile else 'default'
    profile = loadprofile(profname)
    datafile = os.path.expanduser('~') + '/.cache/' + PROGRAM_NAME + '/'
    try:
        datafile = datafile + profile['download'] + '.json'
    except KeyError:
        datafile = datafile + profname + '.json'

    if args.fetch:
        weather = fetch(profile)
        try:
            out = open(datafile, 'w')
            json.dump(weather, out, indent=4, separators=(',', ': '))
            out.close()
        except IOError:
            print "Cannot write cache file for '%s'." % profname
            exit(1)
    if not args.quiet:
        try:
            infile = open(datafile, 'r')
            data = json.load(infile)
            if args.output == None:
                print parseformat(profile['format'], data)
            else:
                print parseformat(eval("'" + args.output + "'"), data)
        except IOError:
            print "Cannot read cache file for '%s'." % profname
            exit(1)
        except KeyError:
            print "You must include a format string in your profile!"
            exit(1)

def parseformat(fmt, data):
    """Parse the given format string and return the formatted data.

    Arguments:
    fmt -- the format string to parse<commit_msg>Fix bug with single quotes in output format string.<commit_after>#!/usr/bin/env python2

import urllib2      # for fetching weather data
import json         # for parsing weather data
import re           # for parsing the format string
import argparse     # for parsing CLI args
import os.path      # for getting the path to the profiles

# Current version information
PROGRAM_NAME = 'winfo'
MAJOR_VERSION = '0'
MINOR_VERSION = '4'
COPYRIGHT = 'Copyright (c) 2014 <NAME> <<EMAIL>>'

VERSTR      = MAJOR_VERSION + '.' + MINOR_VERSION
FULLVERSION = PROGRAM_NAME + ' ' + VERSTR + ', ' + COPYRIGHT



def main():
    args = parseargs()

    profname = args.profile if args.profile else 'default'
    profile = loadprofile(profname)
    datafile = os.path.expanduser('~') + '/.cache/' + PROGRAM_NAME + '/'
    try:
        datafile = datafile + profile['download'] + '.json'
    except KeyError:
        datafile = datafile + profname + '.json'

    if args.fetch:
        weather = fetch(profile)
        try:
            out = open(datafile, 'w')
            json.dump(weather, out, indent=4, separators=(',', ': '))
            out.close()
        except IOError:
            print "Cannot write cache file for '%s'." % profname
            exit(1)
    if not args.quiet:
        try:
            infile = open(datafile, 'r')
            data = json.load(infile)
            if args.output == None:
                print parseformat(profile['format'], data)
            else:
                print parseformat(evalstr(args.output), data)
        except IOError:
            print "Cannot read cache file for '%s'." % profname
            exit(1)
        except KeyError:
            print "You must include a format string in your profile!"
            exit(1)

def evalstr(fmt):
    """Evaluate all the escape sequences in the given string, keeping any single
    quotes unescaped.

    Arguments:
    fmt -- the format string to evaluate
    """
    fmt = re.sub("'", "\\'", fmt)
    return eval("'" + fmt + "'")

def parseformat(fmt, data):
    """Parse the given format string and return the formatted data.

    Arguments:
    fmt -- the format string to parse
{'fraction_non_alphanumeric': 0.11155082859262924, 'fraction_numerical': 0.005936186000494682, 'mean_word_length': 2.2044374009508716, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7496120', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1129, 'n_words': 385}