Skip to content

Commit

Permalink
Merge pull request #94 from SCCapstone/heroku-dev
Browse files Browse the repository at this point in the history
Update Master branch for RC1
  • Loading branch information
Nekomian44 authored Apr 16, 2018
2 parents bd0629f + 3b482b6 commit 5f1f892
Show file tree
Hide file tree
Showing 11 changed files with 251 additions and 120 deletions.
1 change: 1 addition & 0 deletions social_monomania/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
url(r'^thanks/', views.thanks, name='thanks'),
url(r'^graph/', views.graph, name='graph'),
url(r'^results/', views.results, name='results'),
url(r'^advancedresults/', views.advancedresults, name='advancedresults'),
url(r'^help/', views.help, name='help'),
url(r'^advSearch/', views.advSearch, name='advSearch'),
url(r'^download/', views.download, name='download')
Expand Down
119 changes: 93 additions & 26 deletions social_monomania/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.contrib.auth import authenticate
from django.db import models
from utilities import basicHandler
from utilities import advancedHandler
from django.views import View
import json #added for export

Expand All @@ -26,7 +27,7 @@ def hello(request):
return HttpResponseRedirect('online/login')

def search(request):
return render(request, 'home.html')
return render(request, 'search.html')

def advSearch(request):
return render(request, 'advSearch.html')
Expand Down Expand Up @@ -99,7 +100,7 @@ def download(request):
sheet.set_column('C:C', 50)
twittersheet.set_column('A:A', 35)
twittersheet.set_column('B:F', 15)
twittersheet.set_column('G:G', 35)
twittersheet.set_column('G:K', 35)
sheet.freeze_panes(1, 0)
twittersheet.freeze_panes(1, 0)

Expand All @@ -114,54 +115,92 @@ def download(request):

redrow = 1
redcol = 0
for entry in redditVariable:
sheet.write(redrow, redcol, entry, posts_format)
sheet.write(redrow, redcol+1, redditVariable[entry]['time'], posts_format)
sheet.write(redrow, redcol+2, redditVariable[entry]['url'], url_format)
redrow += 1
#------------------REDDIT------------------------------------------------

#Spreadsheet titles for reddit sheet
headerObjReddit = ['Post Title', 'Time', 'URL']
redcol = 0
for header in headerObjReddit:
sheet.write(0,redcol, header, titles_format)
redcol = redcol + 1

redrow = 1
redcol = 0
#error catching if Reddit isn't checked/returns 0 results
if not redditVariable:
sheet.write(1, 0, "No Reddit Data Found", posts_format)
else:
for entry in redditVariable:
sheet.write(redrow, redcol, entry, posts_format)
sheet.write(redrow, redcol+1, str(redditVariable[entry]['time']), posts_format)
sheet.write(redrow, redcol+2, redditVariable[entry]['url'], url_format)
redrow += 1

#----------------------TWITTER------------------------------------------

#titles in the sheet
headerObj = ['Text', 'User', 'Date', 'Retweets', 'Favorited', 'Location']
headerObj = ['Text', 'User', 'Date', 'Retweets', 'Favorited', 'Location', 'Link to Tweet', 'User Profile Link', '@Mention link', 'Media Link']
twitcol = 0
for header in headerObj:
twittersheet.write(0,twitcol, header, titles_format)
twitcol = twitcol + 1

twitrow = 1
twitcol = 0
statusList = twitterVariable['statuses']
for entry in statusList:
#text, user, date, retweets, favorited, geolocation, link
twittersheet.write(twitrow, twitcol, entry['text'], posts_format)
twittersheet.write(twitrow, twitcol+1, entry['user']['screen_name'], posts_format)
twittersheet.write(twitrow, twitcol+2, entry['created_at'], posts_format)
twittersheet.write(twitrow, twitcol+3, entry['retweet_count'], posts_format)
twittersheet.write(twitrow, twitcol+4, entry['favorite_count'], posts_format)
twittersheet.write(twitrow, twitcol+5, entry['user']['location'], posts_format)
#below is profile link. can't get it working. removing 'Profile Link' from headerObj
#twittersheet.write(twitrow, twitcol+6, entry['entities']['urls']['url'], url_format)
twitrow += 1

#------------------------------------------------------------------

