diff --git a/capuchin/workers/client/posts.py b/capuchin/workers/client/posts.py index 82457a5..c944a32 100644 --- a/capuchin/workers/client/posts.py +++ b/capuchin/workers/client/posts.py @@ -1,19 +1,16 @@ -from capuchin.app import Capuchin from capuchin import config from capuchin import db from capuchin.views.insights import POST_INSIGHTS from capuchin.workers.client.insights import Insights from flask_oauth import OAuth -import urlparse import logging import time -import requests import datetime -from pprint import pprint -from slugify import slugify + date_format = "%Y-%m-%dT%H:%M:%S+0000" + class ClientPosts(): def __init__(self, client, since): @@ -47,7 +44,6 @@ def get_count(self, url): logging.warn(e) return None - def write_data(self, post): p_id = post.get("id") post['client'] = str(self.client._id) @@ -63,7 +59,7 @@ def write_data(self, post): for i in POST_INSIGHTS: url = "{}.{}".format(p_id, i) count = self.get_count(url) - points = [(time.time(), 0, i)] if count == None else [] + points = [(time.time(), 0, i)] if count is None else [] data = post.get(i) for d in data[count:]: ct = d.get("created_time") @@ -87,6 +83,11 @@ def get_feed(self): data=data, ) for p in res.data.get('data'): + # Ignore posts made *to* page (rather than *from*) page + # TODO: Record these separately and report on them somehow? + if p.get('from', {}).get('id') != str(self.page_id): + continue + p_id = p.get("id") for i in POST_INSIGHTS: p[i] = self.page(p_id, i, p.get(i, {})) @@ -115,16 +116,14 @@ def page(self, post_id, typ, data): return res def write_influx(self, points, url): - data = [ - dict( - name = "insights.{}.post.{}".format(self.client._id, url), - columns = ["time", "value", "type"], - points = points - ) - ] + data = [{ + 'name': "insights.{}.post.{}".format(self.client._id, url), + 'columns': ['time', 'value', 'type'], + 'points': points, + }] logging.info("Writing: {}".format(data)) try: res = self.INFLUX.write_points(data) logging.info(res) except Exception as e: - logging.warning(e) + logging.warning(e, exc_info=True)