38
38
#############################
39
39
def readfile (name ):
40
40
print ("Reading file " + name + "..." )
41
- with open (name , "r" ) as f :
42
- lines = f .read ().splitlines ()
41
+ try :
42
+ with open (name , "r" ) as f :
43
+ lines = f .read ().splitlines ()
44
+ except :
45
+ try :
46
+ with open (name , "r" , encoding = 'utf-8' ) as f :
47
+ lines = f .read ().splitlines ()
48
+ except :
49
+ try :
50
+ with open (name , "r" , encoding = 'utf-8-sig' ) as f :
51
+ lines = f .read ().splitlines ()
52
+ except :
53
+ print ("Could not read file " + name + "!" )
43
54
tags = collections .OrderedDict ()
44
55
45
56
open_blocks = 0
@@ -100,8 +111,8 @@ def readfile(name):
100
111
temp_line = re .sub ('\s' , "" , temp_line )
101
112
temp_line .strip ()
102
113
tags [temp_line ] = None
103
- open_blocks += re . sub ( r'\".*?\"' , '' , line ) .count ('{' )
104
- open_blocks -= re . sub ( r'\".*?\"' , '' , line ) .count ('}' )
114
+ open_blocks += line .count ('{' )
115
+ open_blocks -= line .count ('}' )
105
116
106
117
print ("File " + name + " read successfully!" )
107
118
return list (tags .keys ()), (is_event_file , is_focus_file , is_idea_file , is_decision_categories_file )
@@ -120,8 +131,19 @@ def readfile(name):
120
131
#if not parsed_file[1][0] and not parsed_file[1][1] and not parsed_file[1][2:]:
121
132
# sys.exit("File " + args.input + " is not a valid event, national_focus or ideas file.")
122
133
lines = list ()
123
- with open (args .output ,"r" ) as f :
124
- lines = f .read ().splitlines ()
134
+ try :
135
+ with open (args .output , "r" ) as f :
136
+ lines = f .read ().splitlines ()
137
+ except :
138
+ try :
139
+ with open (args .output , "r" , encoding = 'utf-8' ) as f :
140
+ lines = f .read ().splitlines ()
141
+ except :
142
+ try :
143
+ with open (args .output , "r" , encoding = 'utf-8-sig' ) as f :
144
+ lines = f .read ().splitlines ()
145
+ except :
146
+ print ("Could not read file " + args .output + "!" )
125
147
output_lines = list ()
126
148
if len (lines ) < 1 :
127
149
print ("Output file " + args .output + " is empty or doesn't exist, creating a new english localisation file." )
0 commit comments