Exemple #1
0
def renew_subscriptions(force=False, verbose=False):
    subscriptions = Pshb.objects.all().order_by('id')
    for s in subscriptions:
        if s.expire:
            d = s.expire - timedelta(days=7)
            if now() > d or force:
                subscribe(s.service, verbose)
Exemple #2
0
    def run(self):
        if not facebook:
            print("ImportError: facebook. Install Facebook's python-sdk.")
            return

        try:
            args = {}
            if not self.service.last_checked:
                args['limit'] = 250

            graph = facebook.GraphAPI(self.service.creds)
            if not self.service.url:
                self.stream = graph.get_connections('me', 'home', **args)
            else:
                self.stream = graph.get_connections(self.service.url, 'feed',
                                                    **args)
            self.service.last_checked = now()
            self.service.save()
            self.process()
        except Exception as e:
            if self.verbose:
                import sys
                import traceback
                print('%s (%d) Exception: %s' %
                      (self.service.api, self.service.id, e))
                traceback.print_exc(file=sys.stdout)
Exemple #3
0
def renew_subscriptions(force=False, verbose=False):
    subscriptions = Pshb.objects.all().order_by('id')
    for s in subscriptions:
        if s.expire:
            d = s.expire - timedelta(days=7)
            if now() > d or force:
                subscribe(s.service, verbose)
Exemple #4
0
    def run(self):
        if not facebook:
            print("ImportError: facebook. Install Facebook's python-sdk.")
            return

        try:
            args = {}
            if not self.service.last_checked:
                args['limit'] = 250

            graph = facebook.GraphAPI(self.service.creds)
            if not self.service.url:
                self.stream = graph.get_connections('me', 'home', **args)
            else:
                self.stream = graph.get_connections(self.service.url, 'feed',
                                                    **args)
            self.service.last_checked = now()
            self.service.save()
            self.process()
        except Exception as e:
            if self.verbose:
                import sys
                import traceback
                print('%s (%d) Exception: %s' % (self.service.api,
                                                 self.service.id, e))
                traceback.print_exc(file=sys.stdout)
Exemple #5
0
    def fetch(self, url):
        self.fp_error = False
        if not self.payload:
            try:
                hs = httpclient.gen_auth(self.service, url)
                r = httpclient.get(url, auth=hs)
                alturl = httpclient.get_alturl_if_html(r)
                if alturl:
                    r = httpclient.get(alturl, auth=hs)
                self.fp = feedparser.parse(r.text)
                self.fp.etag = r.headers.get('etag')
                self.fp.modified = r.headers.get('last-modified')
            except (IOError, httpclient.HTTPError) as e:
                self.fp_error = True
                if self.verbose:
                    error = e.message if hasattr(e, 'message') else ''
                    print('%s (%d) HTTPError: %s' % (self.service.api,
                                                     self.service.id,
                                                     error))
                return
        else:
            self.fp = feedparser.parse(self.payload)

        if hasattr(self.fp, 'bozo') and self.fp.bozo:
            self.fp_error = True
            if isinstance(self.fp.bozo_exception,
                          feedparser.CharacterEncodingOverride):
                self.fp_error = False
            if self.verbose:
                print('%s (%d) Bozo: %s' % (self.service.api,
                                            self.service.id, self.fp))

        if not self.fp_error:
            self.service.etag = self.fp.get('etag', '')
            if self.service.etag is None:
                self.service.etag = ''
            try:
                self.service.last_modified = mtime(self.fp.modified)
            except:
                pass
            self.service.last_checked = now()
            if not self.service.link:
                self.service.link = self.fp.feed.get('link', '')
            self.service.save()
            if not self.fetch_only:
                self.process()
Exemple #6
0
    def fetch(self, url):
        self.fp_error = False
        if not self.payload:
            try:
                hs = httpclient.gen_auth(self.service, url)
                r = httpclient.get(url, auth=hs)
                alturl = httpclient.get_alturl_if_html(r)
                if alturl:
                    r = httpclient.get(alturl, auth=hs)
                self.fp = feedparser.parse(r.text)
                self.fp.etag = r.etag
                self.fp.modified = r.modified
            except (IOError, httpclient.HTTPError) as e:
                self.fp_error = True
                if self.verbose:
                    error = e.message if hasattr(e, 'message') else ''
                    print('%s (%d) HTTPError: %s' %
                          (self.service.api, self.service.id, error))
                return
        else:
            self.fp = feedparser.parse(self.payload)

        if hasattr(self.fp, 'bozo') and self.fp.bozo:
            self.fp_error = True
            if isinstance(self.fp.bozo_exception,
                          feedparser.CharacterEncodingOverride):
                self.fp_error = False
            if self.verbose:
                print('%s (%d) Bozo: %s' %
                      (self.service.api, self.service.id, self.fp))

        if not self.fp_error:
            self.service.etag = self.fp.get('etag', '')
            if self.service.etag is None:
                self.service.etag = ''
            try:
                self.service.last_modified = mtime(self.fp.modified)
            except:
                pass
            self.service.last_checked = now()
            if not self.service.link:
                self.service.link = self.fp.feed.get('link', '')
            self.service.save()
            if not self.fetch_only:
                self.process()
