Skip to content

Commit

Permalink
Merge pull request #29 from MLH-Fellowship/staging
Browse files Browse the repository at this point in the history
Staging
  • Loading branch information
ramanaditya authored Oct 13, 2020
2 parents d3eac80 + d5bd5c2 commit 4e7cad3
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 251 deletions.
52 changes: 31 additions & 21 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import json
import sys
from datetime import datetime, time
import random

import pandas as pd
from flask import Flask, jsonify
from flask import Flask, jsonify, Response

from apps.process_data import ProcessData, Results
from apps.tweets import Twitter
Expand All @@ -16,27 +19,34 @@
backtrace=True,
diagnose=True,
)
app = Flask(__name__,
static_url_path='',
static_folder='./static',
template_folder='./templates')
app = Flask(
__name__,
static_url_path="",
static_folder="./static",
template_folder="./templates",
)


@app.route("/", methods=["GET"])
def index():
return render_template("index.html")


@app.route("/analyzetweets", methods=["GET"])
def analyze_tweets():
# twitter = Twitter()
# top_trends = twitter.get_top_trends()
# logger.info(f"Top trends now are {top_trends}")
# trending_tweets = twitter.get_trending_tweets(top_trends[0]["name"])
# df = pd.DataFrame(trending_tweets)
# esp = 1.29
# df, clusters_count = ProcessData().cluster(esp, df)
# res, clusters_count = Results(df).get_result()
# logger.info(f"Clusters: {clusters_count}")
# result = {}
# for ind, row in res.iterrows():
# result[ind] = dict(row)
# response = dict()
# response["cluserts_count"] = clusters_count.to_json()
# response["result"] = result
return render_template('index.html')
twitter = Twitter()
top_trends = twitter.get_top_trends()
logger.info(f"Top trends now are {top_trends}")
trending_tweets = twitter.get_trending_tweets(top_trends[0]["name"])
df = pd.DataFrame(trending_tweets)
esp = 1.29
df, clusters_count = ProcessData().cluster(esp, df)
res, clusters_count = Results(df).get_result()
result = {}
for ind, row in res.iterrows():
result[ind] = dict(row)
clusters_count = json.loads(clusters_count.to_json())
response = dict()
response["cluserts_count"] = clusters_count
response["result"] = result
return jsonify(response)
172 changes: 0 additions & 172 deletions scripts/main.py

This file was deleted.

109 changes: 51 additions & 58 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,50 @@
<link rel="stylesheet" href="{{ url_for('static', filename='css/owl-carousel.css') }}">

<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700,800" rel="stylesheet">

<script src="{{ url_for('static', filename='js/vendor/modernizr-2.8.3-respond-1.4.2.min.js') }}"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.min.js" integrity="sha512-s+xg36jbIujB2S2VKfpGmlC3T5V2TF3lY48DX7u2r9XzGzgPsa6wTpOQA7J9iffvdeBN0q9tKzRxVxw1JviZPg==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.js" integrity="sha512-G8JE1Xbr0egZE5gNGyUm1fF764iHVfRXshIoUWCTPAbKkkItp/6qal5YAHXrxEu4HNfPTQs6HOu3D5vCGS1j3w==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.bundle.min.js" integrity="sha512-vBmx0N/uQOXznm/Nbkp7h0P1RfLSj0HQrFSzV8m7rOGyj30fYAOKHYvCNez+yM8IrfnW0TCodDEjRqf6fodf/Q==" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.9.3/Chart.js" integrity="sha512-QEiC894KVkN9Tsoi6+mKf8HaCLJvyA6QIRzY5KrfINXYuP9NxdIkRQhGq3BZi0J4I7V5SidGM3XUQ5wFiMDuWg==" crossorigin="anonymous"></script>
<script src="{{ url_for('static', filename='js/vendor/modernizr-2.8.3-respond-1.4.2.min.js') }}"></script>
</head>

