<commit_before>#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Author: <NAME>
http://github.com/robotmachine/La_Nina
""" """
Originally forked from niño || https://github.com/drbunsen/nino
"""
import os, sys, urllib, urllib.request, http.client, configparser, textwrap, argparse, json

""" Set config file """
settings = os.path.expanduser("~/.nina")
config = configparser.ConfigParser()

""" Main """
def main():
	parser = argparse.ArgumentParser(description='Niña: Gets Wunderground weather reports. Example: nina 29072', prog='nina')
	parser.add_argument('-z','--zip',
		action='store', dest='ZIP', default=None,
		help='Zip code for weather. If nothing is provided, use favourite zip from config file.')
	parser.add_argument('-k','--key',
		action='store', dest='APIKEY', default=None,
		help='API key from http://www.wunderground.com/weather/api')
	args = parser.parse_args()
	APIKEY = args.APIKEY
	ZIP = args.ZIP
	if os.path.exists(settings):
		config.read(settings)
		if APIKEY is None:
			APIKEY = config['NINA']['APIKEY']
		if ZIP is None:
			ZIP = config['NINA']['ZIP']
	if ZIP is not None and APIKEY is not None:
		simple_forecast(APIKEY, ZIP)
	if ZIP is None and APIKEY is None:
		set_config()

""" Create config file """
def set_config():
	print(textwrap.dedent("""
	A Wunderground API Key is required.
	Create one for free here:
	http://www.wunderground.com/weather/api
	"""))
	APIKEY = input("Wunderground API Key: ")
	if (APIKEY == ""):
		print(textwrap.dedent("""
		API Key is not optional!
		Create one for free and return!
		http://www.wunderground.com/weather/api
		"""))
		quit()
	print(textwrap.dedent("""
	Set your local ZIP code to use as the default
	"""))
	ZIP = input("ZIP: ")
	if (APIKEY == ""):
		print(textwrap.dedent("""
		API Key is not optional!
		Create one for free and return!
		http://www.wunderground.com/weather/api
		"""))
		quit()
	config ['NINA'] = {'APIKEY': APIKEY,
		'ZIP': ZIP}
	with open(settings, 'w') as configfile:
		config.write(configfile)
	print("Settings saved!")
	quit()

""" Assemble weather data. """<commit_msg>Added option to edit the config file. Resolves #3.<commit_after>#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Author: <NAME>
http://github.com/robotmachine/La_Nina
""" """
Originally forked from niño || https://github.com/drbunsen/nino
"""
import os, sys, urllib, urllib.request, http.client, configparser, textwrap, argparse, json

settings = os.path.expanduser("~/.nina")
if os.path.exists(settings):
	dotfile = True
elif not os.path.exists(settings):
	dotfile = False
config = configparser.ConfigParser()

""" Main """
def main():
	parser = argparse.ArgumentParser(description='Niña: Gets Wunderground weather reports. Example: nina 29072', prog='nina')
	parser.add_argument('-z','--zip',
		action='store', dest='ZIP', default=None,
		help='Zip code for weather. If nothing is provided, use favourite zip from config file.')
	parser.add_argument('-k','--key',
		action='store', dest='APIKEY', default=None,
		help='API key from http://www.wunderground.com/weather/api')
	parser.add_argument('--edit-config', dest="EDIT",
		action='store_true', default=False,
		help='Create or edit config file.')
	args = parser.parse_args()
	EDIT = args.EDIT
	APIKEY = args.APIKEY
	ZIP = args.ZIP
	if EDIT is True:
		set_config()
	if dotfile is True and APIKEY is None:
		config.read(settings)
		APIKEY = config['NINA']['APIKEY']
	if dotfile is True and ZIP is None:
		config.read(settings)
		ZIP = config['NINA']['ZIP']
	if ZIP is not None and APIKEY is not None:
		"""print("Would have called a simple forecast with API key {} and ZIP {}".format(APIKEY, ZIP))"""
		simple_forecast(APIKEY, ZIP)
	if ZIP is None and APIKEY is None:
		set_config()

""" Create config file """
def set_config():
	if dotfile is False:
		print(textwrap.dedent("""
		A Wunderground API Key is required.
		Create one for free here:
		http://www.wunderground.com/weather/api
		"""))
		APIKEY = input("Wunderground API Key: ")
		print(textwrap.dedent("""
		Set your local ZIP code to use as the default
		"""))
		ZIP = input("ZIP: ")
		if (ZIP == ""):
			ZIP = False
		config ['NINA'] = {'APIKEY': APIKEY,
			'ZIP': ZIP}
		with open(settings, 'w') as configfile:
			config.write(configfile)
		print("Settings saved!")
		quit()
	elif dotfile is True:
		config.read(settings)
		APIKEY = config['NINA']['APIKEY']
		ZIP = config['NINA']['ZIP']
		print(textwrap.dedent("""
		Current stored API key is {}
		Would you like to change it?
		""".format(APIKEY)))
		BOOL1 = input("Y/N: ")
		if BOOL1 in ['Y', 'y', 'Yes', 'YES', 'yes']:
			APIKEY = input("New API key: ")
			config ['NINA'] = {'APIKEY': APIKEY}
			with open(settings, 'w') as configfile:
				config.write(configfile)
		else:
			print(textwrap.dedent("Keeping {} in config file.".format(APIKEY)))
		print(textwrap.dedent("""
		Current stored ZIP is {}
		Would you like to change it?
		""".format(ZIP)))
		BOOL2 = input("Y/N: ")
		if BOOL2 in ['Y', 'y', 'Yes', 'YES', 'yes']:
			ZIP = input("New ZIP: ")
			config ['NINA'] = {'ZIP': ZIP}
			with open(settings, 'w') as configfile:
				config.write(configfile)
		else:
			print(textwrap.dedent("Keeping {} in config file.".format(ZIP)))
		quit()

""" Assemble weather data. """
{'fraction_non_alphanumeric': 0.1697968570333461, 'fraction_numerical': 0.003641241855116903, 'mean_word_length': 4.250503018108652, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 6, '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': '4897158', 'n_tokens_mistral': 1963, 'n_tokens_neox': 1817, 'n_words': 508}