示例#1
0
 def get(self):
     target,targetdomain= geturlanddomain(self.request.get('target'))
     unverified = self.request.get('unverified','off') == 'on'
     jsonformat = self.request.get('json','off') == 'on'
     targetkey = ndb.Key('Domain', targetdomain)
     
     logging.info("ListMentions target:%s targetdomain %s unverified %s json %s" % (target,targetdomain,unverified,json))
     if unverified:
         mentionquery = Mention.query(ancestor = targetkey).order(-Mention.updated)
     else:
         mentionquery = Mention.query(ancestor = targetkey).filter(Mention.verified==True).order(-Mention.updated)
     rawmentions = mentionquery.fetch(100)
     mentions=[]
     logging.info("listmentions got %s mentions for %s" % (len(rawmentions),target))
     for mention in rawmentions:
         logging.info("rawmention.target '%s' target '%s' %s" % (mention.target,target,mention.target.startswith(target)))
         if mention.target.startswith(target):
             mentions.append(mention)
     if jsonformat:
         jsonout={'type':'feed','children':[]}
         for mention in mentions:
             if mention.sourcejf2:
                 jsonout['children'].append(json.loads(mention.sourcejf2))
             else:
                 jsonout['children'].append({
                   "type": "entry",
                   "published": mention.created.isoformat(),
                   "url": mention.source,
                 })
         self.response.headers['Content-Type'] = 'application/json'
         self.response.write(json.dumps(jsonout))
     else:
         for mention in mentions:
             mention.humancreated = humanize.naturaltime(mention.created)
             mention.humanupdated = humanize.naturaltime(mention.updated)
             mention.prettytarget=cassis.auto_link(mention.target,do_embed=True,maxUrlLength=80)
             if mention.sourcejf2:
                 name=mention.source
                 jf = json.loads(mention.sourcejf2)
                 logging.info("ListMentions type %s " % (jf.get("type","")))
                 if jf.get("type","") == "feed":
                     kids= jf.get("children",[{}])
                     logging.info("ListMentions children %s " % (kids[0]))
                     post = kids[0]
                 elif jf.get("type","") == "entry":
                     logging.info("ListMentions entry %s " % (jf))
                     post= jf
                 name= post.get("name",mention.source)
                 content = post.get("content",name)
                 
                 mention.prettysource=cassis.auto_link(content,do_embed=True,maxUrlLength=80)
             else:
                 mention.prettysource=cassis.auto_link(mention.source,do_embed=True,maxUrlLength=80)
         template_values={'mentions':mentions,'targetdomain':targetdomain}
     
         template = JINJA_ENVIRONMENT.get_template('main.html')
         self.response.write(template.render(template_values))
示例#2
0
 def test_checkgif(self):
     self.assertEqual(
         cassis.auto_link(
             'see kevinmarks.com and kevinmarks.com/km.jpg and kevinmarks.com'
         ),
         'see <a class="auto-link" href="http://kevinmarks.com">kevinmarks.com</a> and <a class="auto-link" href="http://kevinmarks.com/km.jpg">kevinmarks.com/km.jpg</a> and <a class="auto-link" href="http://kevinmarks.com">kevinmarks.com</a>'
     )
示例#3
0
 def test_checkspacestyle(self):
     self.assertEqual(
         cassis.auto_link(
             '“In the case of digital content, the artifact, once created and published, is not static.” https://kartikprabhu.com/article/marginalia#In%20the%20case%20of%20digital%20content,%20the%20artifact,%20once%20created%20and%20published,%20is%20not%20static.',
             do_embed=True),
         '“In the case of digital content, the artifact, once created and published, is not static.” <blockquote class="auto-mention"><a class="auto-link" href="https://kartikprabhu.com/article/marginalia#In%20the%20case%20of%20digital%20content,%20the%20artifact,%20once%20created%20and%20published,%20is%20not%20static"><cite>kartikprabhu.com</cite><p>In the case of digital content, the artifact, once created and published, is not static</p></a></blockquote>.'
     )
