Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getting lastest changes #91

Open
wants to merge 100 commits into
base: Jessica
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
100 commits
Select commit Hold shift + click to select a range
df806d4
Merge pull request #73 from SIU-CS/master
akohli96 Apr 8, 2017
9233920
Started bot page
akohli96 Apr 9, 2017
2c1511b
Changed constant name so pylint is happy
akohli96 Apr 9, 2017
473d8a5
Displaying posted data on same page
akohli96 Apr 9, 2017
b8720aa
Display on page refresh (GET request)
akohli96 Apr 9, 2017
4edf94a
Adding link for help
akohli96 Apr 9, 2017
2902a8b
Merge pull request #77 from SIU-CS/master
akohli96 Apr 9, 2017
bf90326
Added model for Messaging with bot
akohli96 Apr 11, 2017
c79197d
Print is_user as well
akohli96 Apr 11, 2017
7e3aacb
Fixed integrety error with date time
akohli96 Apr 11, 2017
907f58c
Focusing on getting chat done for time being
akohli96 Apr 11, 2017
6eb1312
Added better start doc
akohli96 Apr 11, 2017
7dbb9cf
Messages getting saved to db
akohli96 Apr 11, 2017
4fb4501
Displaying all the messages on GET request
akohli96 Apr 11, 2017
91936f1
All messages displayed on POST as well
akohli96 Apr 11, 2017
cf09cb8
Merge pull request #80 from SIU-CS/master
akohli96 Apr 14, 2017
6577ea5
python manage.py loaddata fixtures/quotes.json
akohli96 Apr 16, 2017
9a46b54
Merge branch 'sprint3-ayush' of https://github.com/SIU-CS/J-JAM-produ…
akohli96 Apr 16, 2017
f4e320d
removing semi colon cause python
akohli96 Apr 16, 2017
b55a63a
Adding new line because pylint
akohli96 Apr 16, 2017
7601a08
Different file to encapsulate bot message processing
akohli96 Apr 16, 2017
8f028ff
Fixed bug with refering Quote object
akohli96 Apr 16, 2017
caf0cfb
Throwing up Usage method and using returns instead of print in bot_he…
akohli96 Apr 18, 2017
87fd62a
Encapsulated everythign in a class with static method
akohli96 Apr 18, 2017
b66437e
OOPfied bot logic
akohli96 Apr 19, 2017
56cf777
python manage.py loaddata fixtures/quotes.json
akohli96 Apr 16, 2017
f697f7e
Added logic for notification after 24 hours without a new post
perpetual-pelican Apr 20, 2017
893a65a
Bot processing message on chat page
akohli96 Apr 20, 2017
b991089
If request fails return first quote saved in database
akohli96 Apr 20, 2017
bae88bc
So help response does not fail
akohli96 Apr 20, 2017
aa33f18
Bot message also on console. Both working.
akohli96 Apr 20, 2017
e9e1f74
This doesn't work yet; concerned about bootstrap / jquery console error
markiragoldberg Apr 21, 2017
d2688d8
Remove trailing spaces from quote & author
markiragoldberg Apr 21, 2017
b34d3ff
Merge quote json and notification for not posting recently
markiragoldberg Apr 21, 2017
723a47c
Merge branch 'sprint3-mark' into master
markiragoldberg Apr 21, 2017
4c4ff31
Merge pull request #85 from SIU-CS/master
markiragoldberg Apr 21, 2017
fcd5918
views.py needs datetime
markiragoldberg Apr 23, 2017
eb0b643
The happygraph is now clickable
markiragoldberg Apr 23, 2017
8219223
Make happygraph links work with "back"
markiragoldberg Apr 23, 2017
6c2d587
Merge pull request #86 from SIU-CS/sprint3-mark
akohli96 Apr 27, 2017
7b83fc2
Merge branch 'sprint3-ayush' into master
akohli96 Apr 29, 2017
4044201
Merge pull request #87 from SIU-CS/master
akohli96 Apr 29, 2017
6a07f77
Throwing up my three tests
akohli96 Apr 30, 2017
760917a
Merge pull request #88 from SIU-CS/Jessica
markiragoldberg May 2, 2017
0703040
Merge pull request #89 from SIU-CS/master
akohli96 May 2, 2017
03c3fd4
Fix a couple bugs with the happygraph
markiragoldberg May 2, 2017
5293e8f
Merge pull request #90 from SIU-CS/sprint3-mark
akohli96 May 2, 2017
4cb2eab
Add links to resources when making an ungood post
markiragoldberg May 2, 2017
baec7aa
Merge branch 'Jessica' into master
akohli96 May 2, 2017
71fb27e
Merge pull request #92 from SIU-CS/sprint3-mark
akohli96 May 2, 2017
0d2400e
Cleaned up bot page and changed logic to display only last ten messages
perpetual-pelican May 3, 2017
11a5bcd
Merge branch 'master' of https://github.com/SIU-CS/J-JAM-production i…
perpetual-pelican May 3, 2017
ae9d0f1
Fixed bot page error when user is not logged in
perpetual-pelican May 3, 2017
c027268
Only recent posts trigger notifications
markiragoldberg May 3, 2017
d606fb9
Merge pull request #95 from SIU-CS/master
akohli96 May 3, 2017
479908e
Update views.py
akohli96 May 3, 2017
f5f0102
Merge pull request #94 from SIU-CS/sprint3-mark
akohli96 May 3, 2017
00c1b61
adding comma
akohli96 May 3, 2017
9d661a5
Merge branch 'master' of https://github.com/SIU-CS/J-JAM-production i…
perpetual-pelican May 3, 2017
02aa7d4
Modified bot logic to use choices for message_type
perpetual-pelican May 4, 2017
5da7c49
Merge pull request #93 from SIU-CS/sprint3-james-test
akohli96 May 4, 2017
b7b5949
Merge pull request #96 from SIU-CS/sprint3-ayush
akohli96 May 4, 2017
00a25fa
Added some crucial links to the navbar!
markiragoldberg May 4, 2017
623d788
Adding necessary travis file
markiragoldberg May 4, 2017
a4addb4
try to fix travis
markiragoldberg May 4, 2017
5221ba1
why did we need version 0.0.0
markiragoldberg May 4, 2017
693c6c2
fix directories, see what this does
markiragoldberg May 4, 2017
0ea1c88
add encrypted environment variables
markiragoldberg May 4, 2017
598b4f0
twovars onecmd
markiragoldberg May 4, 2017
c6bdc5b
run the test not the server
markiragoldberg May 4, 2017
1e4f11b
new script
markiragoldberg May 4, 2017
ab6efda
again
markiragoldberg May 4, 2017
1ba2f9f
suspect the data was corrupted
markiragoldberg May 4, 2017
a08c0ec
having trouble encrypting the keys
markiragoldberg May 4, 2017
0cbcd90
Merge branch 'master' into sprint3-mark
markiragoldberg May 4, 2017
1f91e06
added some tests
markiragoldberg May 4, 2017
46abb84
test mhap
markiragoldberg May 4, 2017
c6aabff
oops!
markiragoldberg May 4, 2017
6f97822
test names
markiragoldberg May 4, 2017
3458f40
add name to settings page
markiragoldberg May 4, 2017
88f8090
fix tests
markiragoldberg May 4, 2017
e89510d
Merge pull request #97 from SIU-CS/sprint3-mark
akohli96 May 4, 2017
1ffa31e
Added tests and made login required for password change page
perpetual-pelican May 5, 2017
daa34d9
Took out fetch_quote test and added test for default process_message …
perpetual-pelican May 5, 2017
2881103
Merge pull request #98 from SIU-CS/sprint3-james-test
markiragoldberg May 5, 2017
611e021
Added travis status
akohli96 May 8, 2017
cdff30f
Update README.md
markiragoldberg May 8, 2017
4639799
informing user to add api keys to .bashrc
akohli96 May 9, 2017
99882d8
Adding full instructions
akohli96 May 10, 2017
0f5908c
Delete olddb
akohli96 May 11, 2017
3ec227f
Delete db.sqlite3_beforeSENT
akohli96 May 11, 2017
7417b4f
Delete db.sqlite3_backup2_after_james
akohli96 May 11, 2017
ba3f756
Delete db.sqlite3_backup
akohli96 May 11, 2017
2eaaf5c
Fix variable name
markiragoldberg May 11, 2017
eced44d
Fix travis env
markiragoldberg May 11, 2017
e072ced
Merge pull request #100 from SIU-CS/sprint3-mark
May 11, 2017
74d3de3
Fixing requirements and changing SECRET_KEY to SECRET
akohli96 May 11, 2017
991d30d
Fixed url so root redirects to index (mhap homepage)
perpetual-pelican May 12, 2017
d616021
Merge branch 'master' of https://github.com/SIU-CS/J-JAM-production i…
perpetual-pelican May 12, 2017
7a67a38
Merge pull request #101 from SIU-CS/sprint3-james-test
akohli96 May 12, 2017
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
language: python
python:
- '2.7'
install:
- pip install -r requirements.txt
script:
- python mhapsite/manage.py makemigrations
- python mhapsite/manage.py migrate
- python mhapsite/manage.py loaddata ./fixtures/quotes.json
- python mhapsite/manage.py test mhap
env:
matrix:
secure: FSvW3ISjHxHX4v4bP+BCDjn7NMSpL+6Z4D9fVDgUs1r8Griu1FzS9yxupyv8m2OBsveKk4wiTMMf9DS6K+JEBPU8jF/IY5YU2nwy0gVwggpV0VcfGUv4iZFVuMd93k05CgPrDHTlQULb2mnnqU3JYsKMIkHWaQGGs5SirTAz9MDK/1e2Ga0YcxNwivo+r0XDnDkmcAzV/1sOX20FfRXZBj4zqA6Mul2sZhErZbTX5cqqHbcCpdzfbW9eqzOAO+1CcmGVmyVLcY8XbbZgqyQp99MhW/6tZCYLYaWvbaw4QLp6lKzrfoNY3PTx6oeJeiGY6s95807GGnG49fnv3J7kd0A1vUKR7EapXUnMRzXzKtsGLjQrTqgv6QKM23Qyg/wgfV8zoY0oCAyvkmQQ1BX/Y+RLgjETWiVOoYUt6ZBSDaWMQxTAjQy4J9rE+qaZfqSxdScQnYfnVRlH3+hWhSgllIdnz3iNqV7nkJQQ3fi1VzE5WQms+qa1R+QRDW+joLIWGuj1LEOv2UZkuCaRsoYWF/57+GWdPeXEkV0GQLG3XLXJEa2hwfoFVs60bfKFqEshUoLmQ8M3HakCpiwG/0mzvdigkm5+Wdtgw70eFPJ7GBZdtD8FA4W9HJ8eABZzsjRfB9RJ4EwKbz9okomtJAdkFGKj8A1HhTenhDCNayqa6eQ=
15 changes: 12 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# J-JAM-production
An AI infused personal blogging web app for users to write about their mental health.

