scripts/github_stats.py
def delete_last_line(self, file_path='', date=str(datetime.date.today())):
        """
        The following code was modified from
        http://stackoverflow.com/a/10289740 &
        http://stackoverflow.com/a/17309010
        It essentially will check if the total for the current date already
        exists in total.csv. If it does, it just removes the last line.
        This is so the script could be run more than once a day and not
        create many entries in the total.csv file for the same date.
        """
        deleted_line = False
        if os.path.isfile(file_path):
            with open(file_path, 'r+') as file:
                reader = csv.reader(file, delimiter=',')
                for row in reader:
                    if date == row[0]:
                        file.seek(0, os.SEEK_END)
                        pos = file.tell() - 1
                        while pos > 0 and file.read(1) != "\n":
                            pos -= 1
                            file.seek(pos, os.SEEK_SET)
                        if pos > 0:
                            file.seek(pos, os.SEEK_SET)
                            file.truncate()
                            deleted_line = True
                            break
                if deleted_line: file.write('\n')
            file.close()
def delete_last_line(self, file_path='', date=str(datetime.date.today())):
        """
        The following code was modified from
        http://stackoverflow.com/a/10289740 &
        http://stackoverflow.com/a/17309010
        It essentially will check if the total for the current date already
        exists in total.csv. If it does, it just removes the last line.
        This is so the script could be run more than once a day and not
        create many entries in the total.csv file for the same date.
        """
        deleted_line = False
        if os.path.isfile(file_path):
            with open(file_path, 'r+') as file:
                reader = csv.reader(file, delimiter=',')
                for row in reader:
                    if date == row[0]:
                        file.seek(0, os.SEEK_END)
                        pos = file.tell() - 1
                        while pos > 0 and file.read(1) != "\n":
                            pos -= 1
                            file.seek(pos, os.SEEK_SET)
                        if pos > 0:
                            file.seek(pos, os.SEEK_SET)
                            file.truncate()
                            deleted_line = True
                            break
                if deleted_line: file.write('\n')
            file.close()
The following code was modified from
        http://stackoverflow.com/a/10289740 &
        http://stackoverflow.com/a/17309010
        It essentially will check if the total for the current date already
        exists in total.csv. If it does, it just removes the last line.
        This is so the script could be run more than once a day and not
        create many entries in the total.csv file for the same date.