-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathall_menu_light.py
executable file
·73 lines (51 loc) · 1.92 KB
/
all_menu_light.py
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
73
#!/usr/bin/env python
'''
Author : Tasdik Rahman
To read the .txt files inside the hotel folders and then append all those files into a single file
in accordance to the name of the file
'''
import os
def main() :
## reading the first file named "dark_ocr_menu_output"
dark_file = '/home/tasdik/Dropbox/projects/big_data_project/test/light_ocr_menu_output'
dest_file = '/home/tasdik/Dropbox/projects/big_data_project/test/all_menu_light'
if not os.path.exists(dest_file) :
os.makedirs(dest_file)
hotels_list = os.listdir('/home/tasdik/Dropbox/projects/big_data_project/test/light_ocr_menu_output')
### reading the dark first file
for hotel in hotels_list :
hotel_dir = dark_file + '/' + hotel
# print hotel_dir
print '#'*70
print 'changed the directory to ::: ' + hotel_dir
images_list = os.listdir(hotel_dir)
parent_file = images_list[0]
parent_file_path = hotel_dir + '/' + parent_file
print "parent_file_path : " + parent_file_path
print '\n'
## skipping the first item in the images list
iterimages = iter(images_list)
next(iterimages)
## open the parent file with append mode
open_parent_file = open(parent_file_path, 'r')
parent_file_content = open_parent_file.read()
open_parent_file.close()
final_dest_file = dest_file + "/" + hotel + ".txt"
print 'final folder : ' + final_dest_file
# command = 'touch '+final_dest_file
# os.system(command)
os.mknod(final_dest_file)
f = open(final_dest_file, 'w')
f.write(parent_file_content)
f.close()
print 'the other images are : '
for img in iterimages :
img_dir = hotel_dir + '/' + img
temp_file = open(img_dir, 'r')
content = temp_file.read()
with open(final_dest_file, 'a') as f :
f.write(content)
### opening the first file in the list and then appending the list of other files in the list of images
# with open(parent_file_path + '.txt', 'a') as f :
if __name__ == '__main__' :
main()