-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfirst_600_restaurants.py
executable file
·65 lines (45 loc) · 1.75 KB
/
first_600_restaurants.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
#!/usr/bin/env python
'''
Author : Tasdik Rahman
To get the name of the first 700 restaurants in the file "burrp_bangalore.txt" and then move the files in
"images" directory to another directory called "first_600_restaurants"
'''
import os
from distutils.dir_util import copy_tree
def main():
burrp_bangalore = r'/home/tasdik/Dropbox/projects/big_data_project/test/burrp_bangalore.txt'
full_hotel_list = []
with open(burrp_bangalore, 'r') as file :
for link in file :
temp_link = link.replace('http://www.burrp.com/bangalore/','')
## splitting the temp_link for removing the restaurant id after the '/'
var = temp_link.rpartition('/')[0]
# print var
## the above print statement prints out all the hotel names in the burrp_bangalore.txt
## now to store it the list
full_hotel_list.append(var)
final_hotel_list = full_hotel_list[:700]
## now to move the files
print 'moving the files'
dest_dir = r'/home/tasdik/Dropbox/projects/big_data_project/test/first_600_restaurants'
## creating the directory if its not there
if not os.path.exists(dest_dir) :
os.makedirs(dest_dir)
img_dir = r'/home/tasdik/Dropbox/projects/big_data_project/test/images'
# print 'changing directory to : ' + dest_dir
# os.chdir(dest_dir)
for hotel in final_hotel_list :
print '#'*50
print 'moving file \"' + hotel + '\"'
src_path = img_dir + '/' + hotel
final_dest_dir = dest_dir + '/' + hotel
########################################3
### os module which is not working
# copy_command = 'cp ' + src_path + ' ' + dest_dir + '/'
# os.system('cp '+ src_path + ' ' + dest_dir)
########################################3
copy_tree(src_path, final_dest_dir)
print '\n'
print 'files moved!!!'
if __name__ == '__main__' :
main()