Exemple #7
0
 def fetch(self, url):
     try:
         r = httpclient.get('https://vimeo.com' + url)
         if r.status_code == 200:
             self.json = r.json()
             self.service.last_checked = now()
             self.service.save()
             self.process()
         elif self.verbose:
             print('%s (%d) HTTP: %s' % (self.service.api,
                                         self.service.id, r.reason))
     except Exception as e:
         if self.verbose:
             import sys
             import traceback
             print('%s (%d) Exception: %s' % (self.service.api,
                                              self.service.id, e))
             traceback.print_exc(file=sys.stdout)
Exemple #8
0
 def fetch(self, url):
     try:
         r = httpclient.get('https://vimeo.com' + url)
         if r.status_code == 200:
             self.json = r.json()
             self.service.last_checked = now()
             self.service.save()
             self.process()
         elif self.verbose:
             print('%s (%d) HTTP: %s' %
                   (self.service.api, self.service.id, r.reason))
     except Exception as e:
         if self.verbose:
             import sys
             import traceback
             print('%s (%d) Exception: %s' %
                   (self.service.api, self.service.id, e))
             traceback.print_exc(file=sys.stdout)
Exemple #9
0
 def fetch(self, url):
     try:
         oauth = gls_oauth.OAuth1Client(self.service)
         r = oauth.consumer.get('https://api.twitter.com' + url)
         if r.status_code == 200:
             self.json = r.json()
             self.service.last_checked = now()
             self.service.save()
             self.process()
         elif self.verbose:
             print('%s (%d) HTTP: %s' % (self.service.api,
                                         self.service.id, r.reason))
     except Exception as e:
         if self.verbose:
             import sys
             import traceback
             print('%s (%d) Exception: %s' % (self.service.api,
                                              self.service.id, e))
             traceback.print_exc(file=sys.stdout)
Exemple #10
0
 def fetch(self, url):
     try:
         oauth = gls_oauth.OAuth1Client(self.service)
         r = oauth.consumer.get('http://friendfeed-api.com' + url)
         if r.status_code == 200:
             self.json = r.json()
             self.service.last_checked = now()
             self.service.save()
             self.process()
         elif self.verbose:
             print('%s (%d) HTTP: %s' %
                   (self.service.api, self.service.id, r.reason))
     except Exception as e:
         if self.verbose:
             import sys
             import traceback
             print('%s (%d) Exception: %s' %
                   (self.service.api, self.service.id, e))
             traceback.print_exc(file=sys.stdout)
Exemple #11
0
def verify(id, GET):
    mode = GET.get('hub.mode', None)
    lease_seconds = GET.get('hub.lease_seconds', None)

    if mode == 'subscribe':
        try:
            db = Pshb.objects.get(hash=id)
            db.verified = True
            if lease_seconds:
                db.expire = now() + timedelta(seconds=int(lease_seconds))
            db.save()
        except Pshb.DoesNotExist:
            return False
    elif mode == 'unsubscribe':
        try:
            Pshb.objects.get(hash=id).delete()
        except Pshb.DoesNotExist:
            return False

    return GET.get('hub.challenge', '')
Exemple #12
0
def verify(id, GET):
    mode = GET.get('hub.mode', None)
    lease_seconds = GET.get('hub.lease_seconds', None)

    if mode == 'subscribe':
        try:
            db = Pshb.objects.get(hash=id)
            db.verified = True
            if lease_seconds:
                db.expire = now() + timedelta(seconds=int(lease_seconds))
            db.save()
        except Pshb.DoesNotExist:
            return False
    elif mode == 'unsubscribe':
        try:
            Pshb.objects.get(hash=id).delete()
        except Pshb.DoesNotExist:
            return False

    return GET.get('hub.challenge', '')