Skip to content

Commit

Permalink
added simple end point for downloading sentiment data as json
Browse files Browse the repository at this point in the history
  • Loading branch information
LanceMaverick committed Feb 5, 2017
1 parent 63c7c8c commit cdec011
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
26 changes: 26 additions & 0 deletions beards/sentiment/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import telepot.aio
from skybeard.beards import BeardChatHandler
from skybeard.predicates import Filters
from skybeard.server import web
from skybeard.api.database import is_key_match
from . import sentiment as sent
from . import config

Expand All @@ -19,6 +21,8 @@ class SentBeard(BeardChatHandler):
__userhelp__ = """
Logging for sentiment analysis.
"""
__routes__ = [('/sentData', 'http_get_sents', 'post'),]

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)

Expand Down Expand Up @@ -68,4 +72,26 @@ async def instant_report(self, msg):
str(score))
await self.sender.sendMessage(reply, parse_mode = 'markdown')


async def http_get_sents(request):
data = await request.json()
if not is_key_match(data['key']):
return web.json_response({'status': 'ERROR: Not authenticated'})
elif 'chat_id' not in data:
return web.json_response({'status': 'No chat id specified'})
else:

data.pop('key')
sent_data = sent.get_raw_data(**data)
response = dict(chat_id = data['chat_id'], results = [row for row in sent_data])
return web.json_response(response)










5 changes: 5 additions & 0 deletions beards/sentiment/sentiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,5 +167,10 @@ def get_user_results(msg, neut = True):
return plot


def get_raw_data(**kwargs):
with dataset.connect(config.db_path) as db:
table = db['message_log']
return table.find(**kwargs)



0 comments on commit cdec011

Please sign in to comment.