Commit 206a775037fb2666f30f3ac8ce338d79059e3f1c

Authored by steve ago
1 parent a6cd4662a1
Exists in master

adding top menu bar

adding facebook trends page

Showing 7 changed files with 348 additions and 91 deletions Side-by-side Diff

project/project/controller/printer.py View file @ 206a775
... ... @@ -14,6 +14,13 @@
14 14 ## Coded by Tony (2015.01.)
15 15 #################################################################
16 16  
  17 +def get_date(hour):
  18 + """ Returns timestamp of days ago """
  19 + now = dt.now()
  20 + yesterday = dt.fromtimestamp(time.time() - 60*60*hour)
  21 + yd = yesterday.strftime("%Y-%m-%d %H")
  22 + y = yd
  23 + return y
17 24  
18 25 @app.route('/')
19 26 def start():
... ... @@ -21,6 +28,27 @@
21 28 result = utils.get_keywordlist(c_date)
22 29 s_date = c_date
23 30 return render_template('trends.html',data=result,date=c_date,s_date=s_date)
  31 +
  32 +@app.route('/fb/<v_type>')
  33 +def fb(v_type):
  34 + w_type = request.args['w_type']
  35 + if w_type == "today":
  36 + result = utils.get_facebookData()
  37 + else:
  38 + print "ho"
  39 + now = get_date(0)
  40 + before = get_date(1)
  41 + result = utils.get_facebookGrowData(now, before)
  42 + data = []
  43 + if v_type == "share":
  44 + data = result['share']
  45 + elif v_type == "like":
  46 + data = result['like']
  47 + elif v_type == "comment":
  48 + data = result['comment']
  49 +
  50 +
  51 + return render_template('fb.html',v_type=v_type,w_type=w_type,data=data)
24 52  
25 53 @app.route('/trends')
26 54 def before_now():
project/project/controller/trends_db.py View file @ 206a775
... ... @@ -44,4 +44,52 @@
44 44 result['twitter'].append(row['keyword'])
45 45  
46 46 return result
  47 +
  48 + def get_fbData(self):
  49 + result = { 'share':[], 'like':[], 'comment':[], 'share_grow':[], 'like_grow':[], 'comment_grow':[] }
  50 + main_query = "select content_id, thumbnail,link, message, page_name, title, max(share_count), max(like_count), max(comment_count), max(date), cdate from fb_contents where date between DATE_SUB(now(), INTERVAL 1 DAY) and now() group by content_id"
  51 + top_share_query = main_query + " order by max(share_count) desc limit 10;"
  52 + top_like_query = main_query + " order by max(like_count) desc limit 10;"
  53 + top_comment_query = main_query + " order by max(comment_count) desc limit 10;"
  54 +
  55 + self.cursor.execute(top_share_query)
  56 + rows = self.cursor.fetchall()
  57 + result['share'] = rows
  58 +
  59 + self.cursor.execute(top_like_query)
  60 + rows = self.cursor.fetchall()
  61 + result['like'] = rows
  62 +
  63 + self.cursor.execute(top_comment_query)
  64 + rows = self.cursor.fetchall()
  65 + result['comment'] = rows
  66 +
  67 +
  68 + return result
  69 +
  70 + def get_fbGrowData(self, now, before):
  71 + result = { 'share':[], 'like':[], 'comment':[], 'share_grow':[], 'like_grow':[], 'comment_grow':[] }
  72 +
  73 + columns = "title, link, thumbnail, message, page_name, max(share_count)-min(share_count), max(like_count)-min(like_count), max(comment_count)-min(comment_count), max(share_count), max(like_count), max(comment_count), cdate"
  74 + between = "'%s' and '%s'"%(before, now)
  75 + main_query = "select " + columns + " from fb_contents where date_format(date, '%Y-%m-%d %H') between " + between + " group by content_id"
  76 + top_share_query = main_query + " having max(share_count)-min(share_count) > 5 order by max(share_count)-min(share_count) desc limit 10"
  77 + top_like_query = main_query + " having max(like_count)-min(like_count) > 10 order by max(like_count)-min(like_count) desc limit 10"
  78 + top_comment_query = main_query + " having max(comment_count)-min(comment_count) > 10 order by max(comment_count)- min(comment_count) desc limit 10"
  79 +
  80 +
  81 + self.cursor.execute(top_share_query)
  82 + rows = self.cursor.fetchall()
  83 + result['share'] = rows
  84 +
  85 + self.cursor.execute(top_like_query)
  86 + rows = self.cursor.fetchall()
  87 + result['like'] = rows
  88 +
  89 + self.cursor.execute(top_comment_query)
  90 + rows = self.cursor.fetchall()
  91 + result['comment'] = rows
  92 +
  93 +
  94 + return result
