<commit_before>import os, os.path
from datetime import date, datetime
from mako.template import Template
from connect import Session
from model import *
from logger import log

def generate_template(products):
    template = Template(filename='template.xml')
    return template.render(data=products)

if __name__ == '__main__':
    session = Session()
    products = session.query(Product) \
                      .filter_by(status='pending') \
                      .filter(Product.start_date < datetime.now()) \
                      .filter(Product.end_date > datetime.now()) \
                      .order_by(Product.id)
    xml = generate_template(products)
    log.info('Generated feed of %s items to %s' % (products.count(),
                                                   XML_FILENAME))

    xml_path = 'feed/' + XML_FILENAME 
    if os.path.exists(xml_path):
        today = date.today()
        date_string = '_' + str(today.month) + '-' + str(today.day)
        new_name = xml_path.split('.')[0] + date_string + '.xml'
        os.rename(xml_path, new_name)

    try:
        file = open(xml_path, 'w')
    except IOError:
        if not os.path.exists('feed'):
            os.mkdir('feed')
            file = open(xml_path, 'w')
    file.write(xml)
<commit_msg>Added proper handling of file paths when executed outside of the package's directory.<commit_after>import os, os.path
from datetime import date, datetime
from mako.template import Template
from connect import Session
from model import *
from logger import log

def generate_template(products):
    template = Template(filename=os.path.join(os.path.dirname(__file__),
                                              'template.xml'))
    return template.render(data=products)

if __name__ == '__main__':
    session = Session()
    products = session.query(Product) \
                      .filter_by(status='pending') \
                      .filter(Product.start_date < datetime.now()) \
                      .filter(Product.end_date > datetime.now()) \
                      .order_by(Product.id)
    xml = generate_template(products)
    log.info('Generated feed of %s items to %s' % (products.count(),
                                                   XML_FILENAME))

    xml_path = os.path.join(os.path.dirname(__file__), 'feed/') + XML_FILENAME 
    if os.path.exists(xml_path):
        today = date.today()
        date_string = '_' + str(today.month) + '-' + str(today.day)
        new_name = xml_path.split('.')[0] + date_string + '.xml'
        os.rename(xml_path, new_name)

    try:
        file = open(xml_path, 'w')
    except IOError:
        if not os.path.exists('feed'):
            os.mkdir('feed')
            file = open(xml_path, 'w')
    file.write(xml)

{'fraction_non_alphanumeric': 0.12136627906976744, 'fraction_numerical': 0.0007267441860465116, 'mean_word_length': 2.128409090909091, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 20}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1948409', 'n_tokens_mistral': 796, 'n_tokens_neox': 770, 'n_words': 180}