Example #1
0
def writeRollBreakdownToCsv():
    maxRollTotal = max(points)  # Should be 6 * numberOfRolls!
    with open(f'breakdown-after-{numberOfRolls}-rolls.csv', 'w') as csvFile:
        csv = csvWriter(csvFile)
        csv.writerow(
            ['Roll #'] +
            [f'Ways to roll {total + 1}' for total in range(1, maxRollTotal)])
        for num, possibleTotals in sorted(rolls.items()):
            # Create an empty row, then fill in the totals
            row = [num] + [''] * (maxRollTotal - 1)
            for total, count in possibleTotals.items():
                row[total - 1] = count
            csv.writerow(row)
Example #2
0
 def __init__(self, username, password, query, output="output"):
     self.username = username
     self.password = password
     self.driver = webdriver.Firefox(r'/home/geckodriver')
     self.writer = csv.csvWriter(open(f"{output}.csv", "w"))
Example #3
0
def writePointsToCsv():
    with open(f'points-up-to-{numberOfRolls}-rolls.csv', 'w') as csvFile:
        csv = csvWriter(csvFile)
        csv.writerow(['Point Value', 'Number of Ways to Roll'])
        csv.writerows(sorted(points.items()))
Example #4
0
def rewriteArmorBase():
    path = "./source_data/armors/armorset_base.csv"
    out_path = "./source_data/armors/armorset_modified.csv"
    set_dict = {}
    with open(path, 'r') as input:
        reader = csvReader(input)
        header = None
        for idx, row in enumerate(reader):
            if idx == 0:
                header = [row[0]] + row[2:]
                continue
            if row[1] == "LR":
                continue

            set_name = row[0]
            words = set_name.split()
            #print (armor_name, "    ", [[ord(l) for l in e] for e in words])
            name = []
            for w in words:
                if len(w) == 1 and ord(w[0]) > 20000: continue
                name.append(w)
            name = '_'.join(name)

            info = row[2:]

            if name not in set_dict:
                set_dict[name] = [(1, info)]
            else:
                curr = set_dict[name][-1][0]
                set_dict[name].append((curr + 1, info))

        for key in set_dict:
            print (key, set_dict[key])
            pass

    out_file = open(out_path, 'w', newline='')
    writer = csvWriter(out_file)
    writer.writerow(header)
    suffix = {1: "alpha", 2: "beta", 3: "gamma"}
    for key in set_dict:
        row = None
        if len(set_dict[key]) == 1:
            set_name = key
            info = set_dict[key][0][1]
            for idx, part in enumerate(info):
                if idx == 0 or idx == 6: continue
                words = part.split()
                actual_name = []
                for w in words:
                    if len(w) == 1 and ord(w[0]) > 20000: continue
                    actual_name.append(w)
                actual_name = '_'.join(actual_name)
                info[idx] = actual_name

            row = [set_name] + info
            writer.writerow(row)
        else:
            for info in set_dict[key]:
                suff = suffix[info[0]]
                set_name = '_'.join([key, suff])

                for idx, part in enumerate(info[1]):
                    if idx == 0 or idx == 6 or part == "": continue
                    words = part.split()
                    actual_name = []
                    for w in words:
                        if len(w) == 1 and ord(w[0]) > 20000: continue
                        actual_name.append(w)
                    actual_name = '_'.join(actual_name + [suff])
                    info[1][idx] = actual_name

                row = [set_name] + info[1]
                writer.writerow(row)

    print ("done")
# movies = filter(lambda ele: ele[14] == "1898-01-01" or ele[14] == "1874-12-09", movies) # multiple movies at the same day + only one movie (for debugging)
movies = sorted(movies, key=lambda line: line[14])  # sort by date
print("Movies: " + str(len(movies)) + " (after filter)")

producer = KafkaProducer(
    bootstrap_servers=(KafkaConstants.BROKER_IP +
                       ":9092"))  # connect to kafka broker
curDate = date.strptime(movies[0][14], '%Y-%m-%d')  # start day
getDate = True  # flag for loop
rowDate = date(year=1900, month=1, day=1)  # declare holder

movieCount = 0  # count sent movies
for key, group in groupby(
        movies, key=lambda line: line[14]):  # group and iterate by date
    holder = BytesIO()  # fake file
    csvw = csvWriter(holder)
    getDate = True  # always get the current date of the first item in group

    checker = movieCount
    for item in group:  # iterate over movies in group
        if (getDate):
            rowDate = date.strptime(item[14],
                                    '%Y-%m-%d')  # date of the movie row
            getDate = False

        if (item[5] in credits):
            movieCount += 1
            csvw.writerow(item +
                          credits[item[5]])  # write movie with credit row
        else:
            print(str(rowDate) + " - Creditkey not found")