Skip to content

Commit

Permalink
Changed structure
Browse files Browse the repository at this point in the history
  • Loading branch information
joelklint committed Apr 7, 2017
1 parent 25c1ede commit 952052f
Show file tree
Hide file tree
Showing 10 changed files with 189 additions and 74 deletions.
17 changes: 17 additions & 0 deletions templates/base.html
@@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<title>{% block title %}{% endblock %} Web View</title>
</head>
<body>
<div id="content">
{% include "nav_bar.html" %}
{% block content %}
{% endblock %}
</div>

</body>
</html>
16 changes: 16 additions & 0 deletions templates/nav_bar.html
@@ -0,0 +1,16 @@
{% block content %}

<nav class="navbar navbar-inverse">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="/">twitter geolocater</a>
</div>
<ul class="nav navbar-nav">
<li><a href="/search">Search in tables</a></li>
<li><a href="#">Calculate scores</a></li>
<li><a href="#">View on map</a></li>
</ul>
</div>
</nav>

{% endblock %}
9 changes: 9 additions & 0 deletions templates/search.html
@@ -0,0 +1,9 @@
{% extends "base.html" %}

{% block content %}

{% include "tables.html" %}

{% include "search_table.html"%}

{% endblock %}
23 changes: 23 additions & 0 deletions templates/search_table.html
@@ -0,0 +1,23 @@
{% block content %}
<h1>Table: {{data.table}}</h1>
<table class="table table-condensed">
<thead>
<tr>
{% for columns in data.cols %}
<th>{{columns}}</th>
{% endfor %}
</tr>
</thead>
<tbody>
<tr>
{% for entry in data.entries%}
{% for datapoint in entry%}
<td>{{datapoint}}</td>
{% endfor %}
</tr>
{% endfor%}

</tbody>
</table>

{% endblock %}
18 changes: 18 additions & 0 deletions templates/statistics.html
@@ -0,0 +1,18 @@
{% extends "base.html" %}

{% block content %}

<div>Tweet count: {{ tweet_count }}</div>
<div>Retweet count: {{ retweet_count }}</div>
<div>Commented retweets count: {{ commented_retweet_count }}</div>
<div>Reply tweets count: {{ reply_tweet_count }}</div>
<div>Mention tweets count: {{ total_mention_count }}</div>

<br>

<div>Retweet percentage: {{ (retweet_count/tweet_count)|round(3) }}%</div>
<div>Commented retweet percentage: {{ (commented_retweet_count/tweet_count)|round(3) }}%</div>
<div>Reply tweet percentage: {{ (reply_tweet_count/tweet_count)|round(3) }}%</div>
<div>Mention tweet percentage: {{ (total_mention_count/tweet_count)|round(3) }}%</div>

{% endblock %}
25 changes: 25 additions & 0 deletions templates/tables.html
@@ -0,0 +1,25 @@
{% block content %}
<h1>Select the table you want to view</h1>
<div class="row">
<div class="col-lg-6">
<div class="input-group">
<div class="input-group-btn">
<div class="dropdown">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Tables<span class="caret"></span></button>
<ul class="dropdown-menu">
{% for table in tables %}
<li><a href=/search/{{table}}>{{table}}</a></li>
{% endfor %}
</ul>
</div>
</div><!-- /btn-group -->
</div><!-- /input-group -->
</div><!-- /.col-lg-6 -->
</div>
<script type="text/javascript">
$(".dropdown-menu li a").click(function(){
$(this).parents(".dropdown").find('.btn').html($(this).text() + ' <span class="caret"></span>');
$(this).parents(".dropdown").find('.btn').val($(this).data('value'));
});
</script>
{% endblock %}
5 changes: 5 additions & 0 deletions templates/test.html
@@ -0,0 +1,5 @@
{% block content %}

<h1>Hello World, we currently have {{nbrOfUsers}} users!</h1>

{% endblock %}
74 changes: 1 addition & 73 deletions web/database.py
Expand Up @@ -130,76 +130,4 @@ def get_total_tweet_count(self):
tweet_count = cur.fetchone()

