all repos — nasg @ 32bf4994e7c04ce4476453d5ab1f4c58c918efc7

fetch and display u-syndication in case of webmention.io and brid.gy publish can be asked to provide the endpoint
Peter Molnar hello@petermolnar.eu
Sun, 05 May 2019 13:04:36 +0100
commit

32bf4994e7c04ce4476453d5ab1f4c58c918efc7

parent

72582d0a600a2f4bf7651e7e5d216007708cdae3

2 files changed, 92 insertions(+), 20 deletions(-)

jump to
M nasg.pynasg.py

@@ -230,6 +230,58 @@ )

) @property + def syndication_fpath(self): + return self.fpath.replace('.ping', '.copy') + + def check_syndication(self): + """ this is very specific to webmention.io and brid.gy publish """ + if os.path.isfile(self.syndication_fpath): + logger.debug("syndication copy exist for %s", self.dpath) + return + if "fed.brid.gy" in self.target: + return + if "brid.gy" not in self.target: + return + if not self.exists: + return + + with open(self.fpath) as f: + txt = f.read() + if "telegraph.p3k.io" not in txt: + return + try: + maybe = json.loads(txt) + if "location" not in maybe: + return + if "http_body" not in maybe: + wio = requests.get(maybe["location"]) + if wio.status_code != requests.codes.ok: + return + maybe = wio.json() + with open(self.fpath, "wt") as update: + update.write(json.dumps(maybe, sort_keys=True, indent=4)) + if "url" in maybe["http_body"]: + data = json.loads(maybe["http_body"]) + url = data["url"] + sp = os.path.join( + self.dpath, "%s.copy" % url2slug(url, 200) + ) + with open(sp, "wt") as f: + logger.info( + "writing syndication copy URL %s to %s", + url, + sp + ) + f.write(url) + except Exception as e: + logger.error( + "failed to fetch syndication URL for %s: %s", + self.dpath, + e + ) + pass + + @property def exists(self): if not os.path.isfile(self.fpath): return False

@@ -243,6 +295,7 @@ writepath(self.fpath, content)

async def send(self): if self.exists: + self.check_syndication() return elif settings.args.get('noping'): self.save("noping entry at %s" % arrow.now() )

@@ -264,7 +317,6 @@ if r.status_code not in [200, 201, 202]:

logger.error('sending failed: %s %s', r.status_code, r.text) else: self.save(r.text) - class MarkdownDoc(object): """ Base class for anything that is stored as .md """

@@ -464,7 +516,7 @@ return dt

@property def sameas(self): - r = [] + r = {} for k in glob.glob( os.path.join( os.path.dirname(self.fpath),

@@ -472,8 +524,8 @@ '*.copy'

) ): with open(k, 'rt') as f: - r.append(f.read()) - return r + r.update({f.read(): True}) + return list(r.keys()) @cached_property def comments(self):

@@ -1108,6 +1160,20 @@ "license": settings.licence['_default']

}) if self.is_mainimg: r.update({"representativeOfPage": True}) + + if self.exif['GPSLatitude'] != 0 and self.exif['GPSLongitude'] != 0: + r.update({ + "locationCreated": struct({ + "@context": "http://schema.org", + "@type": "Place", + "geo": struct({ + "@context": "http://schema.org", + "@type": "GeoCoordinates", + "latitude": self.exif['GPSLatitude'], + "longitude": self.exif['GPSLongitude'] + }) + }) + }) return struct(r) def __str__(self):

@@ -1215,7 +1281,9 @@ 'ExposureTime': '',

'FocalLength': '', 'ISO': '', 'LensID': '', - 'CreateDate': str(arrow.get(self.mtime)) + 'CreateDate': str(arrow.get(self.mtime)), + 'GPSLatitude': 0, + 'GPSLongitude': 0 } if not self.is_photo: return exif

@@ -1227,7 +1295,9 @@ 'ExposureTime': ['ExposureTime'],

'FocalLength': ['FocalLength'], # ['FocalLengthIn35mmFormat'], 'ISO': ['ISO'], 'LensID': ['LensID', 'LensSpec', 'Lens'], - 'CreateDate': ['CreateDate', 'DateTimeOriginal'] + 'CreateDate': ['CreateDate', 'DateTimeOriginal'], + 'GPSLatitude': ['GPSLatitude'], + 'GPSLongitude': ['GPSLongitude'] } for ekey, candidates in mapping.items():

@@ -1399,9 +1469,9 @@ if self.parent.meta.get('FileType', 'jpeg').lower() == 'jpeg':

thumb.compression_quality = 88 thumb.unsharp_mask( radius=1, - sigma=1, - amount=0.5, - threshold=0.1 + sigma=0.5, + amount=0.7, + threshold=0.5 ) thumb.format = 'pjpeg'
M templates/Singular.j2.htmltemplates/Singular.j2.html

@@ -96,21 +96,23 @@ {% for keyword in post.keywords %}

#<span class="p-category">{{ keyword }}</span>{% if not loop.last %} {% endif %} {% endfor %} {% endif %} -<!-- -{% if post.sameAs|length %} + {% if post['@type'] == 'Photograph' %} + {% if post.image[0].locationCreated %} + <br /> + Location: + <a class="h-geo" href="https://www.openstreetmap.org/#map=14/{{ post.image[0].locationCreated.geo.longitude }}/{{ post.image[0].locationCreated.geo.latitude }}"> + <span class="p-longitude">{{ post.image[0].locationCreated.geo.longitude }}</span>, + <span class="p-latitude">{{ post.image[0].locationCreated.geo.latitude }}</span> + </a> + {% endif %} + {% endif %} + {% if post.sameAs|length %} <br /> Syndicated to: - <ul> {% for url in post.sameAs %} - <li> - <a class="u-syndication" href="{{ url }}"> - {{ url }} - </a> - </li> + <a class="u-syndication" href="{{ url }}">{{ url }}</a>{% if not loop.last and post.sameAs|length >1 %}, {% endif %} {% endfor %} - </ul> -{% endif %} ---> + {% endif %} </p> {% if post.subjectOf %}