示例#4
0
 def test_checkplustyle(self):
     self.assertEqual(
         cassis.auto_link(
             'http://www.kevinmarks.com/mentionquote.html##we+potentially+have+a+quote+from+the+source+in+the+link+itself',
             do_embed=True),
         '<blockquote class="auto-mention"><a class="auto-link" href="http://www.kevinmarks.com/mentionquote.html##we+potentially+have+a+quote+from+the+source+in+the+link+itself"><cite>www.kevinmarks.com</cite><p>we potentially have a quote from the source in the link itself</p></a></blockquote>'
     )
示例#5
0
 def get(self,path):
     if path is None:
         path=""
     page=path.strip().split('.')[0]
     if page not in ('main','about','testing'):
         page='main'
     mentionquery = Mention.query().order(-Mention.updated)
     mentions = mentionquery.fetch(20)
     for mention in mentions:
         mention.humancreated = humanize.naturaltime(mention.created)
         mention.humanupdated = humanize.naturaltime(mention.updated)
         mention.prettytarget=cassis.auto_link(mention.target,do_embed=True,maxUrlLength=80)
         mention.prettysource=cassis.auto_link(mention.source,do_embed=True,maxUrlLength=80)
     template_values={'mentions':mentions}
     
     template = JINJA_ENVIRONMENT.get_template(page+'.html')
     self.response.write(template.render(template_values))
示例#6
0
 def get(self,path):
     if path is None:
         path=""
     page=path.strip().split('.')[0]
     if page not in ('main','about','testing'):
         page='main'
     mentionquery = Mention.query().order(-Mention.updated)
     mentions = mentionquery.fetch(20)
     for mention in mentions:
         mention.humancreated = humanize.naturaltime(mention.created)
         mention.humanupdated = humanize.naturaltime(mention.updated)
         mention.prettytarget=cassis.auto_link(mention.target,do_embed=True,maxUrlLength=80)
         mention.prettysource=cassis.auto_link(mention.source,do_embed=True,maxUrlLength=80)
     template_values={'mentions':mentions}
     
     template = JINJA_ENVIRONMENT.get_template(page+'.html')
     self.response.write(template.render(template_values))
 def test_checkname(self):
     self.assertEqual(cassis.auto_link('kevinmarks.com',max_url_length=10), '<a class="auto-link" href="http://kevinmarks.com">kevinmarks…</a>')
     self.assertEqual(cassis.auto_link('kevinmarks.com',max_url_length=20), '<a class="auto-link" href="http://kevinmarks.com">kevinmarks.com</a>')
     self.assertEqual(cassis.auto_link('kevinmarks.com',max_url_length=14), '<a class="auto-link" href="http://kevinmarks.com">kevinmarks.com</a>')
     self.assertEqual(cassis.auto_link('http://kevinmarks.com',max_url_length=10), '<a class="auto-link" href="http://kevinmarks.com">kevinmarks…</a>')
     self.assertEqual(cassis.auto_link('https://kevinmarks.com',max_url_length=20), '<a class="auto-link" href="https://kevinmarks.com">kevinmarks.com</a>')
     self.assertEqual(cassis.auto_link('http://kevinmarks.com',max_url_length=14), '<a class="auto-link" href="http://kevinmarks.com">kevinmarks.com</a>')
