コード例 #1
0
    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
コード例 #2
0
ファイル: views.py プロジェクト: rei901/realize-core
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.")
コード例 #3
0
ファイル: models.py プロジェクト: realizeapp/realize-core
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()
コード例 #4
0
ファイル: models.py プロジェクト: realizeapp/realize-core
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()
コード例 #5
0
ファイル: views.py プロジェクト: rei901/realize-core
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.")
コード例 #6
0
ファイル: models.py プロジェクト: realizeapp/realize-core
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()
コード例 #7
0
ファイル: tasks.py プロジェクト: rei901/realize-core
    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
コード例 #8
0
ファイル: models.py プロジェクト: rei901/realize-core
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
コード例 #9
0
ファイル: tasks.py プロジェクト: rei901/realize-core
    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
コード例 #10
0
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()
コード例 #11
0
ファイル: models.py プロジェクト: rei901/realize-core
class WeightModel(BaseFitbitModel):
    metric_proxy = MetricProxy(name="weight")
コード例 #12
0
ファイル: models.py プロジェクト: rei901/realize-core
class MinutesAsleepModel(BaseFitbitModel):
    metric_proxy = MetricProxy(name="minutes_asleep")
コード例 #13
0
ファイル: models.py プロジェクト: rei901/realize-core
class TimeInBedModel(BaseFitbitModel):
    metric_proxy = MetricProxy(name="time_in_bed")
コード例 #14
0
ファイル: models.py プロジェクト: rei901/realize-core
class DistanceModel(BaseFitbitModel):
    metric_proxy = MetricProxy(name="distance")
コード例 #15
0
ファイル: models.py プロジェクト: rei901/realize-core
class StepModel(BaseFitbitModel):
    metric_proxy = MetricProxy(name="steps")
コード例 #16
0
ファイル: models.py プロジェクト: rei901/realize-core
class WaterModel(BaseFitbitModel):
    metric_proxy = MetricProxy(name="water")
コード例 #17
0
ファイル: models.py プロジェクト: rei901/realize-core
class SleepStartTimeModel(BaseFitbitModel):
    metric_proxy = MetricProxy(name="sleep_start_time")
    value = DateTimeField()
コード例 #18
0
ファイル: models.py プロジェクト: rei901/realize-core
class SleepEfficiencyModel(BaseFitbitModel):
    metric_proxy = MetricProxy(name="sleep_efficiency")
コード例 #19
0
ファイル: models.py プロジェクト: rei901/realize-core
class ActivityCaloriesModel(BaseFitbitModel):
    metric_proxy = MetricProxy(name="activity_calories")
コード例 #20
0
class TestLoosePermissions(PluginDataModel):
    metric_proxy = MetricProxy(name="test2")
    source_proxy = SourceProxy(name="test2")
    perms = [Scope(ZonePerm("user", all=True), BlockPerm("plugin", all=True))]
コード例 #21
0
ファイル: models.py プロジェクト: rei901/realize-core
class CaloriesModel(BaseFitbitModel):
    metric_proxy = MetricProxy(name="calories")
コード例 #22
0
class TestModel(PluginDataModel):
    metric_proxy = MetricProxy(name="test1")
    source_proxy = SourceProxy(name='test1')

    number = IntegerField()
コード例 #23
0
ファイル: models.py プロジェクト: rei901/realize-core
class BaseFitbitModel(PluginDataModel):
    metric_proxy = MetricProxy(name="newsfeed")
    source_proxy = SourceProxy(name="fitbit")

    date = DateTimeField()
    value = FloatField()
コード例 #24
0
class SettingsModel(PluginDataModel):
    metric_proxy = MetricProxy(name="settings")
    source_proxy = SourceProxy(name="self")
    name = Field()