
# coding: utf-8

# In[21]:

#Outfit Selector. Chooses random outfits from a spreadsheet based on the weather in 'city'.
#using Open Weather Map API (PyOWM python wrapper) and some user-inputted categories.

import pandas as pd
import numpy as np
from pyowm import OWM

#Variables: accepted_in is a list of accepted user inputs; category_list is used to map input to their choice
#'city' can be changed to map the weather of almost any city worldwide http://openweathermap.org/help/city_list.txt.

city = 'East Los Angeles'

accepted_in = ['1','2','3','4']
accepted_rein = ['1','2','3']
category_list = ['Cool', 'Sexy', 'Cozy', 'Fancy']
category_choice = 0
option_choice = 0
choice = 0
force_temp = False
temp = 0

#Main user input loop

while 1:
    category_choice = input("Today I'm feeling... 1)Cool 2)Sexy 3)Cozy 4)Fancy 5|Other Options ")
    if category_choice in accepted_in:
        choice = category_list[int(category_choice) - 1]
        break
    elif category_choice == '5':
        while 1:
            option_choice = input("Other Options: 1)Themes 2)Add an Outfit 3)Force Weather 4)Back to Selection ")
            if option_choice == '4':
                break
            elif option_choice in accepted_in:
                while 1:
                    if option_choice == '3':
                        force_temp = True
                        try:
                            temp = float(input("What is the temperature (high) for today (in fahrenheit)? "))
                        except:
                            ("Oops. Enter a valid number.")
                        break
                #outfitter()
                #forcer()
            else:
                print("Oops! Enter '1', '2', '3', or '4'")
                continue
    else:
        print("Oops! Enter '1', '2', '3', or '4'")
        continue

def themer():
    if option_choice == 1:
        df = pd.read_csv('Outfit_Selector_Spreadsheet.csv')
        while 1:
            try:
                theme_choice = str(input('Choose a theme: '))
                if theme_choice == 'Exit' or 'exit':
                    option_choice = 0
                    break
                if theme_choice == 'Themes' or 'themes':
                    all_theme_list = list(df['Theme'])
                    theme_list = [y for y in all_theme_list if y != str('0')]
                    print('List of themes: ',theme_list)
                    continue
                choice_array = df[df['Theme'] == theme_choice]
                break
            except:
                print('Enter a valid theme. Type "Themes" for a list or "Exit" to return to selection.')
                continue
        print(list(choice_array['Outfits']))

#Takes input in degrees and outputs the array truncated by temperature. Prints the weather category.

def select_by_degrees(degrees,categ_array):
    if degrees >= 90:
        weather_array = categ_array[categ_array['Weather_value'] >= 3]
        print("Today is hot! (~%.1f F\xb0)" %degrees)
    elif degrees >= 70:
        weather_array = categ_array[(categ_array['Weather_value'] >= 1) & (categ_array['Weather_value'] <= 4)]
        print("Today has fair weather. (~%.1f F\xb0)" %degrees)
    else:
        weather_array = categ_array[(categ_array['Weather_value'] <= 1) | (categ_array['Weather_value'] == 3)]
        print("Today is cold... (~%.1f degrees F\xb0)" %degrees)
    return(weather_array)

#OWM implementation uses Open Weather Map API to find today's forecast for East LA. Manual input if cannot be accessed.

def select_by_inputs(categ_array):
    try:
        owm = OWM('0d68d0be097dc01d8a14a1ff41785d03', version= '2.5')
        fc = owm.daily_forecast(city, limit = 1) 
        f = fc.get_forecast()
        #print(f.get_weathers)
        w = f.get_weathers()[0]
        #print(w.get_temperature)
        if force_temp == False:
            temp = (float(w.get_temperature('fahrenheit')['max'])+5)
        rain = fc.will_have_rain()
        if rain == True:
            print("Rainy day! Bring an umbrella.")
    except:
        while 1:
            try:
                temp = float(input("What is the temperature (high) for today? (in fahrenheit) "))
                break
            except:
                print("Oops! Enter a number.")
                continue
    weather_array = select_by_degrees(temp, categ_array)
    return list(weather_array['Outfits'])

df = pd.read_csv('Outfit_Selector_Spreadsheet.csv')
categ_array = df[df[choice] == 1]
outfit_list = select_by_inputs(categ_array)

#Selects 3 random elements of outfit_list and prints them.

def outfit_print():
    global rand_list
    if len(outfit_list) >= 3:
        rand_list = (np.random.choice(outfit_list, 3, replace=False))
    else:
        rand_list = (np.random.choice(outfit_list, len(outfit_list), replace=False))

    print('"'+choice+'", huh? Maybe one of these...') 
    print("\n")
    print("1.",rand_list[0])
    print("\n")
    print("2.",rand_list[1])
    print("\n")
    print("3.",rand_list[2])
    print("\n")
    
outfit_print()

while 1:
    reinput = input('Which did you choose? Or type "none" to reroll. ')
    if reinput in accepted_rein:
        #placeholder for use count increase code
        break
    elif reinput == 'none' or reinput == 'None':
        outfit_print()
    else:
        print("Oops! Enter '1', '2', or '3'")
        continue

#rechoice = rand_list[int(reinput)-1]
#df.loc[:,'Use_count']=0
#print(df)


# In[7]:

df = pd.read_csv("Outfit_Selector_Spreadsheet.csv")
weathered = (df[df["Weather_value"] <= 1])
print(weathered["Outfits"])

