scripts/step2.py
def parse_file(file_name, file_date):
    """Parses a .html file and extracts values of interest using lxml.

    Parameters
    ----------
    file_name : str
        The name of the file to be parsed.

    """

    with open(file_name, "r", encoding="utf-8") as temp_file:

        # Remove the time from from the file date.
        file_date = file_date.split()[0]

        # Parse the HTML document.
        html = lxml.html.fromstring(temp_file.read())

        name = html.xpath("//small[1]")[0].text.split("-")[0].lower().strip()

        clean_words = list()

        for word in name.split(" "):
            if word != "a" and word != "de" and word != "en" and not word.isdigit():
                clean_words.append(word)

        clean_name = clean_word(" ".join(clean_words))

        salary = html.xpath(
            "//strong[contains(text(),'Salario neto mensual:')]/following-sibling::span")[0].text.strip()

        clean_salary = int(float(salary.replace("$", "").replace(",", "")))

        hours = html.xpath(
            "//strong[contains(text(),'Horario de trabajo:')]/following-sibling::span")[0].text.split()

        start_hour = int(hours[0].replace(":", ""))
        end_hour = int(hours[2].replace(":", ""))

        if start_hour >= end_hour:
            hours_worked = ((end_hour+2400) - start_hour) / 100
        else:
            hours_worked = (end_hour - start_hour) / 100

        work_days = html.xpath(
            "//strong[contains(text(),'Días laborales:')]/following-sibling::span")[0].text.strip()

        monday = 1 if "L" in work_days else 0
        tuesday = 1 if "Ma" in work_days else 0
        wednesday = 1 if "Mi" in work_days else 0
        thursday = 1 if "J" in work_days else 0
        friday = 1 if "V" in work_days else 0
        saturday = 1 if "S" in work_days else 0
        sunday = 1 if "D" in work_days else 0

        days_worked = monday + tuesday + wednesday + \
            thursday + friday + saturday + sunday

        location = html.xpath(
            "//strong[contains(text(),'Ubicación:')]/following-sibling::span")[0].text.strip()

        state, municipality = location.split(",")

        education_level = html.xpath(
            "//strong[contains(text(),'Estudios Solicitados:')]/following-sibling::div")[0].text.strip()

        languages = html.xpath(
            "//strong[contains(text(),'Idiomas:')]/following-sibling::div")[0].text.strip()

        try:
            experience = html.xpath(
                "//strong[contains(text(),'Experiencia:')]/following-sibling::div")[0].text.strip()
        except:
            experience = "No especificada"

        try:
            contract_type = html.xpath(
                "//strong[contains(text(),'Tipo de contrato:')]/following-sibling::span")[0].text.strip()
        except:
            contract_type = "No especificado"

        data_list.append((file_date, clean_name, clean_salary, contract_type,
                          start_hour, end_hour, hours_worked, monday, tuesday,
                          wednesday, thursday, friday, saturday, sunday, days_worked,
                          state.strip(), municipality.strip(), education_level, experience,
                          languages))
Parses a .html file and extracts values of interest using lxml.

    Parameters
    ----------
    file_name : str
        The name of the file to be parsed.

    
Parses a .html file and extracts values of interest using lxml.
Parameters

file_name : str
The name of the file to be parsed.
Parses a . html file and extracts values of interest using lxml . Parameters file_name : str The name of the file to be parsed .
def parse_file(file_name, file_date):
    with open(file_name, "r", encoding="utf-8") as temp_file:
        file_date = file_date.split()[0]
        html = lxml.html.fromstring(temp_file.read())
        name = html.xpath("//small[1]")[0].text.split("-")[0].lower().strip()
        clean_words = list()
        for word in name.split(" "):
            if word != "a" and word != "de" and word != "en" and not word.isdigit():
                clean_words.append(word)
        clean_name = clean_word(" ".join(clean_words))
        salary = html.xpath(
            "//strong[contains(text(),'Salario neto mensual:')]/following-sibling::span")[0].text.strip()
        clean_salary = int(float(salary.replace("$", "").replace(",", "")))
        hours = html.xpath(
            "//strong[contains(text(),'Horario de trabajo:')]/following-sibling::span")[0].text.split()
        start_hour = int(hours[0].replace(":", ""))
        end_hour = int(hours[2].replace(":", ""))
        if start_hour >= end_hour:
            hours_worked = ((end_hour+2400) - start_hour) / 100
        else:
            hours_worked = (end_hour - start_hour) / 100
        work_days = html.xpath(
            "//strong[contains(text(),'Días laborales:')]/following-sibling::span")[0].text.strip()
        monday = 1 if "L" in work_days else 0
        tuesday = 1 if "Ma" in work_days else 0
        wednesday = 1 if "Mi" in work_days else 0
        thursday = 1 if "J" in work_days else 0
        friday = 1 if "V" in work_days else 0
        saturday = 1 if "S" in work_days else 0
        sunday = 1 if "D" in work_days else 0
        days_worked = monday + tuesday + wednesday + \
            thursday + friday + saturday + sunday
        location = html.xpath(
            "//strong[contains(text(),'Ubicación:')]/following-sibling::span")[0].text.strip()
        state, municipality = location.split(",")
        education_level = html.xpath(
            "//strong[contains(text(),'Estudios Solicitados:')]/following-sibling::div")[0].text.strip()
        languages = html.xpath(
            "//strong[contains(text(),'Idiomas:')]/following-sibling::div")[0].text.strip()
        try:
            experience = html.xpath(
                "//strong[contains(text(),'Experiencia:')]/following-sibling::div")[0].text.strip()
        except:
            experience = "No especificada"
        try:
            contract_type = html.xpath(
                "//strong[contains(text(),'Tipo de contrato:')]/following-sibling::span")[0].text.strip()
        except:
            contract_type = "No especificado"
        data_list.append((file_date, clean_name, clean_salary, contract_type,
                          start_hour, end_hour, hours_worked, monday, tuesday,
                          wednesday, thursday, friday, saturday, sunday, days_worked,
                          state.strip(), municipality.strip(), education_level, experience,
                          languages))