cur.close()
return tweet_count[0]

def get_total_clean_retweet_count(self):
cur = self.conn.cursor()

statement = """
SELECT count(*)
FROM tweets
WHERE text ILIKE 'RT @realDonaldTrump%'
"""

cur.execute(statement)
retweet_count = cur.fetchone()

cur.close()
return retweet_count[0]

def get_total_commented_retweet_count(self):
cur = self.conn.cursor()

statement = """
SELECT count(*)
FROM tweets
WHERE text ILIKE '@realDonaldTrump%https://t.co/%'
"""
cur.execute(statement)
commented_retweet_count = cur.fetchone()

cur.close()
return commented_retweet_count[0]

def get_total_reply_count(self):
cur = self.conn.cursor()

statement = """
SELECT
(SELECT count(*)
FROM tweets
WHERE text ILIKE '@realDonaldTrump%'
AND in_reply_to_user_id IN (SELECT user_id FROM trumps_tweets LIMIT 1))
-
(SELECT count(*)
FROM tweets
WHERE text ILIKE '@realDonaldTrump%https://t.co/%')
AS total_count
"""
cur.execute(statement)
commented_retweet_count = cur.fetchone()

cur.close()
return commented_retweet_count[0]

def get_total_mention_count(self):
cur = self.conn.cursor()

statement = """
SELECT
(SELECT count(*)
FROM tweets
WHERE text ILIKE '@realDonaldTrump%'
AND in_reply_to_user_id NOT IN (SELECT user_id FROM trumps_tweets LIMIT 1))
-
(SELECT count(*)
FROM tweets
WHERE text ILIKE '@realDonaldTrump%https://t.co/%')
AS total_count
"""
cur.execute(statement)
commented_retweet_count = cur.fetchone()

cur.close()
return commented_retweet_count[0]

return tweet_count[0]
74 changes: 74 additions & 0 deletions web/database_text_searcher.py
@@ -0,0 +1,74 @@
from database import Database

class Database(Database):

def get_total_clean_retweet_count(self):
cur = self.conn.cursor()

statement = """
SELECT count(*)
FROM tweets
WHERE text ILIKE 'RT @realDonaldTrump%'
"""

cur.execute(statement)
retweet_count = cur.fetchone()

cur.close()
return retweet_count[0]

def get_total_commented_retweet_count(self):
cur = self.conn.cursor()

statement = """
SELECT count(*)
FROM tweets
WHERE text ILIKE '@realDonaldTrump%https://t.co/%'
"""
cur.execute(statement)
commented_retweet_count = cur.fetchone()

cur.close()
return commented_retweet_count[0]

def get_total_reply_count(self):
cur = self.conn.cursor()

statement = """
SELECT
(SELECT count(*)
FROM tweets
WHERE text ILIKE '@realDonaldTrump%'
AND in_reply_to_user_id IN (SELECT user_id FROM trumps_tweets LIMIT 1))
-
(SELECT count(*)
FROM tweets
WHERE text ILIKE '@realDonaldTrump%https://t.co/%')
AS total_count
"""
cur.execute(statement)
commented_retweet_count = cur.fetchone()

cur.close()
return commented_retweet_count[0]

def get_total_mention_count(self):
cur = self.conn.cursor()

statement = """
SELECT
(SELECT count(*)
FROM tweets
WHERE text ILIKE '@realDonaldTrump%'
AND in_reply_to_user_id NOT IN (SELECT user_id FROM trumps_tweets LIMIT 1))
-
(SELECT count(*)
FROM tweets
WHERE text ILIKE '@realDonaldTrump%https://t.co/%')
AS total_count
"""
cur.execute(statement)
commented_retweet_count = cur.fetchone()

cur.close()
return commented_retweet_count[0]
2 changes: 1 addition & 1 deletion web/server.py
@@ -1,5 +1,5 @@
from flask import Flask, render_template
from database import Database
from database_text_searcher import Database
app = Flask(__name__)


Expand Down

0 comments on commit 952052f

Please sign in to comment.