def reshare(self, entry, args={}): sid = args.get('sid', None) as_me = int(args.get('as_me', False)) user = args.get('user', None) un = utcnow() guid = '%s/entry/%s' % (settings.FEED_TAGURI, un.strftime('%Y-%m-%dT%H:%M:%SZ')) if sid: s = Service.objects.get(id=sid, api='selfposts') else: s = Service.objects.filter(api='selfposts').order_by('id')[0] e = Entry(service=s, guid=guid) e.date_published = un e.date_updated = un if as_me: if user and user.first_name and user.last_name: e.author_name = user.first_name + ' ' + user.last_name else: e.author_name = '' e.author_email = '' e.author_uri = '' if entry.service.api == 'greader': e.link = entry.link else: e.link = settings.BASE_URL + '/' if entry.service.api == 'twitter': entry.content = entry.content.split(': ', 1)[1] else: e.author_name = entry.author_name e.author_email = entry.author_email e.author_uri = entry.author_uri e.link = entry.link e.geolat = entry.geolat e.geolng = entry.geolng e.mblob = entry.mblob e.title = entry.title if entry.service.api == 'greader': e.content = '<a href="%s" rel="nofollow">%s</a>' % ( e.link, e.title) elif entry.service.api in ('youtube', 'vimeo'): e.content = '<p>%s</p>%s' % (df_title(e.title), entry.content) else: e.content = urlizetrunc(entry.content, 45) try: media.transform_to_local(e) media.extract_and_register(e) e.save() return e except: pass
def reshare(self, entry, args={}): sid = args.get('sid', None) as_me = int(args.get('as_me', False)) user = args.get('user', None) un = utcnow() guid = '%s/entry/%s' % (settings.FEED_TAGURI, un.strftime('%Y-%m-%dT%H:%M:%SZ')) if sid: s = Service.objects.get(id=sid, api='selfposts') else: s = Service.objects.filter(api='selfposts').order_by('id')[0] e = Entry(service=s, guid=guid) e.date_published = un e.date_updated = un if as_me: if user and user.first_name and user.last_name: e.author_name = user.first_name + ' ' + user.last_name else: e.author_name = '' e.author_email = '' e.author_uri = '' if entry.service.api == 'greader': e.link = entry.link else: e.link = settings.BASE_URL + '/' if entry.service.api == 'twitter': entry.content = entry.content.split(': ', 1)[1] else: e.author_name = entry.author_name e.author_email = entry.author_email e.author_uri = entry.author_uri e.link = entry.link e.geolat = entry.geolat e.geolng = entry.geolng e.mblob = entry.mblob e.title = entry.title if entry.service.api == 'greader': e.content = '<a href="%s" rel="nofollow">%s</a>' % (e.link, e.title) elif entry.service.api in ('youtube', 'vimeo'): e.content = '<p>%s</p>%s' % (df_title(e.title), entry.content) else: e.content = urlizetrunc(entry.content, 45) try: media.transform_to_local(e) media.extract_and_register(e) e.save() return e except: pass
def process(self): for ent in self.fp.entries: guid = ent.id if 'id' in ent else ent.link if self.verbose: print('ID: %s' % guid) try: e = Entry.objects.get(service=self.service, guid=guid) if not self.force_overwrite and 'updated_parsed' in ent: if e.date_updated and \ mtime(ent.updated_parsed) <= e.date_updated: continue if e.protected: continue except Entry.DoesNotExist: e = Entry(service=self.service, guid=guid) e.title = ent.title e.link = ent.get('feedburner_origlink', ent.get('link', '')) if 'author_detail' in ent: e.author_name = ent.author_detail.get('name', '') e.author_email = ent.author_detail.get('email', '') e.author_uri = ent.author_detail.get('href', '') else: e.author_name = ent.get('author', ent.get('creator', '')) if not e.author_name and 'author_detail' in self.fp.feed: e.author_name = self.fp.feed.author_detail.get('name', '') e.author_email = self.fp.feed.author_detail.get( 'email', '') e.author_uri = self.fp.feed.author_detail.get('href', '') try: e.content = ent.content[0].value except: e.content = ent.get('summary', ent.get('description', '')) if 'published_parsed' in ent: e.date_published = mtime(ent.published_parsed) elif 'updated_parsed' in ent: e.date_published = mtime(ent.updated_parsed) if 'updated_parsed' in ent: e.date_updated = mtime(ent.updated_parsed) if 'geo_lat' in ent and 'geo_long' in ent: e.geolat = ent.geo_lat e.geolng = ent.geo_long elif 'georss_point' in ent: geo = ent['georss_point'].split(' ') e.geolat = geo[0] e.geolng = geo[1] if 'image' in self.fp.feed: e.link_image = media.save_image(self.fp.feed.image.url) else: for link in ent.links: if link.rel == 'image' or link.rel == 'photo': e.link_image = media.save_image(link.href) if hasattr(self, 'custom_process'): self.custom_process(e, ent) if hasattr(e, 'custom_mblob'): e.mblob = e.custom_mblob else: e.mblob = None mblob = media.mrss_init(e.mblob) if 'media_content' in ent: mblob['content'].append(ent.media_content) e.mblob = media.mrss_gen_json(mblob) e.content = strip_script(e.content) try: e.save() media.extract_and_register(e) except: pass