示例#8
0
 def test_checkname(self):
     self.assertEqual(
         cassis.auto_link('kevinmarks.com', max_url_length=10),
         '<a class="auto-link" href="http://kevinmarks.com">kevinmarks…</a>'
     )
     self.assertEqual(
         cassis.auto_link('kevinmarks.com', max_url_length=20),
         '<a class="auto-link" href="http://kevinmarks.com">kevinmarks.com</a>'
     )
     self.assertEqual(
         cassis.auto_link('kevinmarks.com', max_url_length=14),
         '<a class="auto-link" href="http://kevinmarks.com">kevinmarks.com</a>'
     )
     self.assertEqual(
         cassis.auto_link('http://kevinmarks.com', max_url_length=10),
         '<a class="auto-link" href="http://kevinmarks.com">kevinmarks…</a>'
     )
     self.assertEqual(
         cassis.auto_link('https://kevinmarks.com', max_url_length=20),
         '<a class="auto-link" href="https://kevinmarks.com">kevinmarks.com</a>'
     )
     self.assertEqual(
         cassis.auto_link('http://kevinmarks.com', max_url_length=14),
         '<a class="auto-link" href="http://kevinmarks.com">kevinmarks.com</a>'
     )
示例#9
0
 def get(self):
     html = self.request.get('html')
     pretty = self.request.get('pretty','on') == 'on'
     rawtext = self.request.get('rawtext')
     embed = self.request.get('embed','')
     maxUrlLength = self.request.get('maxurllength','0')
     if maxUrlLength=='':
         maxUrlLength= '0'
     embedit = embed == 'on'
     values ={"rawhtml": html, "mfjson":"","rawtext":rawtext,"linkedhtml":""}
     if html:
         mf2dict = mf2py.Parser(doc=html).to_dict()
         if pretty:
             mf2json = json.dumps(mf2dict, indent=4,
                               separators=(', ', ': '),ensure_ascii=False)
         else:
             mf2json = json.dumps(mf2dict,ensure_ascii=False)
         values["mfjson"] = mf2json
     if rawtext:
         linkedhtml = cassis.auto_link(rawtext,do_embed=embedit,maxUrlLength=int(maxUrlLength))
         values["linkedhtml"] = linkedhtml
     template = JINJA_ENVIRONMENT.get_template('index.html')
     self.response.write(template.render(values))
示例#10
0
 def test_checknamewithttp(self):
     self.assertEqual(cassis.auto_link('http://kevinmarks.com'), '<a class="auto-link" href="http://kevinmarks.com">http://kevinmarks.com</a>')
示例#11
0
 def test_checkgifinline(self):
     self.assertEqual(
         cassis.auto_link(
             'http://media2.giphy.com/media/it8ZQy0jXZiX6/giphy.gif', True),
         '<a class="auto-link figure" href="http://media2.giphy.com/media/it8ZQy0jXZiX6/giphy.gif"><img alt="gif" src="http://media2.giphy.com/media/it8ZQy0jXZiX6/giphy.gif"/></a>'
     )
示例#12
0
 def test_checksvginline(self):
     self.assertEqual(
         cassis.auto_link('http://svgur.com/i/19.svg', True),
         '<a class="auto-link figure" href="http://svgur.com/i/19.svg"><img alt="svg" src="http://svgur.com/i/19.svg"/></a>'
     )
示例#13
0
 def test_checknoname(self):
     self.assertEqual(cassis.auto_link('@'), '@')
示例#14
0
 def test_checkgifinline(self):
     self.assertEqual(cassis.auto_link('http://media2.giphy.com/media/it8ZQy0jXZiX6/giphy.gif',True), '<a class="auto-link figure" href="http://media2.giphy.com/media/it8ZQy0jXZiX6/giphy.gif"><img alt="gif" src="http://media2.giphy.com/media/it8ZQy0jXZiX6/giphy.gif"/></a>')
示例#15
0
 def test_checknoname(self):
     self.assertEqual(cassis.auto_link('@'), '@')
示例#16
0
 def test_checknourl(self):
     self.assertEqual(cassis.auto_link('kevinmarks'), 'kevinmarks')
示例#17
0
 def test_checknamewithword(self):
     self.assertEqual(cassis.auto_link('hi @t'), 'hi <a class="auto-link h-x-username" href="https://twitter.com/t">@t</a>')