project/project/controller/utils.py View file @ 206a775
... ... @@ -81,6 +81,14 @@
81 81 db = TendsDB()
82 82 return db.get_keyword(date)
83 83  
  84 +def get_facebookData():
  85 + db = TendsDB()
  86 + return db.get_fbData()
  87 +
  88 +def get_facebookGrowData(now, before):
  89 + db = TendsDB()
  90 + return db.get_fbGrowData(now, before)
  91 +
84 92 def loop_process():
85 93 #do some stuff
86 94 if not os.path.isfile('/tmp/trends_piki.pid'):
project/project/static/css/piki-data.css View file @ 206a775
... ... @@ -8,4 +8,51 @@
8 8 margin : 0;
9 9 color : #4d63bc;
10 10 }
  11 +.week_type{
  12 + margin: 25px;
  13 +}
  14 +.unfluid_chart{
  15 + width: 100%;
  16 + float: left;
  17 +}
  18 +.weekly_list .thumbnail img{
  19 + height: 144px;
  20 +}
  21 +.weekly_list .title{
  22 + font-size: 22px;
  23 + color: #00A6DF;
  24 +}
  25 +.weekly_list .description{
  26 + font-size: 11px;
  27 +}
  28 +.weekly_list .headline{
  29 + margin-top: 20px;
  30 +}
  31 +.weekly_list p{
  32 + font-size: 11px;
  33 +}
  34 +.weekly_list .total_view{
  35 + text-align: center;
  36 + margin-top: 20px;
  37 +}
  38 +.weekly_list .total_like{
  39 + text-align: center;
  40 + margin-top: 20px;
  41 +}
  42 +.weekly_list .total_share{
  43 + text-align: center;
  44 + margin-top: 20px;
  45 +}
  46 +.weekly_list .total_bookmark{
  47 + text-align: center;
  48 + margin-top: 20px;
  49 +}
  50 +.weekly_list .total_comment{
  51 + text-align: center;
  52 + margin-top: 20px;
  53 +}
  54 +.weekly_list .udate{
  55 + text-align: center;
  56 + margin-top: 20px;
  57 +}
project/project/templates/fb.html View file @ 206a775
  1 +{% extends "header.html" %}
  2 +{% block datadetails %}
  3 +<link rel="stylesheet" type="text/css" href="//cdn.datatables.net/1.10.4/css/jquery.dataTables.min.css">
  4 +
  5 +<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
  6 +<script type="text/javascript" language="javascript" src="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>
  7 +<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/trends.css') }}">
  8 +<script>
  9 +$(document).ready(function(){
  10 + $('#myTable').DataTable({
  11 + "iDisplayLength": 100
  12 + });
  13 +});
  14 +</script>
  15 +<div class="container">
  16 + <div class="week_type">
  17 + <a class="btn btn-default" href="{{ url_for('fb',v_type=v_type,w_type='today') }}">금일 TOP10</a>
  18 + <a class="btn btn-primary" href="{{ url_for('fb',v_type=v_type,w_type='realtime') }}">실시간 급상승</a>
  19 + </div>
  20 + <ul class="nav nav-tabs nav-justified">
  21 + <li role="presentation" {% if v_type == 'share' %}class="active"{% endif %}>
  22 + <a href="{{ url_for('fb',v_type='share', w_type=w_type) }}">Share TOP10</a>
  23 + </li>
  24 + <li role="presentation" {% if v_type == 'like' %}class="active"{% endif %}><a href="{{ url_for('fb',v_type='like', w_type=w_type) }}">Like TOP10</a></li>
  25 + <li role="presentation" {% if v_type == 'comment' %}class="active"{% endif %}><a href="{{ url_for('fb',v_type='comment', w_type=w_type) }}">Comment TOP10</a></li>
  26 + </ul>
  27 + <table class="table">
  28 + <thead>
  29 + </thead>
  30 + <tbody>
  31 + {% for di in data %}
  32 + <tr class="weekly_list">
  33 + <td class='thumbnail' style="height: 170px;width: 300px">
  34 + <img src="{{ di['thumbnail'] }} " id='thumbnail' style="height: 100%">
  35 + </td>
  36 + <td>
  37 + <div class='headline'>
  38 + <div class='title'><a target="_blank" href="{{ di['link'] }}">{% if di['title'] != 'None' %}{% print di['title'].decode('utf-8') %}{% else %}제목없음{% endif %}</a></div>
  39 + <div class='description'><br><p><b>[{{ di['page_name'].decode('utf-8') }}]</b>&nbsp;{% if di['message'] != 'None' %}{% print di['message'].decode('utf-8') %}{% endif %}<br>생성 시간 : {% print di['cdate'] %}</p></div>
  40 + </div>
  41 + </td>
  42 + <td>
  43 + <div class='total_share'>
  44 + {% print di['max(share_count)'] %} <p>Total share</p>
  45 + {% if v_type == 'share' and w_type == 'realtime' %}
  46 + <p style="margin:15px;width: 0;height: 11px;border-style: solid;border-width: 0 5px 8px 5px;border-color: transparent transparent #ff0022 transparent;">&nbsp;&nbsp;{{ di['max(share_count)-min(share_count)'] }}</p>
  47 + {% endif %}
  48 + </div>
  49 + </td>
  50 + <td>
  51 + <div class='total_like'>
  52 + {% print di['max(like_count)'] %} <p>Total like</p>
  53 + {% if v_type == 'like' and w_type == 'realtime' %}
  54 + <p style="margin:5px;width: 0;height: 11px;border-style: solid;border-width: 0 5px 8px 5px;border-color: transparent transparent #ff0022 transparent;">&nbsp;&nbsp;{{ di['max(like_count)-min(like_count)'] }}</p>
  55 + {% endif %}
  56 +
  57 + </div>
  58 + </td>
  59 + <td>
  60 + <div class='total_comment'>
  61 + {% print di['max(comment_count)'] %} <p>Total comment</p>
  62 + {% if v_type == 'comment' and w_type == 'realtime' %}
  63 + <p style="margin:18px;width: 0;height: 11px;border-style: solid;border-width: 0 5px 8px 5px;border-color: transparent transparent #ff0022 transparent;">&nbsp;&nbsp;{{ di['max(comment_count)-min(comment_count)'] }}</p>
  64 + {% endif %}
  65 +
  66 + </div>
  67 + </td>
  68 +
  69 + </tr>
  70 + {% endfor %}
  71 + </tbody>
  72 + </table>
  73 +</div>
  74 +{% endblock %}
