#!/usr/bin/python
# -*- coding: utf-8 -*-

from operator import itemgetter, attrgetter, methodcaller
import csv
import os
import re

genders = dict(men=0, woman=0)
womens = ["WOMAN", 'GIRL', "PIZZA GIRLS FEAR",'COOL GIRLS ANGER','MOMS DISGUST','COOL GIRLS FEAR'
          ,'TEACHERS FEAR','RILEY','MEG','MOMS FEAR'
          ,'JORDAN','MOM','MOMS SADNESS','TEACHER','TEACHERS SADNESS','TEACHERS JOY','PIZZA GIRLS ANGER','COOL GIRL'
          ,'FEAR AND DISGUST','SADNESS','COOL GIRLS SADNESS','RILEYS TEACHER','PIZZA GIRL','MOMS JOY','JOY','MOMS ANGER','ANGER','FEAR']

origin = 'CountWords'
destination = 'GendersCount'

filename = 'InsideOut.csv'

if os.path.exists(os.path.join(os.getcwd(), destination)) == False:
    os.mkdir(os.path.join(os.getcwd(), destination))

with open(os.path.join(os.path.join(os.getcwd(), origin), filename), 'r') as reader:
    for z in range(2):
        reader.readline()
    for line in reader:

        datos = line.split(';')
        if womens.count(datos[0].upper()) > 0:
            genders["woman"] = genders["woman"] + int(datos[1])
        elif datos[0] == '' or datos[1] == '':
            pass
        else:
            genders["men"] = genders["men"] + int(datos[1])

with open(os.path.join(os.path.join(os.getcwd(), destination), filename), 'w') as writer:
    writer.write(filename[:-(len(filename)-filename.find('.'))] + '\n')

    for key, value in genders.items():
        writer.write(key + ';' + str(value)+';\n')


del genders

#!/usr/bin/python
# -*- coding: utf-8 -*-

from operator import itemgetter, attrgetter, methodcaller
import csv
import os
import re

genders = dict(men=0, woman=0)
womens = ["WOMAN", 'GIRL', "PIZZA GIRLS FEAR",'COOL GIRLS ANGER','MOMS DISGUST','COOL GIRLS FEAR'
          ,'TEACHERS FEAR','RILEY','MEG','MOMS FEAR'
          ,'JORDAN','MOM','MOMS SADNESS','TEACHER','TEACHERS SADNESS','TEACHERS JOY','PIZZA GIRLS ANGER','COOL GIRL'
          ,'FEAR AND DISGUST','SADNESS','COOL GIRLS SADNESS','RILEYS TEACHER','PIZZA GIRL','MOMS JOY','JOY','MOMS ANGER','ANGER','FEAR']

origin = 'CountWords'
destination = 'GendersCount'

filename = 'InsideOut.csv'

if os.path.exists(os.path.join(os.getcwd(), destination)) == False:
    os.mkdir(os.path.join(os.getcwd(), destination))

with open(os.path.join(os.path.join(os.getcwd(), origin), filename), 'r') as reader:
    for z in range(2):
        reader.readline()
    for line in reader:

        datos = line.split(';')
        if womens.count(datos[0].upper()) > 0:
            genders["woman"] = genders["woman"] + int(datos[1])
        elif datos[0] == '' or datos[1] == '':
            pass
        else:
            genders["men"] = genders["men"] + int(datos[1])

with open(os.path.join(os.path.join(os.getcwd(), destination), filename), 'w') as writer:
    writer.write(filename[:-(len(filename)-filename.find('.'))] + '\n')

    for key, value in genders.items():
        writer.write(key + ';' + str(value)+';\n')


del genders

#!/usr/bin/python # -*- coding: utf-8 -*-