#error catching if Twitter box isn't checked/returns 0 results
if not twitterVariable:
twittersheet.write(1, 0, "No Twitter Data Found", posts_format)
else:
statusList = twitterVariable['statuses']
mentionList = []
mediaList = []
for entry in statusList:
#text, user, date, retweets, favorited, geolocation, link
twittersheet.write(twitrow, twitcol, entry['text'], posts_format)
twittersheet.write(twitrow, twitcol+1, entry['user']['screen_name'], posts_format)
twittersheet.write(twitrow, twitcol+2, entry['created_at'], posts_format)
twittersheet.write(twitrow, twitcol+3, entry['retweet_count'], posts_format)
twittersheet.write(twitrow, twitcol+4, entry['favorite_count'], posts_format)
twittersheet.write(twitrow, twitcol+5, entry['user']['location'], posts_format)
twittersheet.write_url(twitrow, twitcol+6, 'https://www.twitter.com/statuses/'+str(entry['id']), url_format)
twittersheet.write_url(twitrow, twitcol+7, 'https://www.twitter.com/'+str(entry['user']['screen_name']), url_format)
#user mentions requires a bit more work. The for-loop fills a list, and .join() is used in writing all the list elements
for mention in entry['entities']['user_mentions']:
mentionList.append('https://www.twitter.com/'+mention['screen_name']+'\n')
twittersheet.write_url(twitrow, twitcol+8, ''.join(mentionList), url_format)
#media links is similar to user mentions. Was not possible to access
#with entry['extended_entities']['media']['media_url_https'], so had to
#work around it a bit.
if 'extended_entities' in entry:
for item in entry['extended_entities']['media']:
mediaList.append(item['media_url_https']+'\n')
twittersheet.write_url(twitrow, twitcol+9, ''.join(mediaList), url_format)

#clear lists for next entry, go to next row to fill
mentionList[:] = []
mediaList[:] = []
twitrow += 1

#------------------------------------------------------------------

#Closing the workbook
book.close()