project/project/templates/header.html View file @ 206a775
  1 +<!DOCTYPE html>
  2 +<html lang="en">
  3 +<head>
  4 + <meta charset="UTF-8">
  5 +
  6 + <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/bootstrap/bootstrap.min.css') }}">
  7 + <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/bootstrap/doc.min.css') }}">
  8 + <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/font-awesome.css') }}">
  9 + <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/pikinav.css') }}">
  10 + <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/piki-data.css') }}">
  11 +
  12 +
  13 + <title>PIKI trends</title>
  14 +</head>
  15 +<body>
  16 + <header class="navbar navbar-static-top bs-docs-nav navbar-inverse" id="top" role="banner">
  17 + <div class="container">
  18 + <div class="navbar-header">
  19 + <button class="navbar-toggle collapsed" type="button" data-toggle="collapse" data-target=".bs-navbar-collapse">
  20 + <span class="sr-only">Toggle navigation</span>
  21 + <span class="icon-bar"></span>
  22 + <span class="icon-bar"></span>
  23 + <span class="icon-bar"></span>
  24 + </button>
  25 + <a href="../" class="navbar-brand">Pikicast</a>
  26 + </div>
  27 + <nav class="collapse navbar-collapse bs-navbar-collapse">
  28 + <ul class="nav navbar-nav">
  29 + <li id=il_main>
  30 + <a href="../">Main</a>
  31 + </li>
  32 + <li id=il_w_contents>
  33 + <a href="{{ url_for('fb',v_type='share', w_type='today') }}">facebook</a>
  34 + </li>
  35 + </ul>
  36 + <ul class="nav navbar-nav navbar-right">
  37 + <li><a href="http://expo.getbootstrap.com" onclick="ga('send', 'event', 'Navbar', 'Community links', 'Expo');">Login</a></li>
  38 + <li><a href="http://blog.getbootstrap.com" onclick="ga('send', 'event', 'Navbar', 'Community links', 'Blog');">About</a></li>
  39 + </ul>
  40 + </nav>
  41 + </div>
  42 + </header>
  43 + <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
  44 + <script type="text/javascript" src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
  45 +
  46 + {% block introblock %}{% endblock %}
  47 + {% block datadetails %}{% endblock %}
  48 +</body>
  49 +</html>
project/project/templates/trends.html View file @ 206a775
  1 +{% extends "header.html" %}
  2 +{% block datadetails %}
  3 +
1 4 <!DOCTYPE html>
2 5 <html lang="en">
3 6 <head>
4   - <meta charset="UTF-8">
  7 + <meta charset="UTF-8">