<!--
Vanilla Template
https://templatemo.com/tm-526-vanilla
-->
<body>
<script>
window.onload = function () {

var chart = new CanvasJS.Chart("chartContainer", {
animationEnabled: true,
theme: "light2", // "light1", "light2", "dark1", "dark2"
title:{
text: "Sentimental Clusters with Twitter Data"
},
axisY: {
title: "Tweets"
},
data: [{
type: "column",
showInLegend: true,
legendMarkerColor: "grey",
legendText: "Clusters",
dataPoints: [
{ y: 416, label: "Cluster 0" },
{ y: 24, label: "Cluster 1" },
{ y: 454, label: "Cluster 2" },
{ y: 52, label: "Cluster 3" },
{ y: 27, label: "Cluster 4" },
{ y: 28, label: "Cluster 5" },
],
}]
});
chart.render();

}
</script>
<body>


<div class="fixed-side-navbar">
<ul class="nav flex-column">
Expand All @@ -50,61 +85,14 @@ <h4 style="color: ghostwhite">v1.0.0</h4>
</div>


<!-- <div class="service-content" id="services">-->
<!-- <div class="container">-->
<!-- <div class="row">-->
<!-- <div class="col-md-4">-->
<!-- <div class="left-text">-->
<!-- <h4>More About Vanilla</h4>-->
<!-- <div class="line-dec"></div>-->
<!-- <p>Vanilla is free HTML CSS template with Bootstrap v4.2.1 and you can apply this theme for your sites.-->
<!-- Please share our <a rel="nofollow" href="https://templatemo.com">website</a> to your friends or collegues. Thank you.</p>-->
<!-- <ul>-->
<!-- <li>- Praesent porta urna id eros</li>-->
<!-- <li>- Curabitur consectetur malesuada</li>-->
<!-- <li>- Nam pretium imperdiet enim</li>-->
<!-- <li>- Sed viverra arcu non nisi efficitur</li>-->
<!-- </ul>-->
<!-- <div class="primary-button">-->
<!-- <a href="#portfolio">Learn More About Us</a>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="col-md-8">-->
<!-- <div class="row">-->
<!-- <div class="col-md-6">-->
<!-- <div class="service-item">-->
<!-- <h4>Classic Modern Design</h4>-->
<!-- <div class="line-dec"></div>-->
<!-- <p>Sed lacinia ligula est, at venenatis ex iaculis quis. Morbi sollicitudin nulla eget odio pellentesque.</p>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="col-md-6">-->
<!-- <div class="service-item">-->
<!-- <h4>Unique &amp; Creative Ideas</h4>-->
<!-- <div class="line-dec"></div>-->
<!-- <p>Sed lacinia ligula est, at venenatis ex iaculis quis. Morbi sollicitudin nulla eget odio pellentesque.</p>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="col-md-6">-->
<!-- <div class="service-item">-->
<!-- <h4>Effective Team Work</h4>-->
<!-- <div class="line-dec"></div>-->
<!-- <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed lacinia ligula est, at venenatis ex iaculis quis.</p>-->
<!-- </div>-->
<!-- </div>-->
<!-- <div class="col-md-6">-->
<!-- <div class="service-item">-->
<!-- <h4>Fast Support 24/7</h4>-->
<!-- <div class="line-dec"></div>-->
<!-- <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed lacinia ligula est, at venenatis ex iaculis quis.</p>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
<!-- </div>-->
<div>
<div class="container">
<!-- <canvas id="canvas" width="400" height="400"></canvas>-->
<div id="chartContainer" style="height: 300px; width: 100%;"></div>
<script src="https://canvasjs.com/assets/script/canvasjs.min.js"></script>
</div>
</div>



<!-- <div class="tabs-content" id="our-story">-->
Expand Down Expand Up @@ -183,6 +171,11 @@ <h4 style="color: ghostwhite">v1.0.0</h4>
});
});
</script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
<!--suppress JSUnresolvedLibraryURL -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.min.js"></script>
<!--suppress JSUnresolvedLibraryURL -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.8.0/Chart.min.js"></script>

</body>
</html>

0 comments on commit 4e7cad3

Please sign in to comment.