[![Build Status](https://travis-ci.org/SIU-CS/J-JAM-production.svg?branch=master)](https://travis-ci.org/SIU-CS/J-JAM-production)

## Members

Expand All @@ -21,22 +22,30 @@ [email protected]


# Get started
Use branch `master`

```bash
sudo apt-get install python-pip python-dev
sudo apt-get install python-virtualenv

#Create python environment
git clone https://github.com/SIU-CS/J-JAM-production.git
cd J-JAM-production
virtualenv djangofy

#Add the secret variable to .bashrc
export SECRET='key in mhapsite/secret.py'
#Make sure all the required api keys are in the .bashrc

#Activate it
source djangofy/bin/activate

pip install -r requirements

python manage.py runserver
python mhapsite/manage.py makemigrations
python mhapsite/manage.py migrate
python mhapsite/manage.py loaddata ./fixtures/quotes.json
python mhapsite/manage.py runserver


```

## Coding style
Expand Down
19 changes: 19 additions & 0 deletions fixtures/quotes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@

[
{
"model": "mhap.quote",
"pk": 1,
"fields": {
"quote": "All seasons are beautiful for the person who carries happiness within.",
"author": "Horace Friess"
}
},
{
"model": "mhap.quote",
"pk": 2,
"fields": {
"quote": "I begin with an idea and then it becomes something else.",
"author": "Pablo Picasso"
}
}
]
Binary file removed mhapsite/db.sqlite3
Binary file not shown.
Binary file removed mhapsite/db.sqlite3_backup
Binary file not shown.
Binary file removed mhapsite/db.sqlite3_backup2_after_james
Binary file not shown.
Binary file removed mhapsite/db.sqlite3_beforeSENT
Binary file not shown.
3 changes: 2 additions & 1 deletion mhapsite/mhap/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
# Register your models here.
from .models import Profile
from .models import Post
from .models import Quote
from .models import Quote,ChatMessages

admin.site.register(Profile)
admin.site.register(Post)
admin.site.register(Quote)
admin.site.register(ChatMessages)
57 changes: 57 additions & 0 deletions mhapsite/mhap/bot_helper.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import requests,json

from .models import Quote

#http://stackoverflow.com/questions/1859959/python-static-methods-how-to-call-a-method-from-another-method
#http://stackoverflow.com/questions/3434581/accessing-a-class-member-variables-in-python
#http://stackoverflow.com/questions/740287/how-to-check-if-one-of-the-following-items-is-in-a-list
class Bot(object):
'Bot Logic in a class'
help_patterns = ['help','please help me']

quote_patterns= ['quote','quotes','inspiration']

help_response=['https://www.adaa.org/tips-manage-anxiety-and-stress','http://tinybuddha.com/']


@staticmethod
def fetch_quote(API="http://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=json"):
try:
quote_json = requests.get(API).text
quote_json = quote_json.replace('\\x', '\\u00')
quote_json = json.loads(quote_json,strict=False)
return (str(quote_json['quoteText']), str(quote_json['quoteAuthor']))
except Exception as e:
print e

first_quote = Quote.objects.get(id=1)

return first_quote.quote,first_quote.author



@classmethod
def process_message(cls,user_message):

if type(user_message) is not str:
return "I only accept strings"

splitted_message = user_message.split(" ")
print splitted_message
if any(message in cls.quote_patterns for message in splitted_message):
return cls.fetch_quote()
#return "You want a quote :)"


elif any(message in cls.help_patterns for message in splitted_message):
return cls.help_response
else:
return "I am not a very intelligent bot. Please ask the MHAP team to upgrade me"




#print Bot.process_message("quote")


#print Bot.process_message("Cant interpret this")
8 changes: 8 additions & 0 deletions mhapsite/mhap/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ def __init__(self, user=None, *args, **kwargs):
print self.user, "IN INIT"
super(PasswordForm, self).__init__(*args, **kwargs)

class ChatForm(forms.Form):
"""
Extends forms.Form and is essentially a form for inputting chat messages
"""

chat = forms.CharField(label=("Input"))


class ProfileForm(forms.ModelForm):

class Meta:
Expand Down
49 changes: 49 additions & 0 deletions mhapsite/mhap/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2017-03-25 20:56
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

initial = True

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]

operations = [
migrations.CreateModel(
name='Post',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=120)),
('slug', models.SlugField(unique=True)),
('sentiment', models.FloatField(default=0.5)),
('content', models.TextField()),
('updated', models.DateTimeField(auto_now=True)),
('created', models.DateTimeField(auto_now_add=True)),
('secret', models.BooleanField(default=True)),
],
options={
'ordering': ['-created', '-updated'],
},
),
migrations.CreateModel(
name='Profile',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('email_confirmed', models.BooleanField(default=False)),
('birth_date', models.DateField(blank=True, null=True)),
('user', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
],
),
migrations.AddField(
model_name='post',
name='user_id',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='mhap.Profile'),
),
]
19 changes: 19 additions & 0 deletions mhapsite/mhap/migrations/0002_remove_post_sentiment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2017-04-02 18:28
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('mhap', '0001_initial'),
]