5 8  
6   - <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/bootstrap/bootstrap.min.css') }}">
7   - <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/bootstrap/doc.min.css') }}">
8   - <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/font-awesome.css') }}">
9   - <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/trends.css') }}">
  9 + <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/font-awesome.css') }}">
  10 + <link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='css/trends.css') }}">
10 11  
11 12  
12   - <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
13   - <script type="text/javascript" src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
  13 + <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
  14 + <script type="text/javascript" src="{{ url_for('static', filename='js/bootstrap.min.js') }}"></script>
14 15  
15   - <title>PIKI-Trends</title>
  16 + <title>PIKI-Trends</title>
16 17 </head>
17 18 <body>
18 19  
19   - <div class="container">
20   - <div class="row">
21   - <h1 style="color:#00a6de">PIKICAST TRENDS {% print s_date %}</h1>
22   - <ul>
23   - <span class="choice_date"><a href='{{ url_for('before_now',date=-1,s_date=s_date) }}'>이전 날짜</a></span>
24   - {% for i in range((date.split(' ')[1].split(':')[0]|int)+1) %}
25   - <span class="choice_date"><a href='{{ url_for('before_now',date=date.split(' ')[0] + ' ' + i|string + ':' + date.split(' ')[1].split(':')[1] + ':' + date.split(' ')[1].split(':')[2]) }}'>{% print i %}시</a></span>
26   - {% if i == 23 %}
27   - <span class="choice_date"><a href='{{ url_for('before_now',date=+1,s_date=s_date) }}'>이후 날짜</a></span>
28   - {% endif %}
29   - {% endfor %}
30   - </ul>
31   - <div class="col-md-4">
32   - <div class="panel panel-default">
33   - <!-- Default panel contents -->
34   - <div class="panel-heading">네이버 실시간 검색어 </div>
35   - <dl id="ranklist" class="ranklist">
36   - <dt id="rankTitle">실시간 급상승 검색어</dt>
37   - <dd>
38   - <ol id="realrank">
39   - {% for item in range(0,10) %}
40   - <li value="1" class="up"><a href="http://search.naver.com/search.naver?where=nexearch&amp;query={% print data['naver'][item].decode('utf-8') %}" title="">{% print data['naver'][item].decode('utf-8') %}
41   - <span class="ic" style="background-image:url(http://img.naver.net/static/www/2014/sp_main20141204.png)">
42   - </span>
43   - </a>
44   - </li>
45   - {% endfor %}
46   - </ol>
47   - </dd>
48   - </dl>
49   - </div>
50   - </div>
51   - <div class="col-md-4">
52   - <div class="panel panel-default">
53   - <!-- Default panel contents -->
54   - <div class="panel-heading">다음 실시간 검색어 </div>
55   - <div class="panel-body">
56   - <div id="minitoday" class="part_today">
57   - <ol id="realTimeSearchWord" class="list_issue #searchrank">
58   - {% for item in range(0,10): %}
59   - <li class="item_g realtime_viewport4 #issue " id="als-container_3" data-id="als-container_3">
60   - <div class="roll_txt realtime_wrapper1" id="scroll-wrapper_0" style="height: 34px; width: 200px;">
61   - <div class="rank_cont realtime_item1" id="scroll-item_0_0" style="top: 0px;">
62   - <span class="ico_daum rank_issue rank{% print item+1 %}"></span>
63   - <span class="txt_issue">
64   - <a href="http://search.daum.net/search?w=tot&amp;rtupcate=issue&amp;q={% print data['daum'][item].decode('utf-8') %}&amp;rtupcoll=DQP,NNS&amp;guide=rissue&amp;DA=ATG&amp;nil_profile=rtupkwd" class="ellipsis_g @1-1">
65   - <strong>{% print data['daum'][item].decode('utf-8') %}</strong>
66   - </a>
67   - </span>
68   - </div>
69   - </div>
70   - </li>
71   - {% endfor %}
72   - </ol>
73   - </div>
74   - </div>
75   - </div>
76   - </div>
77   - <div class="col-md-4">
78   - <div class="panel panel-default">
79   - <!-- Default panel contents -->
80   - <div class="panel-heading">트위터 trend </div>
81   - <div class="panel-body">
82   - <dl>
83   - <dd>
84   - <ol id="realrank">
85   - {% for item in data['twitter'] %}
86   - <li><a href="https://twitter.com/hashtag/{% print item.decode('utf-8').replace('#','') %}">{% print item.decode('utf-8') %}</a></li>
87   - {% endfor %}
88   - </ol>
89   - </dd>
90   - </dl>
91   - </div>
92   - </div>
93   - </div>
94   - </div>
  20 + <div class="container">
  21 + <div class="row">
  22 + <h1 style="color:#00a6de">PIKICAST TRENDS {% print s_date %}</h1>
  23 + <ul>
  24 + <span class="choice_date"><a href='{{ url_for('before_now',date=-1,s_date=s_date) }}'>이전 날짜</a></span>
  25 + {% for i in range((date.split(' ')[1].split(':')[0]|int)+1) %}
  26 + <span class="choice_date"><a href='{{ url_for('before_now',date=date.split(' ')[0] + ' ' + i|string + ':' + date.split(' ')[1].split(':')[1] + ':' + date.split(' ')[1].split(':')[2]) }}'>{% print i %}시</a></span>
  27 + {% if i == 23 %}
  28 + <span class="choice_date"><a href='{{ url_for('before_now',date=+1,s_date=s_date) }}'>이후 날짜</a></span>
  29 + {% endif %}
  30 + {% endfor %}
  31 + </ul>
  32 + <div class="col-md-4">
  33 + <div class="panel panel-default">
  34 + <!-- Default panel contents -->
  35 + <div class="panel-heading">네이버 실시간 검색어 </div>
  36 + <dl id="ranklist" class="ranklist">
  37 + <dt id="rankTitle">실시간 급상승 검색어</dt>
  38 + <dd>
  39 + <ol id="realrank">
  40 + {% for item in range(0,10) %}
  41 + <li value="1" class="up"><a href="http://search.naver.com/search.naver?where=nexearch&amp;query={% print data['naver'][item].decode('utf-8') %}" title="">{% print data['naver'][item].decode('utf-8') %}
  42 + <span class="ic" style="background-image:url(http://img.naver.net/static/www/2014/sp_main20141204.png)">
  43 + </span>
  44 + </a>
  45 + </li>
  46 + {% endfor %}
  47 + </ol>
  48 + </dd>
  49 + </dl>
  50 + </div>
  51 + </div>
  52 + <div class="col-md-4">
  53 + <div class="panel panel-default">
  54 + <!-- Default panel contents -->
  55 + <div class="panel-heading">다음 실시간 검색어 </div>
  56 + <div class="panel-body">
  57 + <div id="minitoday" class="part_today">
  58 + <ol id="realTimeSearchWord" class="list_issue #searchrank">
  59 + {% for item in range(0,10): %}
  60 + <li class="item_g realtime_viewport4 #issue " id="als-container_3" data-id="als-container_3">
  61 + <div class="roll_txt realtime_wrapper1" id="scroll-wrapper_0" style="height: 34px; width: 200px;">
  62 + <div class="rank_cont realtime_item1" id="scroll-item_0_0" style="top: 0px;">
  63 + <span class="ico_daum rank_issue rank{% print item+1 %}"></span>
  64 + <span class="txt_issue">
  65 + <a href="http://search.daum.net/search?w=tot&amp;rtupcate=issue&amp;q={% print data['daum'][item].decode('utf-8') %}&amp;rtupcoll=DQP,NNS&amp;guide=rissue&amp;DA=ATG&amp;nil_profile=rtupkwd" class="ellipsis_g @1-1">
  66 + <strong>{% print data['daum'][item].decode('utf-8') %}</strong>
  67 + </a>
  68 + </span>
  69 + </div>
  70 + </div>
  71 + </li>
  72 + {% endfor %}
  73 + </ol>
  74 + </div>
  75 + </div>
  76 + </div>
  77 + </div>
  78 + <div class="col-md-4">
  79 + <div class="panel panel-default">
  80 + <!-- Default panel contents -->
  81 + <div class="panel-heading">트위터 trend </div>
  82 + <div class="panel-body">
  83 + <dl>
  84 + <dd>
  85 + <ol id="realrank">
  86 + {% for item in data['twitter'] %}
  87 + <li><a href="https://twitter.com/hashtag/{% print item.decode('utf-8').replace('#','') %}">{% print item.decode('utf-8') %}</a></li>
  88 + {% endfor %}
  89 + </ol>
  90 + </dd>
  91 + </dl>
  92 + </div>
  93 + </div>
  94 + </div>
  95 + </div>
95 96 </div>
96 97 <footer>
97   - <div class="info">
98   - Contact information: <a href="mailto:tony.oh@pikicast.com">
99   - tony.oh@pikicast.com</a>.
100   - </div>
  98 + <div class="info">
  99 + Contact information: <a href="mailto:tony.oh@pikicast.com">
  100 + tony.oh@pikicast.com</a>.
  101 + </div>
101 102 </footer>
102 103 </body>
103 104 </html>
  105 +
  106 +{% endblock %}