<commit_before>from __future__ import absolute_import

import datetime
import calendar
import sqlite3
import numpy as np
from sunpy.time import parse_time
import sunpy.net.download
import urllib

def download_lytaf_database(lytaf_dir=''):
    """download the latest version of the Proba-2 pointing database from the Proba2 Science Center"""
    #dl=sunpy.net.download.Downloader()
    #dl.download('http://proba2.oma.be/lyra/data/lytaf/annotation_ppt.db',path=lytaf_dir)
    url='http://proba2.oma.be/lyra/data/lytaf/annotation_ppt.db'
    urllib.urlretrieve(url,lytaf_dir+'annotation_ppt.db')
    
    return


def get_lytaf_events(timerange,lytaf_dir=''):
    """returns a list of LYRA pointing events that occured during a timerange"""
    #timerange is a TimeRange object
    #start_ts and end_ts need to be unix timestamps
    st_timerange = timerange.start()
    start_ts=calendar.timegm(st_timerange.timetuple())
    en_timerange=timerange.end()
    end_ts=calendar.timegm(en_timerange.timetuple())
    
    #involves executing SQLite commands from within python.
    #connect to the SQlite database
    conn=sqlite3.connect(lytaf_dir + 'annotation_ppt.db')
    cursor=conn.cursor()

    #create a substitute tuple out of the start and end times for using in the database query
    query_tup=(start_ts,end_ts,start_ts,end_ts,start_ts,end_ts)

    #search only for events within the time range of interest (the lightcurve start/end). Return records ordered by start time
    result=(cursor.execute('select * from event WHERE((begin_time > ? AND begin_time < ?) OR (end_time > ? AND end_time < ?)' +  <commit_msg>now use os module to make specification of the lytaf_dir a bit more flexible.<commit_after>from __future__ import absolute_import

import datetime
import calendar
import sqlite3
import numpy as np
import os
from sunpy.time import parse_time
import sunpy.net.download
import urllib

def download_lytaf_database(lytaf_dir=''):
    """download the latest version of the Proba-2 pointing database from the Proba2 Science Center"""
    #dl=sunpy.net.download.Downloader()
    #dl.download('http://proba2.oma.be/lyra/data/lytaf/annotation_ppt.db',path=lytaf_dir)
    url='http://proba2.oma.be/lyra/data/lytaf/annotation_ppt.db'
    destination=os.path.join(lytaf_dir,'annotation_ppt.db')
    urllib.urlretrieve(url,destination)
    
    return


def get_lytaf_events(timerange,lytaf_dir=''):
    """returns a list of LYRA pointing events that occured during a timerange"""
    #timerange is a TimeRange object
    #start_ts and end_ts need to be unix timestamps
    st_timerange = timerange.start()
    start_ts=calendar.timegm(st_timerange.timetuple())
    en_timerange=timerange.end()
    end_ts=calendar.timegm(en_timerange.timetuple())
    
    #involves executing SQLite commands from within python.
    #connect to the SQlite database
    #conn=sqlite3.connect(lytaf_dir + 'annotation_ppt.db')
    conn=sqlite3.connect(os.path.join(lytaf_dir,'annotation_ppt.db'))
    cursor=conn.cursor()

    #create a substitute tuple out of the start and end times for using in the database query
    query_tup=(start_ts,end_ts,start_ts,end_ts,start_ts,end_ts)

    #search only for events within the time range of interest (the lightcurve start/end). Return records ordered by start time
    result=(cursor.execute('select * from event WHERE((begin_time > ? AND begin_time < ?) OR (end_time > ? AND end_time < ?)' +  
{'fraction_non_alphanumeric': 0.09436167104878761, 'fraction_numerical': 0.0037978381536663743, 'mean_word_length': 4.567479674796748, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4359894', 'n_tokens_mistral': 1128, 'n_tokens_neox': 1107, 'n_words': 291}