def parse_file ( file_name , file_date ) : with open ( file_name , "r" , encoding = "utf-8" ) as temp_file : file_date = file_date . split ( ) [ 0 ] html = lxml . html . fromstring ( temp_file . read ( ) ) name = html . xpath ( "//small[1]" ) [ 0 ] . text . split ( "-" ) [ 0 ] . lower ( ) . strip ( ) clean_words = list ( ) for word in name . split ( " " ) : if word != "a" and word != "de" and word != "en" and not word . isdigit ( ) : clean_words . append ( word ) clean_name = clean_word ( " " . join ( clean_words ) ) salary = html . xpath ( "//strong[contains(text(),'Salario neto mensual:')]/following-sibling::span" ) [ 0 ] . text . strip ( ) clean_salary = int ( float ( salary . replace ( "$" , "" ) . replace ( "," , "" ) ) ) hours = html . xpath ( "//strong[contains(text(),'Horario de trabajo:')]/following-sibling::span" ) [ 0 ] . text . split ( ) start_hour = int ( hours [ 0 ] . replace ( ":" , "" ) ) end_hour = int ( hours [ 2 ] . replace ( ":" , "" ) ) if start_hour >= end_hour : hours_worked = ( ( end_hour + 2400 ) - start_hour ) / 100 else : hours_worked = ( end_hour - start_hour ) / 100 work_days = html . xpath ( "//strong[contains(text(),'Días laborales:')]/following-sibling::span") [ 0 ] . t ext. s trip( ) monday = 1 if "L" in work_days else 0 tuesday = 1 if "Ma" in work_days else 0 wednesday = 1 if "Mi" in work_days else 0 thursday = 1 if "J" in work_days else 0 friday = 1 if "V" in work_days else 0 saturday = 1 if "S" in work_days else 0 sunday = 1 if "D" in work_days else 0 days_worked = monday + tuesday + wednesday + thursday + friday + saturday + sunday location = html . xpath ( "//strong[contains(text(),'Ubicación:')]/following-sibling::span") [ 0 ] . t ext. s trip( ) state , municipality = location . split ( "," ) education_level = html . xpath ( "//strong[contains(text(),'Estudios Solicitados:')]/following-sibling::div" ) [ 0 ] . text . strip ( ) languages = html . xpath ( "//strong[contains(text(),'Idiomas:')]/following-sibling::div" ) [ 0 ] . text . strip ( ) try : experience = html . xpath ( "//strong[contains(text(),'Experiencia:')]/following-sibling::div" ) [ 0 ] . text . strip ( ) except : experience = "No especificada" try : contract_type = html . xpath ( "//strong[contains(text(),'Tipo de contrato:')]/following-sibling::span" ) [ 0 ] . text . strip ( ) except : contract_type = "No especificado" data_list . append ( ( file_date , clean_name , clean_salary , contract_type , start_hour , end_hour , hours_worked , monday , tuesday , wednesday , thursday , friday , saturday , sunday , days_worked , state . strip ( ) , municipality . strip ( ) , education_level , experience , languages ) )
Parses a .html file and extracts values of interest using lxml.
Parses a . html file and extracts values of interest using lxml .
"""Parses a .html file and extracts values of interest using lxml.

    Parameters
    ----------
    file_name : str
        The name of the file to be parsed.

    """ # Remove the time from from the file date. # Parse the HTML document.
file_name
file_date