<commit_before>""" Find sales prices of various (or all?) types of properties sold in a given
period of time and prepare for plotting on a map with R
"""

# It is possible that the module 'vincent' could do the plotting

import requests, bs4, datetime, math

currentYear = datetime.datetime.now().year
propertyTypes = ['villa','ejerlejlighed']

def numPages(firstYear, lastYear, propType):
    """ Find the number of pages we have to iterate through to get all the results we want.
    Each page contains 40 results.
    """
    # Get the page and check the result is good
    resPropNo = requests.get('http://www.boliga.dk/salg/resultater?so=1&type=' + propType + '&fraPostnr=1000&tilPostnr=9990&minsaledate=' + firstYear + '&maxsaledate=' + lastYear)
    resPropNo.raise_for_status()

    # Parse the result
    propNoSoup = bs4.BeautifulSoup(resPropNo.text, 'html.parser')

    # Extract the total number of results from the text above the results table
    propNoArr = propNoSoup.select('td[class="text-center"] > label')[0].getText().split()
    for i in range(len(propNoArr)):
        try:
            # Is the element a number?
            int(propNoArr[i])
        except ValueError:
            # Not a number, next element
            continue
        # The only element that is a number is the total number of results
        propNo = propNoArr[i]

    # Return value is the number of pages with 40 results per page
    pageNo = math.ceil(propNo, 40)

    return pageNo

while True:
    try:
        startYear = int(input("Starting year: ")) # Should probably default to the current year
    except ValueError:
        # User did not enter a valid year
        print("Please enter a year between 1992 and " + str(currentYear) + ".")
        # Back to start
        continue
    if startYear < 1992 or startYear > currentYear:
        # There are no data before 1992 or for the future
        print("Please enter a year between 1992 and " + str(currentYear) + ".")
        # Back to start
        continue
    else:<commit_msg>Started writing function to get property prices.<commit_after>""" Find sales prices of various (or all?) types of properties sold in a given
period of time and prepare for plotting on a map with R
"""

# It is possible that the module 'vincent' could do the plotting

import requests, bs4, datetime, math

currentYear = datetime.datetime.now().year
propertyTypes = ['villa','ejerlejlighed']

def numPages(firstYear, lastYear, propType):
    """ Find the number of pages we have to iterate through to get all the
    results we want. Each page contains 40 results; this should probably be
    verified by looking at the text.
    """
    # Get the page and check the result is good
    resPropNo = requests.get('http://www.boliga.dk/salg/resultater?so=1&type=' + propType + '&fraPostnr=1000&tilPostnr=9990&minsaledate=' + firstYear + '&maxsaledate=' + lastYear)
    resPropNo.raise_for_status()

    # Parse the result
    propNoSoup = bs4.BeautifulSoup(resPropNo.text, 'html.parser')

    # Extract the total number of results from the text above the results table
    propNoArr = propNoSoup.select('td[class="text-center"] > label')[0].getText().split()
    for i in range(len(propNoArr)):
        try:
            # Is the element a number?
            int(propNoArr[i])
        except ValueError:
            # Not a number, next element
            continue
        # The only element that is a number is the total number of results
        propNo = propNoArr[i]

    # Return value is the number of pages with 40 results per page
    pageNo = math.ceil(propNo, 40)

    return pageNo

def getPrices(firstYear, lastYear, propType):
    """ Get the prices of the given property type for the given years. Also
    extract the addresses, we will use these to find the geographic
    coordinates of the properties later.
    """

while True:
    try:
        startYear = int(input("Starting year: ")) # Should probably default to the current year
    except ValueError:
        # User did not enter a valid year
        print("Please enter a year between 1992 and " + str(currentYear) + ".")
        # Back to start
        continue
    if startYear < 1992 or startYear > currentYear:
        # There are no data before 1992 or for the future
        print("Please enter a year between 1992 and " + str(currentYear) + ".")
        # Back to start
        continue
    else:
{'fraction_non_alphanumeric': 0.08616780045351474, 'fraction_numerical': 0.015419501133786848, 'mean_word_length': 2.938392857142857, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '1594844', 'n_tokens_mistral': 1292, 'n_tokens_neox': 1216, 'n_words': 500}