-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
182 lines (166 loc) · 6.8 KB
/
main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/usr/bin/python
# -*- coding: utf-8 -*-
__author__ = '500004'
import excelutil
import mongoDb
db_pic = mongoDb.getMongoConn()
db_house = mongoDb.getMongoConn(database='houses')
num = excelutil.getExcelTableNRows()
# pic_path = u'F:\gongxiang\lptp\济南楼盘\houses_type_pic\\'
pic_path = u'F:\gongxiang\lptp\杭州楼盘\houses_type_pic\\'
# 处理float
def switchToStr(row, line):
title = excelutil.getExcelCell(row, line)
if isinstance(title, float):
title = str(int(title))
if isinstance(title, unicode):
title = title.split("(")[0]
return title
# 保存图片
def saveImp(imagePath, name):
try:
return mongoDb.putImg(imagePath, db_pic, name)
except IOError as e:
e.message
print(u"图片不存在")
return None
# 获取楼盘
def findHouses(condition):
oldHouse = db_house.houses.find_one(condition)
print oldHouse
if oldHouse is None:
# excelutil.write(houseName)
print condition["name"]
print(u"没有楼盘数据")
return oldHouse
# 获取楼盘类型
def getHouseType(oldHouse, condition):
try:
oldList = oldHouse["new_houses_type"]
except KeyError:
print 'new_houses_type not found,create!'
db_house.houses.update(condition, {"$set": {"new_houses_type": []}})
house = findHouses(condition)
oldList = house["new_houses_type"]
return oldList
# 新建记录
def saveNewHouseType(house_room, house_hall, house_toilet, house_area, house_type_title, id):
# 循环完没有找到
value = {"house_room": house_room, "house_hall": house_hall, "house_toilet": house_toilet,
"house_area": house_area, "house_type_title": house_type_title, "mongo_key": id}
db_house.houses.update(condition, {"$push": {"new_houses_type": value}})
for x in range(num):
row = x + 1
print row
if row == num:
print u'完成表中数据'
break
name = excelutil.getExcelCell(row, 8).split("\\")[1].strip()
print u"图片名:" + name
imagePath = pic_path + name
houseName = excelutil.getExcelCell(row, 1)
city = excelutil.getExcelCell(row, 2)
house_type_title = switchToStr(row, 3)
# 室
house_room = switchToStr(row, 4)
# 厅
house_hall = switchToStr(row, 5)
# 卫
house_toilet = switchToStr(row, 6)
# 面积
house_area = switchToStr(row, 7)
condition = {"name": houseName, "city": city}
oldHouse = findHouses(condition)
if oldHouse is None:
continue
oldList = getHouseType(oldHouse, condition)
# 保存图片
id = saveImp(imagePath, name)
saveNewHouseType(house_room, house_hall, house_toilet, house_area, house_type_title, str(id))
# for x in range(num):
# row = x + 1
# print row
# if row == num:
# print u'完成表中数据'
# break
# col = 9
# name = excelutil.getExcelCell(row, 8).split("\\")[1]
# print u"图片名:" + name
# # imagePath = u'F:\gongxiang\lptp\济南楼盘\houses_type_pic\\' + name
# imagePath = u'F:\gongxiang\lptp\杭州楼盘\houses_type_pic\\' + name
# # 更新原来数据
# houseName = excelutil.getExcelCell(row, 1)
# city = excelutil.getExcelCell(row, 2)
# house_type_title = excelutil.getExcelCell(row, 3)
# if isinstance(house_type_title, float):
# house_type_title = str(int(house_type_title))
# # 室
# house_room = excelutil.getExcelCell(row, 4)
# # 厅
# house_hall = excelutil.getExcelCell(row, 5)
# # 卫
# house_toilet = excelutil.getExcelCell(row, 6)
# # 面积
# house_area = excelutil.getExcelCell(row, 7)
# if isinstance(house_area, unicode):
# house_area = house_area.split("(")[0]
# condition = {"name": houseName, "city": city}
# oldHouse = findHouses(condition)
# # 保存图片
# id = saveImp(imagePath, name)
# if id is None or oldHouse is None:
# continue
# oldList = getHouseType(oldHouse)
# if len(oldList) > 0:
# for index, value in enumerate(oldList):
# try:
# houseArea = value["house_area"]
# houseTypeTitle = value["house_type_title"]
# except KeyError:
# print u"键值不存在 不存在,新建"
# saveNewHouseType(house_room, house_hall, house_toilet, house_area, house_type_title, id)
# key = 'houses_type.%d.' % index
# set_condi = {
# "$set": {key + "mongo_key": id, key + "house_room": house_room,
# key + "house_hall": house_hall,
# key + "house_toilet": house_toilet}}
# if house_area:
# try:
# if houseArea:
# if isinstance(houseArea, unicode):
# houseArea = houseArea.split(u"㎡")[0]
# if int(houseArea) == int(house_area):
# if value["house_type_title"]:
# if isinstance(houseTypeTitle, unicode):
# title = houseTypeTitle
# else:
# title = str(houseTypeTitle)
# if house_type_title in title:
# print u'匹配房型成功'
# db_house.houses.update(condition, set_condi)
# continue
# except KeyError:
# print u"house_area 不存在,新建"
# except ValueError:
# print u"house_area 包含数字跳过,第" + str(row)
# continue
# elif house_type_title:
# try:
# # 没有面积 按户型匹配
# if houseTypeTitle:
# if isinstance(houseTypeTitle, unicode):
# title = value["house_type_title"]
# else:
# title = str(houseTypeTitle)
# if house_type_title in title:
# db_house.houses.update(condition, set_condi)
# continue
# print u"house_area 不存在,新建"
# except KeyError:
# print u"house_area 不存在,新建"
# print u'没有匹配房型'
# # 循环完没有找到
# saveNewHouseType(house_room, house_hall, house_toilet, house_area, house_type_title, id)
# else:
# # 一个都不存在
# saveNewHouseType(house_room, house_hall, house_toilet, house_area, house_type_title, id)