#construct response
output.seek(0)
response = HttpResponse(output.read(), content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
response['Content-Disposition'] = "attachment; filename=SM_Results.xlsx"

return response
response = HttpResponse(output.read(), content_type="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
response['Content-Disposition'] = "attachment; filename=SM_Results.xlsx"

return response

def results(request):

if request.method == 'POST':
print(request.POST)
# print(request.POST['q'])
# print(request.POST['boxes[]'])
global searchQuery
searchQuery = request.POST['q']
redditReturn, twitterReturn = basicHandler.searchHandle(request.POST['q'], dict(request.POST)['boxes[]'])
Expand All @@ -173,6 +212,34 @@ def results(request):
global twitterVariable
twitterVariable = twitterReturn
global twitterVariable1

return render(request, 'results.html', {'redditReturn': redditReturn, 'twitterReturn': twitterReturn, 'searchQuery': searchQuery})

def advancedresults(request):

if request.method == 'POST':
print(request.POST)
# print(request.POST['q'])
# print(request.POST['boxes[]'])
global searchQuery
queryOne = request.POST['q1']
queryTwo = request.POST['q2']
booleanOp = request.POST['booleanOperator']
searchQuery = queryOne + " " + booleanOp + " " + queryTwo

twitterDate = request.POST['newestDate']

subredditsDict = dict(request.POST)['subboxes[]']
subredditsDict.append(request.POST['searchCustomSub'])
redditReturn, twitterReturn = advancedHandler.searchHandle(searchQuery, dict(request.POST)['boxes[]'], subredditsDict, twitterDate)
#reddit global variables
global redditVariable
redditVariable = redditReturn
global redditVariable1
#twitter global variables
global twitterVariable
twitterVariable = twitterReturn
global twitterVariable1



Expand Down
11 changes: 7 additions & 4 deletions templates/about.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@

{% block content %}
<p class='about_info'> This webapp was created as a Computer Science Capstone project by several students at the University of South Carolina.
This is meant to be a way to search multiple social media sites at one time and gain insight into trends shown on these sites.
This webapp has very limited functions compared to full featured paid services. </p>
This is meant to be a way to search multiple social media sites at one time and to gain insight into trends shown on these sites.
This webapp currently has very limited functionality compared to full featured, paid services. </p>

<p class='about_info'> Use the large search bar on the home page to begin a new search. Consult the frequently asked questions page for more help. If
you run into a problem, feel free to use our contact us page to let us know about the issue.
<p class='about_info'> Navigate to the <a href="{% url 'search' %}">Search Page</a> to begin a query. Consult the <a href="{% url 'help' %}">Help Page</a> if you have any questions. If
your issue is still not resolved or simply not listed, feel free to <a href="{% url 'contact' %}">Contact Us Here!</a>
</p>
<br>
<h2>Disclamer:</h2>
<h3><em>*Due to the recent Cambridge Analytica Scandal, both Facebook and Instagram have severely limited their public data access; as a result, they are currently unavaliable*</em></h3>
{% endblock %}
50 changes: 13 additions & 37 deletions templates/advSearch.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
{% block heading %} Advanced Search {% endblock %}

{% block content %}
<form id='advSearch' method='get' onsubmit='return validateForm()' action='http://socialmonomania-dev.herokuapp.com/results' >
<form id='advSearch' method='post' onsubmit='return validateForm()' action='/advancedresults/' >
{% csrf_token %}
<h3>Enter your search in the bar below and press enter. </h3>
<input class="w3-input w3-border w3-round-large"type="search" id="searchMain" name='q' placeholder="Search.." >
<input class="w3-input w3-border w3-round-large"type="search" id="searchMain" name='q1' placeholder="Search.." >
<p>
<select id = "myList">
<select id = "myList" name="booleanOperator">
<option value = "AND">AND</option>
<option value = "OR">OR</option>
<option value = "NOT">NOT</option>
</select>
</p>

<input class="w3-input w3-border w3-round-large"type="search" id="searchSecond" name='q' placeholder="Search.." >
<input class="w3-input w3-border w3-round-large" type="search" id="searchSecond" name='q2' placeholder="Search.." >
<br>&nbsp;</br>
<button id='s_button' style onclick="myFunction()">Search</button>
<br>&nbsp;</br>
Expand All @@ -26,12 +27,11 @@ <h3>Enter your search in the bar below and press enter. </h3>
<div id='redditSubmenu'>
<p> Select subreddit to search</p>
<input type="checkbox" name='subboxes[]' id="news" value= 'news' checked/> News<br />
<input type="checkbox" name='subboxes[]' id="SC" value='SC'checked/> SC<br />
<p>Date Filter </p>
<label for="redditFromDate">From</label>
<input type='date' name='startDate' id='redditFromDate'>
<label for="redditEndDate">To</label>
<input type='date' name='endDate' id='redditEndDate'>
<input type="checkbox" name='subboxes[]' id="SC" value='southcarolina' checked/> SC<br />

<p>Custom Subreddit (Please check subreddit's proper name before searching)</p>
<input class="w3-input w3-border w3-round-large"type="search" id="searchCustomSub" name='searchCustomSub' placeholder="Search.." >

</div>
</div>

Expand All @@ -41,23 +41,9 @@ <h3>Enter your search in the bar below and press enter. </h3>
<p>Location</p>
<input class="w3-input w3-border w3-round-large"type="search" id="searchLocation" name='q' placeholder="Search.." >
<p>Date Filter </p>
<label for="twitterFromDate">From</label>
<input type='date' name='startDate' id='twitterFromDate'>
<label for="twitterEndDate">To</label>
<input type='date' name='endDate' id='twitterEndDate'>
</div>
</div>

<div id='instagramBox'>
<input type="checkbox" name='boxes[]' id="instagramAdvBox" value='test' onclick="instagramSearch(this)" checked/>Instagram<br />
<div id='instagramSubmenu'>
<p>Location</p>
<input class="w3-input w3-border w3-round-large"type="search" id="searchLocation" name='q' placeholder="Search.." >
<p>Date Filter </p>
<label for="instagramFromDate">From</label>
<input type='date' name='startDate' id='instagramFromDate'>
<label for="instagramEndDate">To</label>
<input type='date' name='endDate' id='instagramEndDate'>
<label for="twitterBeforeDate">Before</label>
<input type='date' name='newestDate' id='newestDate'>
<p> Find posts up to this date </p>
</div>
</div>
</div>
Expand All @@ -84,16 +70,6 @@ <h3>Enter your search in the bar below and press enter. </h3>
}
}

function instagramSearch(checkbox)
{ if (checkbox.checked)
{ //search using Reddit
document.getElementById('instagramSubmenu').style.display = 'block';

}else{
document.getElementById('instagramSubmenu').style.display = 'none';
}
}



function validateForm(){
Expand Down
15 changes: 9 additions & 6 deletions templates/graph.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
function getRandomInt() {
return Math.floor((Math.random() * 1000) + 1);
}

var ctx = document.getElementById("myChart").getContext('2d');
var facebook_data = [getRandomInt(), getRandomInt(), getRandomInt(), getRandomInt(), getRandomInt(), getRandomInt(), getRandomInt()];

var reddit_data = [getRandomInt(), getRandomInt(), getRandomInt(), getRandomInt(), getRandomInt(), getRandomInt(), getRandomInt()];
var twitter_data = [getRandomInt(), getRandomInt(), getRandomInt(), getRandomInt(), getRandomInt(), getRandomInt(), getRandomInt()];

var max = Math.max(
Math.max.apply(null, facebook_data),
Math.max.apply(null, reddit_data),
Math.max.apply(null, twitter_data)
);
var pad_top = max *.10;
Expand All @@ -20,13 +23,13 @@
labels: ["0:00", "4:00", "8:00", "12:00", "16:00", "20:00", "0:00"],
datasets: [
{
label: 'Facebook',
data: facebook_data,
label: 'Reddit',
data: reddit_data,
fill: false,
backgroundColor: [
'rgba(59, 89, 152, 0.6)'],
'rgba(255, 69, 0, 0.6)'],
borderColor: [
'rgba(59, 89, 152, 0.6)'],
'rgba(255, 69, 0, 0.6)'],
borderWidth: 1.5
},
{
Expand Down
32 changes: 13 additions & 19 deletions templates/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,34 @@
{% block content %}

<p> Have a question? Check the FAQ first, then feel free to contact us if the issue isn't resolved. </p>


<h1>FAQ:</h1>
<div id='question'>
<h4>Q: What social media platforms does Social Monomania pull the results from?</h4>
<p>A: Facebook,Instagram, Reddit, Twitter </p>
<h4>Q: What social media platforms does Social Monomania currently pull the results from?</h4>
<p>A: Right now, our results are retrieved from Twitter and Reddit! </p>
</div>

<div id='question'>
<h4> Q: Can I save the results?</h4>
<p> A: Yes, there is a downloadable excel file available at the end of every search <br></p>
<p> A: Yes! At the top of the results page, there is a .CSV export button. <br></p>
</div>

<div id='question'>
<h4>Q: What are the options for advanced search?</h4>
<p>A: Geolocation, source such as Facebook only items, filter by time period<br></p>
<p>A: Geolocation, time period, sub-reddit, and other API exclusive limitors are avaliable!<br></p>
</div>

<div id='question'>
<h4> Q: Will any other social media platforms be added?</h4>
<p>A: Yes, in the future we will be looking to implement more media platforms. Stay tuned.<br></p>
<p>A: Yes, in the future we will be looking to implement more platforms. Stay tuned!<br></p>
</div>

<div id='question'>
<h4> Q: Why is there a login feature?</h4>
<p>A: To prevent overloading our servers at the moment, we are restricting only authorized logins to use our features.<br> </p>
<h4> Q: Is this data stored or saved anywhere?</h4>
<p>A: Currently, data is not stored after a search; this is to prevent storage caps from our database and due to the fact that social media data has a short relevance time.</p>
</div>

<div id='question'>
<h4> Q: How do I search within Facebook?</h4>
<p>A: Make sure Facebook is selected for search results, then use hashtags (#) and keywords; or keywords by themselves.<br> </p>
<h4> Q: Why is there a login feature?</h4>
<p>A: To prevent overloading our servers at the moment, we are restricting only authorized logins to use our features. Currently, the registration is in open-enrollment.<br> </p>
</div>

<!-- Twitter operators found here: https://lifehacker.com/search-twitter-more-efficiently-with-these-search-opera-1598165519 -->
<div id='question'>
<h4> Q: How do I search within Twitter?</h4>
Expand All @@ -62,11 +58,9 @@ <h4> Q: How do I search within Reddit?</h4>
<p>subreddit:[name] searches only posts that were submitted to the given subreddit community.<br> </p>
</div>

<div id='question'>
<h4> Q: How do I search within Instagram?</h4>
<p>A: Make sure Instagram is selected for search results, and simply enter the name, hashtag, or place you're looking for.<br> </p>
<br>
<h3>Have a Question or Suggestion? <a href="{% url 'contact' %}">Contact Us Here!</a></h3>
</div>

<a href="{% url 'contact' %}">Contact Us</a>
<br>

{% endblock %}
Loading

0 comments on commit 5f1f892

Please sign in to comment.