示例#1
0
    def run(self, user_id):
        self.user = User.get_by_id(user_id)
        if not self.user.verify_user():
            # not really much we can do about this...
            log.info("Missing tokens for user %r", self.user)
            self.set_status(0, 0, "You need to log out and log back in again.")
            return
        self.fk = flickr.FlickrAPI(self.user.flickr_token)
        self.fb_user = fb.GraphUser(access_token=self.user.fb_access_token)
        photosets = self.fk.photosets_getList()[0]

        self.synced_photos = 0
        self.total_photos = sum(int(pset.get("photos")) for pset in photosets)

        self.set_status(self.synced_photos, self.total_photos, "syncing Flickr photos to Facebook")

        settings = UserSetting.multiget(
            user_id=user_id, settings=[UserSettingConst.FB_PRIVACY, UserSettingConst.FLICKR_SET_SYNCING]
        )
        self.fb_privacy = settings.get(UserSettingConst.FB_PRIVACY, "FB_DEFAULT")
        self.flickr_settings = settings.get(UserSettingConst.FLICKR_SET_SYNCING, {})

        select_sets = self.flickr_settings.get("select_sets", False)
        selected_sets = self.flickr_settings.get("selected_sets", [])
        for photoset in photosets:
            if not select_sets or photoset.get("id") in selected_sets:
                self.sync_photoset(photoset)

        log.info("Finished job %r for user %r", self.job.jid, self.user.id)
        # once we are all done, let's submit the task to rerun in an hour.
        self.resubmit(delay=60 * 60)
示例#2
0
    def run(self, user_id):
        self.user = User.get_by_id(user_id)
        if not self.user.verify_user():
            # not really much we can do about this...
            log.info("Missing tokens for user %r", self.user)
            self.set_status(0, 0, "You need to log out and log back in again.")
            return
        self.fk = flickr.FlickrAPI(self.user.flickr_token)
        self.fb_user = fb.GraphUser(access_token=self.user.fb_access_token)
        photosets = self.fk.photosets_getList()[0]

        self.synced_photos = 0
        self.total_photos = sum(int(pset.get('photos')) for pset in photosets)

        self.set_status(
            self.synced_photos,
            self.total_photos,
            "syncing Flickr photos to Facebook")

        settings = UserSetting.multiget(
            user_id=user_id,
            settings=[UserSettingConst.FB_PRIVACY,
                      UserSettingConst.FLICKR_SET_SYNCING])
        self.fb_privacy = settings.get(UserSettingConst.FB_PRIVACY, 'FB_DEFAULT')
        self.flickr_settings = settings.get(UserSettingConst.FLICKR_SET_SYNCING, {})

        select_sets = self.flickr_settings.get('select_sets', False)
        selected_sets = self.flickr_settings.get('selected_sets', [])
        for photoset in photosets:
            if not select_sets or photoset.get('id') in selected_sets:
                self.sync_photoset(photoset)

        log.info("Finished job %r for user %r", self.job.jid, self.user.id)
        # once we are all done, let's submit the task to rerun in an hour.
        self.resubmit(delay=60*60)
示例#3
0
 def settings(self):
     return UserSetting.multiget(
         settings=[UserSettingConst.FB_PRIVACY,
                   UserSettingConst.FLICKR_SET_SYNCING])
示例#4
0
 def settings(self):
     return UserSetting.multiget(settings=[
         UserSettingConst.FB_PRIVACY, UserSettingConst.FLICKR_SET_SYNCING
     ])