summaryrefslogtreecommitdiff
path: root/outdated/reformat/redormat.py
blob: 75b2d950492b4dcd265a477977c2e36841d03985 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#! /usr/bin/env python2.6
# -*- coding: utf8 -*-

import os
import re

def calcSize(str):
	sz = 0
	for chr in str:
		if chr != '\t':
			sz = sz + 1
	return sz + 1



strre = re.compile(",")
with open ("item_db.txt", "r") as r:
	with open ("item_db2.txt", "w") as w:
		lines = [];
		for line in r:
			arr = strre.split(line)
			if line[0] == '#':
				lines.append(line)
				continue
			text = []
		
			for item in arr:
				text.append(item.strip())

			lines.append(text)

		maxSize = 0
		minSize = 100
		for line in lines:
			if len(line[1]) > 1:
				if len(line) > maxSize:
					maxSize = len(line)
				if len(line) < minSize:
					minSize = len(line)

		minSize = 19
		sizes = []
		for k in range(0, minSize):
			sz = 6
			for line in lines:
				if len(line[k]) > sz:
					sz = len(line[k])
			if sz < 3:
				sz = 4
			elif sz > 6:
				sz = 24
			sizes.append(sz + 1)
	
		print sizes
		for k in range(0, minSize):
			for line in lines:
				if len(line[1]) > 1:
					line[k] = line[k] + ","
					while len(line[k]) < sizes[k]:
						line[k] = line[k] + " "

		for line in lines:
			if len(line[1]) == 1:
				w.write(line)
			else:
				for item in line:
					w.write(item)
				w.write("\n")

		print minSize
		print maxSize