<commit_before>from influxdb import InfluxDBClient
import os
import re
import datetime
import calendar
from stravalib.client import Client

######### Variables ############

path_for_files = "./authfiles/"
influxhost = "localhost"
influxport = "8086"
influxuser = "root"
influxpassword = "<PASSWORD>"
influxdbname = "strava"

strava = Client()
fluxdb = InfluxDBClient(influxhost, influxport, influxuser, influxpassword, influxdbname)


######### Functions ############


def initialise_db():
    print "...create database: ", influxdbname
    fluxdb.create_database(influxdbname)

    query = "select last(counter) from strava_activity"
    print "...queying last activity from DB" + influxdbname + " with query: '" + query + "'"

    result = list(fluxdb.query(query))
    print "...received result "

    db_results = []
    if result:
        for row in result[0]: counter = row.get("last")
        for row in result[0]: last_strava_activity = row.get("time")
        
        print "...last activity in DB " + influxdbname + " is: ", last_strava_activity

        db_results.append(counter)
        db_results.append(last_strava_activity)
    else:
        counter = 0
        last_strava_activity = "1970-01-01T00:00:01Z"

        print "...empty or no DB. getting all activities since 1970"
        
        db_results.append(counter)
        db_results.append(last_strava_activity)

    return db_results



def get_string_from_file(file):
    if os.path.exists(path_for_files + file):
        with open(path_for_files + file, 'r') as string_from_file:
            global string
            string = string_from_file.read().replace('\n', '')
            print "...reading " + path_for_files + file 
            print "...reading ", file <commit_msg>dont break when DB is corrupt<commit_after>from influxdb import InfluxDBClient
import os
import re
import datetime
import calendar
from stravalib.client import Client

######### Variables ############

path_for_files = "./authfiles/"
influxhost = "localhost"
influxport = "8086"
influxuser = "root"
influxpassword = "<PASSWORD>"
influxdbname = "strava"

strava = Client()
fluxdb = InfluxDBClient(influxhost, influxport, influxuser, influxpassword, influxdbname)


######### Functions ############


def initialise_db():
    print "...create database: ", influxdbname
    fluxdb.create_database(influxdbname)

    query = "select last(counter) from strava_activity"
    print "...queying last activity from DB" + influxdbname + " with query: '" + query + "'"

    result = list(fluxdb.query(query))
    print "...received result "

    db_results = []
    if result:
        for row in result[0]: counter = row.get("last")
        if counter == "None": counter = 0
        for row in result[0]: last_strava_activity = row.get("time")
        
        print "...last activity in DB " + influxdbname + " is: ", last_strava_activity

        db_results.append(counter)
        db_results.append(last_strava_activity)
    else:
        counter = 0
        last_strava_activity = "1970-01-01T00:00:01Z"

        print "...empty or no DB. getting all activities since 1970"
        
        db_results.append(counter)
        db_results.append(last_strava_activity)

    print "CCC", db_results
    return db_results



def get_string_from_file(file):
    if os.path.exists(path_for_files + file):
        with open(path_for_files + file, 'r') as string_from_file:
            global string
            string = string_from_file.read().replace('\n', '')
            print "...reading " + path_for_files + file 
            print "...reading ", file 
{'fraction_non_alphanumeric': 0.1281267370761534, 'fraction_numerical': 0.014174541411895497, 'mean_word_length': 3.0620767494356658, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '5285801', 'n_tokens_mistral': 1158, 'n_tokens_neox': 1073, 'n_words': 275}