示例#1
0
def CheckIfFileExists(pth_to_check):
    global _write_mode

    if os.path.isfile(pth_to_check):
        print("Default file name --> ", pth_to_check, ", already exists.")
        print("   Enter option: ")
        print("   'write (w)'            : to OVERWRITE file")
        print("   'append (a)'           : to APPEND file")
        print("   new_file_name: to create NEW file")
        user_in = input("--> ").lower()

        if (any(val == user_in.lower()
                for val in Utils._write_modes.keys())) or any(
                    val == user_in.lower()
                    for val in Utils._write_modes.values()):
            if user_in == 'a' or user_in == 'append':
                CsvHand.SetSaveMode('append')

            if user_in == 'w' or user_in == 'write':
                CsvHand.SetSaveMode('write')
                CsvHand.StartNewFile()
        else:
            #create new file given name
            Utils.SetMarkedFileName(user_in)
            while os.path.isfile(Utils.GetSavePath()):
                print("The file: " + Utils.GetSavePath() + " already exists.")
                Utils.SetMarkedFileName(input("Enter new file name: "))
            CsvHand.StartNewFile()

    else:
        CsvHand.StartNewFile()

    print("--> Marked files will be stored at location: " +
          (Utils.GetSavePath()))
    input("--> Press ENTER key")
def loadHeroes():
    """Function that loads the heroes from a csv file into a list"""
    hero_list = []
    f = open('marvel.csv')
    marvelFile = csv.reader(f)
    for line in marvelFile:
        marvel_list = CsvHandler.split(line[0], ";")
        hero_list.append(Hero(marvel_list[0], [marvel_list[1], marvel_list[2], marvel_list[3]]))
    return hero_list
def loadHighscore(sortType = "None"):
    f = open('highscores.csv', 'r')
    file = csv.reader(f)
    highscore_list = []
    for row in file:
        row_list = CsvHandler.split(row[0], ";")
        scoreDing = Highscore(row_list[2], row_list[1], row_list[3], row_list[0])
        highscore_list.append(scoreDing)
    return highscore_list
def loadScores(fileName, sc):
    fileName += ".csv"
    file = open(fileName, "r")
    bestand = csv.reader(file)
    outputString = ""
    count = 1
    for row in bestand:
        punten = CsvHandler.split(row[0], ";")
        outputString = outputString + str(count) + ": " + punten[2] + " - Score: " + punten[1] + " - Date: " + punten[0] + "\n"
        count += 1
    sc.set(outputString)
    def save(self):
        dagmaandjaarList = CsvHandler.split(self.TimeStamp, "/")
        stScore = str(self.Score)
        if(len(stScore) == 1):
            stScore = "0" + stScore
        stSeconds = str(self.Seconds)
        if len(stSeconds) < 4:
            for i in range(4 - len(stSeconds)):
                stSeconds = "0" + stSeconds

        with open('highscores.csv', 'a+', newline='') as csvfile:
            winnaars = csv.writer(csvfile, delimiter=";")
            winnaars.writerow([self.TimeStamp, stScore, self.UserName, stSeconds,dagmaandjaarList[0], dagmaandjaarList[1], dagmaandjaarList[2]])
示例#6
0
        sys.stdout.write(" " * numOfWhiteSpace)
        print("[  OK  ]")
        # sys.stdout.flush()

    def printFail(self):
        numOfWhiteSpace = self.consoleLength - self.usedLength - 8
        sys.stdout.write("[-] %s" % self.processText)
        sys.stdout.write(" " * numOfWhiteSpace)
        print("[ FAIL ]")
        # sys.stdout.flush()


if __name__ == "__main__":
    CSVFILE = "C:\\Users\\emrecan\\Documents\\PythonWin32Automation\\test.csv"

    cH = CsvHandler.CsvHandler()
    # PathFinder is the class that finds the .doc files in specified directories.
    pF = PathFinder()
    pp = PrettyPrint(50)

    pp.printProcess("Checking csv file")
    if not pF.checkIfFileExists(CSVFILE):
        pp.printFail()
        pp.printError("The csv file does not exist! Exitting!!!")
        sys.exit(10)
    pp.printOk()

    pp.printProcess("Reading csv file")
    cH.readCsvFile(CSVFILE)
    pp.printOk()
__author__ = 'Brent'

import csv
import operator
import CsvHandler
import time

bestand = open('highscores.csv', 'r')

reader = csv.reader(bestand, delimiter=";")

sort = sorted(reader, key=operator.itemgetter(1), reverse=True)

datum = time.strftime("%x")
maand = CsvHandler.split(time.strftime("%x"),"/")
maand = maand[0]

open("sortedlist.csv", 'w')

for eachline in sort:
    # print(eachline)
    with open("sortedlist.csv", 'a', newline='') as csvfile:
        bla = csv.writer(csvfile, delimiter=';')
        bla.writerow([eachline[0], eachline[1], eachline[2], eachline[3], eachline[4], eachline[5], eachline[6]])

def daily():
    file = open("highscores.csv", 'r')
    lezer = csv.reader(file, delimiter=';')
    surt = sorted(lezer, key=operator.itemgetter(5), reverse=False)
    surt = sorted(surt, key=operator.itemgetter(1), reverse=True)
    open('daily.csv', 'w')
示例#8
0
def Help():
    print("*************************")
    print("-quit: quit program")
    print("-skip: move to next task")
    print("-------------------------")
    print("Valid status inputs:")
    print("\td    : discuss")
    print("\tdemo : demonstrate")
    print("\tfix  : fix and resubmit")
    print("\tredo : start again")
    print("*************************")
    input("HIT ENTER TO CONTINUE!")


SubHand.LoadAndSortFileData(Utils.f_to_mark)
CsvHand.LoadCSV(Utils.f_to_mark)
command = ""

CheckIfFileExists(Utils.f_marked + Utils._f_name_marked)

while '-quit' not in command and SubHand._task_idx < len(SubHand._sorted_pdfs):
    SubHand.OpenNextSubmissionPdf()
    stu_num_and_task = SubHand.GetCurrentStudentNumAndTaskNum()
    CsvHand.PrintStudentInfo(stu_num_and_task[0], stu_num_and_task[1])

    status, comment = GetUserInput()

    if any(com == status for com in ['-quit', '-q']):
        break
    elif any(com == status for com in ['-skip', '-sk']):
        SubHand.IteratePdfIdx()
示例#9
0
def exportMD5():
    csvHandler._writeMD5Csv()
示例#10
0
import X2CCsv
import CsvHandler as csvHandler

# def xlsx_to_csv():
    # filepath_list = getList()
    # for item in filepath_list:
    #     x2c.xlsx_to_csv(item[0],item[1])

# def getCSVList():
#
def exportMD5():
    csvHandler._writeMD5Csv()

if __name__ == '__main__':
    # xlsx_to_csv()
    x2c = X2CCsv.X2CCsv
    for item in csvHandler._getImportAndExportList():
        x2c.xlsx_to_csv(list=item)
    exportMD5()
示例#11
0
# Generates a set of test courses which are valid
from ObstacleGenerator import *
from CsvHandler import *

numCourses = 1000

for i in range(numCourses):
    # The course generated with obstacles and has a solution
    course = ObstacleGenerator()
    course.generate()

    field = ObstacleField(72, 96, 24, 34, 24, 6, course.pointobjects)

    # Used to save the file
    csvObj = CsvHandler()
    csvObj.addFieldToTable(field)
    fileName = "Test" + str(i)
    print(fileName)
    csvObj.saveTableToFile(fileName)