forked from AnyMarvel/LianjiaSpider
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathdeployFig.py
executable file
·247 lines (233 loc) · 8.03 KB
/
deployFig.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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# -*- coding: utf-8 -*-
import os
import pandas as pd
img_html_tmp = '<img alt="{city}" src="http://www.yeshiwei.com/fig/{dirname}">'
wxml_tmp = '''<!--pages/fangjia/fangjia.wxml-->
<view class="container">
<ad unit-id="adunit-35015dc194c26a95"></ad>
<view>
<official-account></official-account>
</view>
<!-- 导航 -->
<view class="list">
<view class="list-item">
<text class="request-text">房价走势</text>
</view>
{buttons}
</view>
<view>
{citydata}
<div class="nav">
<button class="next" size="mini" type="default" bindtap="goHome">回到首页</button>
</div>
</view>
</view>
'''
img_wxml_tmp = ''' <view wx:if="{{{{city === '{city}' && district === '{district}'}}}}">
<image class="image3" src="cloud://shiwei-mwhas.7368-shiwei-mwhas-1301568844/{city}-aa-{filename}" mode="scaleToFill"></image>
</view>
'''
button_line_tmp = '''
<view class="list-item">
{buttons}
</view>
'''
button_wxml_tmp = '''
<div class="nav">
<button class="next" size="mini" type="default" data-city = '{city}' bindtap="gotoCity">{citydes}</button>
</div>
'''
district_button_wxml_tmp = '''
<div class="nav">
<button class="next" size="mini" type="default" data-city = '{city}' data-district='{district}' bindtap="gotoDistrict">{district}</button>
</div>
'''
wxml_city_tmp = '''
<!-- {citydes} -->
<view class="guide" wx:if="{{{{city === '{city}'}}}}">
<text class="headline">{citydes}</text>
{img}
<view class="list">
{city_button}
</view>
</view>
'''
rootDir = 'fig/'
dirNames = os.listdir(rootDir)
citydesMap = {'allcity':'全部城市','default':'草稿'
}
head_template = ''' <div class="table-head">
{content}
</div>'''
row_template = ''' <div class="table-row">
{content}
</div>'''
element_temp = ''' <div class="serial">{value}</div>
'''
image_template = ''' <div class="col-md-4">
<a href="{url}" class="img-pop-up">
<div class="single-gallery-image" style="background: url({url});"></div>
</a>
</div>'''
dirName = 'fig/'
def getCityHTML(city):
df = pd.DataFrame()
if city not in ['房价收入分析']:
if city == 'allcity':
df = pd.read_excel('rank/城市排名.xlsx')
else:
df = pd.read_excel('rank/%s区域排名.xlsx'%city)
if "Unnamed: 0" in df.columns:
df = df.drop(["Unnamed: 0" ], axis = 1)
table_html = ""
content = element_temp.format(value='#')
for col in df.columns:
content += element_temp.format(value=col)
table_html += head_template.format(content=content)
for index, row in df.iterrows():
content = element_temp.format(value=str(index))
for col in df.columns:
content += element_temp.format(value = str(row[col]))
table_html += row_template.format(content = content)
else:
table_html = ""
image_html = ""
districts = os.listdir(os.path.join(dirName, city))
districts_sorted = []
if '城区' in df.columns or '城市' in df.columns:
for d in districts:
if city in d:
districts_sorted.append(d)
s = pd.Series()
if '城区' in df.columns:
s = df['城区']
else:
s = df['城市']
for district in s:
for d in districts:
if district in d and district not in districts_sorted:
districts_sorted.append(d)
for d in districts:
if not d in districts_sorted:
districts_sorted.append(d)
districts = districts_sorted
for district in districts:
if not district.endswith('.png'):
continue
url = 'http://www.yeshiwei.com/fig/{city}/{district}'.format(city = city, district = district)
image_html += image_template.format(url=url)
html = open('fangjia_template.html').read().format(city = city, table = table_html, image = image_html)
fp = open('fangjia/%s.html'%city,'w')
fp.write(html)
fp.close()
def makeWeixin(city):
df = pd.DataFrame()
if city not in ['房价收入分析']:
if city == 'allcity':
df = pd.read_excel('rank/城市排名.xlsx')
else:
df = pd.read_excel('rank/%s区域排名.xlsx'%city)
dirName = os.path.join(rootDir, city)
files = os.listdir(dirName)
files.sort(reverse=False)
img_wxml = ""
button_wxml = ""
for f in files:
if city in f:
files.remove(f)
files = [f, *files]
break
button_buf = ''
current_line_char_num = 0
districts_sorted = []
if '城区' in df.columns or '城市' in df.columns:
for d in files:
if city in d:
districts_sorted.append(d)
s = pd.Series()
if '城区' in df.columns:
s = df['城区']
else:
s = df['城市']
for district in s:
for d in files:
if district in d and district not in districts_sorted:
districts_sorted.append(d)
for d in files:
if not d in districts_sorted:
districts_sorted.append(d)
files = districts_sorted
for f in files:
if not f.endswith('.png'):
continue
district = f.split(".")[0]
img_wxml_ele = img_wxml_tmp.format(city = city, district = district, filename = f)
img_wxml += img_wxml_ele
button_wxml_ele = district_button_wxml_tmp.format(city = city, district = district)
if current_line_char_num + len(district) > 10:
button_wxml += button_line_tmp.format(buttons = button_buf)
button_buf = ""
current_line_char_num = 0
current_line_char_num += len(district)
button_buf += button_wxml_ele
fileName = os.path.join(rootDir, city, f)
targetFileName = city + '-aa-' + f
cmd = 'cp %s wximg/%s' % (fileName, targetFileName)
#print(cmd)
os.system(cmd)
if current_line_char_num > 0:
button_wxml += button_line_tmp.format(buttons = button_buf)
if city == 'allcity':
return ""
citydes = citydesMap.get(city, "")
if citydes == "":
citydes = city
wxml = wxml_city_tmp.format(citydes = citydes, city = city, img = img_wxml, city_button = button_wxml)
return wxml
wxml_city = ''
buttons = ''
button_buf = ''
current_line_char_num = 0
df = pd.read_excel('rank/城市排名.xlsx')
s = df['城市']
city_sorted = []
for city in s:
for d in dirNames:
if city in d and city not in city_sorted:
city_sorted.append(d)
for d in dirNames:
if not d in city_sorted:
city_sorted.append(d)
dirNames = city_sorted
for city in dirNames:
#try:
if city == 'default' or city == 'allcity':
continue
if not os.path.isdir(os.path.join(rootDir, city)):
continue
getCityHTML(city)
if city != 'allcity':
wxml_city += makeWeixin(city)
citydes = citydesMap.get(city, "")
if citydes == "":
citydes = city
if current_line_char_num + len(citydes) > 10:
buttons += button_line_tmp.format(buttons = button_buf)
button_buf = ''
current_line_char_num = 0
current_line_char_num += len(citydes)
button_buf += button_wxml_tmp.format(city=city,citydes=citydes)
#except Exception:
# print(Exception)
# pass
if current_line_char_num > 0:
buttons += button_line_tmp.format(buttons = button_buf)
wxml = wxml_tmp.format(buttons = buttons, citydata = wxml_city)
fp = open('/mnt/c/yeshiwei/miniprogram-1/miniprogram/pages/fangjia/fangjia.wxml','w')
fp.write(wxml)
fp.close()
def exec(cmd):
os.system(cmd)
getCityHTML('allcity')
exec('rsync -avzP fig/ root@vps.yeshiwei.com:/var/www/html/fig')
exec('rsync -avzP fangjia/ root@vps.yeshiwei.com:/var/www/html/fangjia')