operations = [
migrations.RemoveField(
model_name='post',
name='sentiment',
),
]
28 changes: 28 additions & 0 deletions mhapsite/mhap/migrations/0003_auto_20170402_1906.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2017-04-02 19:06
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mhap', '0002_remove_post_sentiment'),
]

operations = [
migrations.CreateModel(
name='Quote',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('quote', models.CharField(max_length=120)),
('author', models.CharField(max_length=120)),
],
),
migrations.AddField(
model_name='post',
name='sentiment',
field=models.FloatField(default=0.5),
),
]
18 changes: 18 additions & 0 deletions mhapsite/mhap/migrations/0004_delete_quote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2017-04-02 19:34
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('mhap', '0003_auto_20170402_1906'),
]

operations = [
migrations.DeleteModel(
name='Quote',
),
]
23 changes: 23 additions & 0 deletions mhapsite/mhap/migrations/0005_quote.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2017-04-02 19:37
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mhap', '0004_delete_quote'),
]

operations = [
migrations.CreateModel(
name='Quote',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('quote', models.CharField(max_length=120)),
('author', models.CharField(max_length=120)),
],
),
]
25 changes: 25 additions & 0 deletions mhapsite/mhap/migrations/0006_auto_20170409_1857.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.10 on 2017-04-09 18:57
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('mhap', '0005_quote'),
]

