def ping_links(instance, **kwargs): from turbion.bits.pingback.models import Pingback from turbion.bits.pingback import utils domain = Site.objects.get_current().domain local_url = 'http://%s%s' % (domain, instance.get_absolute_url()) for target_url in utils.parse_html_links(instance.text_html, domain): try: pingback = Pingback.objects.get( target_url=target_url, source_url=local_url, post=None, incoming=False ) if pingback.finished: # do nothing if we just have pinged this url # from this instance of model continue except Pingback.DoesNotExist: pingback = Pingback( target_url=target_url, source_url=local_url, post=None, incoming=False ) try: gateway = get_rpc_gateway(target_url) except Exception, e: logger.warning(str(e)) continue if not gateway: continue try: server = ServerProxy(gateway) status = server.pingback.ping(local_url, target_url) except Exception, e: logger.warning(str(e)) continue
def send(self): try: domain = Site.objects.get_current().domain from_email = settings.TURBION_NOTIFICATION_FROM_EMAIL % {'domain': domain} msg = EmailMessage( self.subject, self.body, from_email, [self.email] ) if self.content_type: msg.content_subtype = self.content_type msg.send() return True except Exception, e: logger.warning(str(e)) self.attempt += 1 self.save() return False
except (urllib2.HTTPError, urllib2.URLError, socket.timeout), e: return 16 parser = utils.SourceParser(doc) paragraph = parser.get_paragraph(target_uri) if paragraph is None: return 17 pingback = Pingback.objects.create( source_url=source_uri, target_url=target_uri, incoming=True, title=parser.get_title(), paragraph=paragraph, status='Pingback from %s to %s registered. Keep the web talking! :-)' % (source_uri, target_uri), post=post, finished=True ) signals.pingback_recieved.send( sender=post.__class__, instance=post, pingback=pingback ) return pingback.status except Exception, e: logger.warning(str(e)) return 0