|
@@ -2,9 +2,6 @@
|
2
|
2
|
# -*- coding:utf-8 -*-
|
3
|
3
|
from util import pgsql_util
|
4
|
4
|
import json
|
5
|
|
-import sys
|
6
|
|
-reload(sys)
|
7
|
|
-sys.setdefaultencoding('utf8')
|
8
|
5
|
|
9
|
6
|
query_articles_sql = '''
|
10
|
7
|
select a.aid,a.title,a.cities,a.cid,a.other_info,"array_agg"(t.tag_value),days,a.recom,a."rank",read_count
|
|
@@ -18,39 +15,40 @@ limit 100 OFFSET 0
|
18
|
15
|
|
19
|
16
|
query_sell_main_sql = '''
|
20
|
17
|
select count(*)
|
21
|
|
-FROM order
|
22
|
|
-where aid in (select aid from articles where stock_aid = %s)
|
|
18
|
+FROM zhima.order
|
|
19
|
+where aid in (select aid from articles where stock_aid = '%s')
|
23
|
20
|
and pay_status = 7
|
24
|
21
|
'''
|
25
|
22
|
|
26
|
23
|
query_stock_main_sql = '''
|
27
|
24
|
select sum(maxt::int)
|
28
|
25
|
FROM zm_alipay
|
29
|
|
-where aid in (select aid from articles where stock_aid = %s)
|
|
26
|
+where aid in (select aid from articles where stock_aid = '%s')
|
30
|
27
|
and status in (1,2)
|
31
|
28
|
'''
|
32
|
29
|
|
33
|
30
|
query_sell_main_sql_2 = '''
|
34
|
31
|
select count(*)
|
35
|
|
-FROM order
|
36
|
|
-where aid = %s
|
|
32
|
+FROM zhima.order
|
|
33
|
+where aid = '%s'
|
37
|
34
|
and pay_status = 7
|
38
|
35
|
'''
|
39
|
36
|
|
40
|
37
|
query_stock_main_sql_2 = '''
|
41
|
38
|
select sum(maxt::int)
|
42
|
39
|
FROM zm_alipay
|
43
|
|
-where aid = %s
|
|
40
|
+where aid = '%s'
|
44
|
41
|
and status in (1,2)
|
45
|
42
|
'''
|
46
|
43
|
|
|
44
|
+
|
47
|
45
|
def get_articles():
|
48
|
46
|
rows = pgsql_util.get_rows(query_articles_sql)
|
49
|
47
|
|
50
|
48
|
attr_list = []
|
51
|
49
|
for row in rows:
|
52
|
50
|
attr = {}
|
53
|
|
- attr['city'] = row['cities'].encode('utf-8')
|
|
51
|
+ attr['city'] = row['cities']
|
54
|
52
|
attr['cid'] = row['cid']
|
55
|
53
|
|
56
|
54
|
other_info = json.loads(row['other_info'])
|
|
@@ -64,13 +62,89 @@ def get_articles():
|
64
|
62
|
attr['rank'] = row['rank']
|
65
|
63
|
attr['read_count'] = row['read_count']
|
66
|
64
|
|
67
|
|
-
|
68
|
|
-
|
|
65
|
+ if row['cities'] == '株洲':
|
|
66
|
+ sell_count = pgsql_util.get_rows(query_sell_main_sql % (row['aid']))[0]['count']
|
|
67
|
+ stock_count = pgsql_util.get_rows(query_stock_main_sql % (row['aid']))[0]['sum']
|
|
68
|
+ else:
|
|
69
|
+ sell_count = pgsql_util.get_rows(query_sell_main_sql_2 % (row['aid']))[0]['count']
|
|
70
|
+ stock_count = pgsql_util.get_rows(query_stock_main_sql_2 % (row['aid']))[0]['sum']
|
|
71
|
+ attr['sell_count'] = sell_count
|
|
72
|
+ attr['stock_count'] = stock_count
|
69
|
73
|
|
70
|
74
|
attr_list.append(attr)
|
71
|
75
|
|
72
|
|
- print attr
|
|
76
|
+ print(attr)
|
|
77
|
+ return attr_list
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+def to_a1(attr_list):
|
|
81
|
+ for attr in attr_list:
|
|
82
|
+ if attr['recruit'] is None:
|
|
83
|
+ attr['recruit'] = 0
|
|
84
|
+
|
|
85
|
+ if attr['stock_count'] is None:
|
|
86
|
+ attr['stock_count'] = 0
|
|
87
|
+
|
|
88
|
+ new_attr_list = []
|
|
89
|
+ for attr in attr_list:
|
|
90
|
+ new_attr = []
|
|
91
|
+ city = attr['city']
|
|
92
|
+ cid = attr['cid']
|
|
93
|
+ dtype = attr['dtype']
|
|
94
|
+ recruit = attr['recruit']
|
|
95
|
+ country = attr['country']
|
|
96
|
+ price = attr['price']
|
|
97
|
+ days = attr['days']
|
|
98
|
+ recom = attr['recom']
|
|
99
|
+ rank = attr['rank']
|
|
100
|
+ read_count = attr['read_count']
|
|
101
|
+ sell_count = attr['sell_count']
|
|
102
|
+ stock_count = attr['stock_count']
|
|
103
|
+
|
|
104
|
+ new_attr.extend(to_list_attr(city, open_city_list))
|
|
105
|
+ new_attr.extend(to_list_attr(cid, open_cid_list))
|
|
106
|
+ new_attr.extend(to_list_attr(dtype, open_dtype_list))
|
|
107
|
+ new_attr.extend(to_list_attr(recruit, open_recruit_list))
|
|
108
|
+ new_attr.extend(to_list_attr(country, open_country_list))
|
|
109
|
+ new_attr.append(float(price))
|
|
110
|
+ new_attr.append(float(days))
|
|
111
|
+ new_attr.extend(to_list_attr(recom, open_recom_list))
|
|
112
|
+ new_attr.append(rank)
|
|
113
|
+ new_attr.append(read_count)
|
|
114
|
+ new_attr.append(stock_count)
|
|
115
|
+ new_attr.append(sell_count)
|
|
116
|
+
|
|
117
|
+ print(new_attr)
|
|
118
|
+
|
|
119
|
+ return new_attr_list
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+open_city_list = ['北京', '长沙', '成都', '重庆', '佛山', '福州', '广州', '杭州', '合肥', '济南',
|
|
123
|
+ '南京', '宁波', '青岛', '上海', '深圳', '苏州', '天津', '武汉', '厦门', '西安',
|
|
124
|
+ '郑州', '株洲']
|
|
125
|
+open_cid_list = [23,24,25,26,27,28,29]
|
|
126
|
+open_dtype_list = [0,1,2,3,4,5]
|
|
127
|
+open_recruit_list = [0,1,2,3,4,5,6,7,8,9]
|
|
128
|
+open_country_list = ['港澳台', '国内', '新加坡', '英国', '日本', '泰国', '美国']
|
|
129
|
+open_recom_list = ['yes', 'no']
|
|
130
|
+
|
|
131
|
+def city_attr(city):
|
|
132
|
+ return to_list_attr(city, open_city_list)
|
|
133
|
+
|
|
134
|
+def cid_attr(cid):
|
|
135
|
+ return to_list_attr(cid, open_cid_list)
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+def to_list_attr(item, a_list):
|
|
139
|
+ c_list = [0 for i in a_list]
|
|
140
|
+ try:
|
|
141
|
+ idx = a_list.index(item)
|
|
142
|
+ except:
|
|
143
|
+ idx = 0
|
|
144
|
+ c_list[idx] = 1
|
|
145
|
+ return c_list
|
73
|
146
|
|
74
|
147
|
|
75
|
148
|
if __name__ == '__main__':
|
76
|
|
- get_articles()
|
|
149
|
+ attr_list = get_articles()
|
|
150
|
+ new_attr_list = to_a1(attr_list)
|