operations = [
migrations.AddField(
model_name='post',
name='seems_depressed',
field=models.BooleanField(default=False),
),
migrations.AddField(
model_name='post',
name='seems_suicidal',
field=models.BooleanField(default=False),
),
]
Empty file.
28 changes: 26 additions & 2 deletions mhapsite/mhap/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ def get_absolute_url(self):
def get_list_url(self):
return reverse("mhap:list")

#http://stackoverflow.com/questions/1737017/django-auto-now-and-auto-now-add
class ChatMessages(models.Model):
message = models.CharField(max_length=255)
RESOURCE = "r"
DEFAULT = "d"
choices = ((RESOURCE, "resource"),
(DEFAULT, "default"))
message_type = models.CharField(max_length=1, choices=choices, default=DEFAULT)
user_id = models.ForeignKey(Profile)
is_user = models.BooleanField(default=True)
time_stamp = models.DateTimeField(default=None, editable=False,null=True)

def save(self, *args, **kwargs):
if not self.id:
self.created = timezone.now()
return super(ChatMessages,self).save(*args,**kwargs)

def __str__(self):
return str(self.user_id) + " " + str(self.message) + str(self.is_user)


class Quote(models.Model):
quote = models.CharField(max_length=120)
Expand Down Expand Up @@ -117,7 +137,7 @@ def evaluate_sentiment(instance):
"text": str(instance.title) + ". " + str(instance.content)
}
]
};
}

try:
header = {
Expand All @@ -141,7 +161,11 @@ def contains_patterns(instance, patterns):
def pre_save_post_receiver(sender, instance, *args, **kwargs):
instance.slug = create_slug(instance)
instance.sentiment = evaluate_sentiment(instance)
instance.seems_depressed = contains_patterns(instance, depression_patterns)
instance.seems_suicidal = contains_patterns(instance, suicide_patterns)
if instance.seems_suicidal:
# Suicide makes depression warnings redundant
instance.seems_depressed = False
else:
instance.seems_depressed = contains_patterns(instance, depression_patterns)

pre_save.connect(pre_save_post_receiver, sender=Post)
Loading