Skip to content
Open
Changes from all commits
Commits
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
29 changes: 14 additions & 15 deletions capuchin/workers/client/posts.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)
Expand All @@ -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")
Expand All @@ -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, {}))
Expand Down Expand Up @@ -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)