def create_bundle(self, metric_name, source_name, plugin, cls): if issubclass(cls, PluginDataModel): factory = PluginDataFactory else: raise Exception("Invalid class type for factory.") metric = MetricFactory(name=metric_name) source = SourceFactory(name=source_name) model = PluginModelFactory() cls_args = dict(metric=metric, source=source, plugin=plugin, plugin_model=model) inst = factory(**cls_args) cls_args.update({ 'source_proxy': SourceProxy(name=source.name), 'metric_proxy': MetricProxy(name=metric.name), 'plugin_proxy': PluginProxy(name=plugin.name, hashkey=plugin.hashkey), 'plugin_model_proxy': PluginModelProxy(metric_id=metric.name, plugin_id=plugin.hashkey, hashkey=model.hashkey, name=model.__class__.__name__), 'inst': inst }) return cls_args
class SurveyForm(FormView): name = "survey" description = "Please enter some long information about your mood." model = DataModel metric_proxy = MetricProxy(name="data") source_proxy = SourceProxy(name="self") text = TextField(description="Enter the mood you are feeling.") number = IntegerField(description="Number on a 1-10 scale.")
class MoodModel(PluginDataModel): metric_proxy = MetricProxy(name="mood") source_proxy = SourceProxy(name="self") perms = [ Scope(ZonePerm("user", current=True), BlockPerm("plugin", current=True)) ] score = IntegerField()
class SettingsModel(PluginDataModel): metric_proxy = MetricProxy(name="settings") source_proxy = SourceProxy(name="self") perms = [ Scope(ZonePerm("user", current=True), BlockPerm("plugin", current=True)) ] your_name = Field()
class MoodForm(FormView): name = "mood" description = "Please enter some information about your mood." model = MoodModel metric_proxy = MetricProxy(name="mood") source_proxy = SourceProxy(name="self") score = IntegerField('Mood', [required()], description="Number on a 1-10 scale.")
class DataModel(PluginDataModel): metric_proxy = MetricProxy(name="data") source_proxy = SourceProxy(name="self") perms = [ Scope(ZonePerm("user", current=True), BlockPerm("plugin", current=True)) ] number = Field() text = Field()
def run(self): last_m = self.manager.query_last(manifest.plugin_proxy, MetricProxy(name="checkins")) if last_m is None: last_time = datetime.now().replace(tzinfo=pytz.utc) - timedelta( days=365) else: last_time = last_m.date.replace(tzinfo=pytz.utc) timestamp = calendar.timegm(last_time.timetuple()) foursquare = self.auth_manager.get_auth("foursquare") token = foursquare.token token = token.replace("Bearer ", "") print(token) version = datetime.now().strftime("%Y%m%d") response = foursquare.get( "https://api.foursquare.com/v2/users/self/checkins?afterTimestamp={0}&oauth_token={1}&v={2}" .format(timestamp, token, version)).json() checkins = response['response']['checkins']['items'] for c in checkins: if 'venue' in c: venue = c['venue']['name'] location = c['venue']['location'] latitude = location['lat'] longitude = location['lng'] visit_count = c['venue']['beenHere']['count'] else: continue type = c['type'] source = c['source']['name'] created = c['createdAt'] offset = c['timeZoneOffset'] dt = datetime.fromtimestamp(created).replace( tzinfo=tz.tzoffset(None, offset)) obj = Checkins(type=type, source=source, venue=venue, latitude=latitude, longitude=longitude, location=location, visit_count=visit_count, date=dt) try: self.manager.add(obj) except DuplicateRecord: pass
class Checkins(PluginDataModel): metric_proxy = MetricProxy(name="checkins") source_proxy = SourceProxy(name="foursquare") perms = [Scope(ZonePerm("user", current=True), BlockPerm("plugin", all=True))] type = Field() source = Field() venue = Field() location = DictField() latitude = Field() longitude = Field() visit_count = FloatField() date = DateTimeField
def run(self): last_m = self.manager.query_last(manifest.plugin_proxy, MetricProxy(name="newsfeed")) if last_m is None: last_time = datetime.now() - timedelta(days=365) else: last_time = last_m last_stamp = timegm(last_time.utctimetuple()) url = "https://graph.facebook.com/me?fields=posts.since({0})".format( last_time.isoformat()) facebook = self.auth_manager.get_auth("facebook") data = self.get_data(facebook, url) streams = [] next_page = True until_under = False while next_page: pages = data.get('paging', None) stream = data.get('data', None) if stream is None: break streams += stream if pages is None: next_page = False else: url = pages['next'] until = int(parse_qs(urlparse(url).query)['until'][0]) if until < last_stamp: if not until_under: until_under = True else: next_page = False data = self.get_data(facebook, url) if len(data['data']) < 0: next_page = False for s in streams: try: self.handle_stream_object(s) except KeyError: continue
class NewsFeed(PluginDataModel): metric_proxy = MetricProxy(name="newsfeed") source_proxy = SourceProxy(name="facebook") perms = [ Scope(ZonePerm("user", current=True), BlockPerm("plugin", all=True)) ] date = DateTimeField() update_time = DateTimeField() from_id = Field() from_name = Field() story = Field() type = Field() likes = ListField() comments = ListField() message = Field() name = Field() shares = IntegerField() picture = Field()
class WeightModel(BaseFitbitModel): metric_proxy = MetricProxy(name="weight")
class MinutesAsleepModel(BaseFitbitModel): metric_proxy = MetricProxy(name="minutes_asleep")
class TimeInBedModel(BaseFitbitModel): metric_proxy = MetricProxy(name="time_in_bed")
class DistanceModel(BaseFitbitModel): metric_proxy = MetricProxy(name="distance")
class StepModel(BaseFitbitModel): metric_proxy = MetricProxy(name="steps")
class WaterModel(BaseFitbitModel): metric_proxy = MetricProxy(name="water")
class SleepStartTimeModel(BaseFitbitModel): metric_proxy = MetricProxy(name="sleep_start_time") value = DateTimeField()
class SleepEfficiencyModel(BaseFitbitModel): metric_proxy = MetricProxy(name="sleep_efficiency")
class ActivityCaloriesModel(BaseFitbitModel): metric_proxy = MetricProxy(name="activity_calories")
class TestLoosePermissions(PluginDataModel): metric_proxy = MetricProxy(name="test2") source_proxy = SourceProxy(name="test2") perms = [Scope(ZonePerm("user", all=True), BlockPerm("plugin", all=True))]
class CaloriesModel(BaseFitbitModel): metric_proxy = MetricProxy(name="calories")
class TestModel(PluginDataModel): metric_proxy = MetricProxy(name="test1") source_proxy = SourceProxy(name='test1') number = IntegerField()
class BaseFitbitModel(PluginDataModel): metric_proxy = MetricProxy(name="newsfeed") source_proxy = SourceProxy(name="fitbit") date = DateTimeField() value = FloatField()
class SettingsModel(PluginDataModel): metric_proxy = MetricProxy(name="settings") source_proxy = SourceProxy(name="self") name = Field()