示例#18
0
 def test_checkgif(self):
     self.assertEqual(cassis.auto_link('http://media2.giphy.com/media/it8ZQy0jXZiX6/giphy.gif'), '<a class="auto-link" href="http://media2.giphy.com/media/it8ZQy0jXZiX6/giphy.gif">http://media2.giphy.com/media/it8ZQy0jXZiX6/giphy.gif</a>')
示例#19
0
 def test_checkplustyle(self):
     self.assertEqual(cassis.auto_link('http://www.kevinmarks.com/mentionquote.html##we+potentially+have+a+quote+from+the+source+in+the+link+itself',do_embed=True),'<blockquote class="auto-mention"><a class="auto-link" href="http://www.kevinmarks.com/mentionquote.html##we+potentially+have+a+quote+from+the+source+in+the+link+itself"><cite>www.kevinmarks.com</cite><p>we potentially have a quote from the source in the link itself</p></a></blockquote>')
示例#20
0
 def get(self):
     target,targetdomain= geturlanddomain(self.request.get('target'))
     unverified = self.request.get('unverified','off') == 'on'
     jsonformat = self.request.get('json','off') == 'on'
     targetkey = ndb.Key('Domain', targetdomain)
     
     logging.info("ListMentions target:%s targetdomain %s unverified %s json %s" % (target,targetdomain,unverified,json))
     if unverified:
         mentionquery = Mention.query(ancestor = targetkey).order(-Mention.updated)
     else:
         mentionquery = Mention.query(ancestor = targetkey).filter(Mention.verified==True).order(-Mention.updated)
     rawmentions = mentionquery.fetch(100)
     mentions=[]
     logging.info("listmentions got %s mentions for %s" % (len(rawmentions),target))
     for mention in rawmentions:
         logging.info("rawmention.target '%s' target '%s' %s" % (mention.target,target,mention.target.startswith(target)))
         if mention.target.startswith(target):
             mentions.append(mention)
     if jsonformat:
         jsonout={'type':'feed','children':[]}
         for mention in mentions:
             post ={"type": "entry","published": mention.created.isoformat(),"url": mention.source}
             if mention.sourcejf2:
                 post=json.loads(mention.sourcejf2)
                 post['url'] = post.get('url',mention.source)
                 for key in post:
                     if post[key]==mention.target or (isinstance(post[key],dict) and post[key].get('url','')==mention.target):
                         post['wm-property']=key
                         break
                 
             jsonout['children'].append(post)
         self.response.headers['Content-Type'] = 'application/json'
         self.response.headers['Access-Control-Allow-Origin'] = '*'
         self.response.write(json.dumps(jsonout))
     else:
         for mention in mentions:
             mention.humancreated = humanize.naturaltime(mention.created)
             mention.humanupdated = humanize.naturaltime(mention.updated)
             mention.prettytarget=cassis.auto_link(mention.target,do_embed=True,maxUrlLength=80)
             if mention.sourcejf2:
                 post={}
                 name=mention.source
                 jf = json.loads(mention.sourcejf2)
                 logging.info("ListMentions type %s " % (jf.get("type","")))
                 if jf.get("type","") == "feed":
                     kids= jf.get("children",[{}])
                     logging.info("ListMentions children %s " % (kids[0]))
                     post = kids[0]
                 elif jf.get("type","") == "entry":
                     logging.info("ListMentions entry %s " % (jf))
                     post= jf
                 name= post.get("name",mention.source)
                 content = post.get("content",name)
                 
                 mention.prettysource=cassis.auto_link(content,do_embed=True,maxUrlLength=80)
             else:
                 mention.prettysource=cassis.auto_link(mention.source,do_embed=True,maxUrlLength=80)
         template_values={'mentions':mentions,'targetdomain':targetdomain}
     
         template = JINJA_ENVIRONMENT.get_template('main.html')
         self.response.write(template.render(template_values))
