yufeng0528 4 years ago
parent
commit
2d0091d9f1
1 changed files with 76 additions and 0 deletions
  1. 76 0
      bbztx/get_data.py

+ 76 - 0
bbztx/get_data.py

@@ -0,0 +1,76 @@
1
+#!/usr/bin/python
2
+# -*- coding:utf-8 -*-
3
+from util import pgsql_util
4
+import json
5
+import sys
6
+reload(sys)
7
+sys.setdefaultencoding('utf8')
8
+
9
+query_articles_sql = '''
10
+select a.aid,a.title,a.cities,a.cid,a.other_info,"array_agg"(t.tag_value),days,a.recom,a."rank",read_count
11
+from articles a
12
+LEFT JOIN article_tags t on a.aid = t.aid
13
+where a.crt_time > '2018-01-01' and a.atype = '0'
14
+and a.stock_aid is NULL
15
+GROUP BY a.aid
16
+limit 100 OFFSET 0
17
+'''
18
+
19
+query_sell_main_sql = '''
20
+select count(*)
21
+FROM order 
22
+where aid in (select aid from articles where stock_aid = %s)
23
+and pay_status = 7
24
+'''
25
+
26
+query_stock_main_sql = '''
27
+select sum(maxt::int)
28
+FROM zm_alipay 
29
+where aid in (select aid from articles where stock_aid = %s)
30
+and status in (1,2)
31
+'''
32
+
33
+query_sell_main_sql_2 = '''
34
+select count(*)
35
+FROM order 
36
+where aid = %s
37
+and pay_status = 7
38
+'''
39
+
40
+query_stock_main_sql_2 = '''
41
+select sum(maxt::int)
42
+FROM zm_alipay 
43
+where aid = %s
44
+and status in (1,2)
45
+'''
46
+
47
+def get_articles():
48
+    rows = pgsql_util.get_rows(query_articles_sql)
49
+
50
+    attr_list = []
51
+    for row in rows:
52
+        attr = {}
53
+        attr['city'] = row['cities'].encode('utf-8')
54
+        attr['cid'] = row['cid']
55
+
56
+        other_info = json.loads(row['other_info'])
57
+        attr['dtype'] = other_info.get('dtype')
58
+        attr['recruit'] = other_info.get('recruit')
59
+        attr['country'] = other_info.get('country')
60
+        attr['price'] = other_info.get('price').replace('元', '')
61
+
62
+        attr['days'] = row['days']
63
+        attr['recom'] = row['recom']
64
+        attr['rank'] = row['rank']
65
+        attr['read_count'] = row['read_count']
66
+
67
+
68
+
69
+
70
+        attr_list.append(attr)
71
+
72
+        print attr
73
+
74
+
75
+if __name__ == '__main__':
76
+    get_articles()