示例#21
0
 def test_checkspacestyle(self):
     self.assertEqual(cassis.auto_link('“In the case of digital content, the artifact, once created and published, is not static.” https://kartikprabhu.com/article/marginalia#In%20the%20case%20of%20digital%20content,%20the%20artifact,%20once%20created%20and%20published,%20is%20not%20static.',do_embed=True),'“In the case of digital content, the artifact, once created and published, is not static.” <blockquote class="auto-mention"><a class="auto-link" href="https://kartikprabhu.com/article/marginalia#In%20the%20case%20of%20digital%20content,%20the%20artifact,%20once%20created%20and%20published,%20is%20not%20static"><cite>kartikprabhu.com</cite><p>In the case of digital content, the artifact, once created and published, is not static</p></a></blockquote>.')
示例#22
0
 def test_checkgif(self):
     self.assertEqual(cassis.auto_link('see kevinmarks.com and kevinmarks.com/km.jpg and kevinmarks.com'), 'see <a class="auto-link" href="http://kevinmarks.com">kevinmarks.com</a> and <a class="auto-link" href="http://kevinmarks.com/km.jpg">kevinmarks.com/km.jpg</a> and <a class="auto-link" href="http://kevinmarks.com">kevinmarks.com</a>')
示例#23
0
 def test_checksvginline(self):
     self.assertEqual(cassis.auto_link('http://svgur.com/i/19.svg',True), '<a class="auto-link figure" href="http://svgur.com/i/19.svg"><img alt="svg" src="http://svgur.com/i/19.svg"/></a>')
示例#24
0
 def test_checknourl(self):
     self.assertEqual(cassis.auto_link('kevinmarks'), 'kevinmarks')
示例#25
0
 def test_checkemail(self):
     self.assertEqual(cassis.auto_link('*****@*****.**'), '*****@*****.**')
示例#26
0
 def test_checklongnamewithword(self):
     self.assertEqual(cassis.auto_link('hi @kevinmarks'), 'hi <a class="auto-link h-x-username" href="https://twitter.com/kevinmarks">@kevinmarks</a>')
示例#27
0
 def test_checkemail(self):
     self.assertEqual(cassis.auto_link('*****@*****.**'),
                      '*****@*****.**')
示例#28
0
 def test_checklongnamewithword(self):
     self.assertEqual(
         cassis.auto_link('hi @kevinmarks'),
         'hi <a class="auto-link h-x-username" href="https://twitter.com/kevinmarks">@kevinmarks</a>'
     )
示例#29
0
 def test_checkgif(self):
     self.assertEqual(
         cassis.auto_link(
             'http://media2.giphy.com/media/it8ZQy0jXZiX6/giphy.gif'),
         '<a class="auto-link" href="http://media2.giphy.com/media/it8ZQy0jXZiX6/giphy.gif">http://media2.giphy.com/media/it8ZQy0jXZiX6/giphy.gif</a>'
     )
示例#30
0
 def test_checknamewithttp(self):
     self.assertEqual(
         cassis.auto_link('http://kevinmarks.com'),
         '<a class="auto-link" href="http://kevinmarks.com">http://kevinmarks.com</a>'
     )
示例#31
0
 def test_checksvg(self):
     self.assertEqual(
         cassis.auto_link('http://svgur.com/i/19.svg'),
         '<a class="auto-link" href="http://svgur.com/i/19.svg">http://svgur.com/i/19.svg</a>'
     )
示例#32
0
 def test_checkname(self):
     self.assertEqual(
         cassis.auto_link('@t'),
         '<a class="auto-link h-x-username" href="https://twitter.com/t">@t</a>'
     )
示例#33
0
 def test_checksvg(self):
     self.assertEqual(cassis.auto_link('http://svgur.com/i/19.svg'), '<a class="auto-link" href="http://svgur.com/i/19.svg">http://svgur.com/i/19.svg</a>')