my eye

Reintroduce feed support

Committed 438c86

--- a/indieweb_rocks/__init__.py
+++ b/indieweb_rocks/__init__.py

     update_details(
         social_network=social_network, reciprocals=list(reciprocals), rel_me=rel_mes
     )
-    return
-
-    # XXX feed = page.feed
-    # alt_feed_urls = set()
-    # if not feed["entries"]:
-    #     try:
-    #         alt_feed_urls = set(rels["home"]) & set(rels["alternate"])
-    #     except KeyError:
-    #         pass
-    # alternate_reprs = rels.pop("alternate", [])
-    # alternate_feeds = rels.pop("feed", [])
-    # if not feed["entries"]:
-    #     for alt_feed_url in alternate_reprs + alternate_feeds:
-    #         try:
-    #             feed = agent.get(alt_feed_url).feed
-    #         except ValueError:  # XML feed
-    #             pass
-    #         finally:
-    #             print("using", alt_feed_url)
-    # # rels.pop("alternate", None)
-    # for entry in feed["entries"]:
-    #     try:
-    #         published = entry["published"]
-    #         permalink = entry["url"]
-    #         entry.pop("published-str")
-    #     except KeyError:
-    #         continue
-    #     entry.pop("uid", None)
-    #     # TODO refresh_page(permalink)
+
+    feed = response.feed
+    alt_feed_urls = set()
+    if not feed["items"]:
+        try:
+            alt_feed_urls = set(rels["home"]) & set(rels["alternate"])
+        except KeyError:
+            pass
+    alternate_reprs = rels.pop("alternate", [])
+    alternate_feeds = rels.pop("feed", [])
+    if not feed["items"]:
+        for alt_feed_url in alternate_reprs + alternate_feeds:
+            try:
+                feed = agent.get(alt_feed_url).feed
+            except ValueError:  # XML feed
+                pass
+            finally:
+                print("using", alt_feed_url)
+    # rels.pop("alternate", None)
+    for entry in feed["items"]:
+        try:
+            published = entry["published"]
+            permalink = entry["url"]
+            entry.pop("published-str")
+        except KeyError:
+            continue
+        entry.pop("uid", None)
+        # TODO refresh_page(permalink)
+    update_details(feed=feed)
 
     # logging.debug("archiving to WARC..")
     # warc_file = site_path / "warc_output"
         scores[0][1] = (2, "no <code>rel=me</code>s found")
 
     # L1 Posts
-    if feed["entries"]:
-        if len(feed["entries"]) > 1:
+    if feed["items"]:
+        if len(feed["items"]) > 1:
             scores[0][2] = (0, "more than one post")
         else:
             scores[0][2] = (1, "only one post")

--- a/indieweb_rocks/templates/site.html
+++ b/indieweb_rocks/templates/site.html

             $else:
                 $org\
             $if not loop.last:
-                , 
+                ,
         </small>
     $if roles := card.pop("role", None):
         <br><small>
         $for role in roles:
             <code>$role</code>\
             $if not loop.last:
-                , 
+                ,
         </small>
     $if note := card.pop("note", None):
         <p style=font-size:.75em;hyphens:auto>$note[0]</p>
                 $category\
             </code>\
             $if not loop.last:
-                , 
+                ,
         </small></p>
     $ street_address = card.pop("street-address", None)
     $ locality = card.pop("locality", None)
     </form>
 </div>
 <div>
-$# $ feed = details["feed"]
-$# $if feed["entries"]:
-$#     <div class=h-feed>
-$#     $for entry in feed["entries"]:
-$#         $# <pre>$pformat(entry)</pre>
-$#         $if details["whostyle"]:
-$#             <iframe
-$#             onload="this.style.height=(this.contentWindow.document.body.scrollHeight+25)+'px'"
-$#             style=border:0;width:100% srcdoc='<link rel=stylesheet href=$uri(details["whostyle"][0]).normalized>
-$#             <div class=whostyle-$uri(details["url"]).minimized.replace(".", "-")>
-$#         <div class=entry>
-$#         $ entry_url = entry.pop("url", None)
-$#         $ entry_type = entry.pop("type")
-$#         $ post_type = entry.pop("post-type")
-$#         $if entry_type == "entry":
-$#             $if in_reply_to := entry.pop("in-reply-to", None):
-$#                 $ reply = in_reply_to[0]
-$#                 $ reply_url = reply.get("url", "")
-$#                 <p>↩️
-$#                 $ gh_issue_re = r"https://github.com/(\w+)/([\w-]+)/issues/(\d+)(#([\w-]+))?"
-$#                 $if gh_match := re.match(gh_issue_re, reply_url):
-$#                     $ user, repo, issue, _, comment = gh_match.groups()
-$#                     <img src=/sites/github.com/icon.png style=height:1em alt="GitHub logo">
-$#                     <a href=https://github.com/$user>$user</a> /
-$#                     <a href=https://github.com/$user/$repo>$repo</a> /
-$#                     <a href=https://github.com/$user/$repo/issues>issues</a> /
-$#                     <a href=https://github.com/$user/$repo/issues/$issue>$issue</a> # 
-$#                     <a href=https://github.com/$user/$repo/issues/$issue#$comment>$comment</a>
-$#                 $elif tw_match := re.match(r"https://twitter.com/(\w+)/status/(\d+)", reply_url):
-$#                     $ user, tweet = tw_match.groups()
-$#                     <img src=/sites/twitter.com/icon.png style=height:1em class="Twitter logo">
-$#                     <a href=https://twitter.com/$user>$user</a> /
-$#                     <a href=https://twitter.com/$user/status/$tweet>$tweet</a>
-$#                 $else:
-$#                     <a href=$reply_url>$reply_url</a>
-$#                 </p>
-$#             $if photo := entry.pop("photo", None):
-$#                 <p><img src=$photo style=max-width:100% alt=$photo /></p>
-$#             $if entry_name := entry.pop("name", None):
-$#                 <h3>$entry_name</h3>
-$#             $if summary := entry.pop("summary", None):
-$#                 $if entry_name != summary:
-$#                     <p>$summary</p>
-$#             $if like_of := entry.pop("like-of", None):
-$#                 $ like_url = like_of[0]["url"]
-$#                 <p>♥️ <a href=$like_url>$like_url</a></p>
-$#             $if content := entry.pop("content", None):
-$#                 $if post_type == "article":
-$#                     <p>$entry.pop("content-plain")[:280]&hellip;</p>
-$#                 $else:
-$#                     <p>$:content</p>
-$#                     $ entry.pop("content-plain")
-$#             $if categories := entry.pop("category", None):
-$#                 <p><small>
-$#                 $for category in categories:
-$#                     <code>$category</code>\
-$#                     $if not loop.last:
-$#                         , 
-$#                 </small></p>
-$#         $elif entry_type == "event":
-$#             <p>$entry.pop("name")<br>
-$#             <small>$entry.pop("start")&thinsp;&ndash;&thinsp;$entry.pop("end", None)</small></p>
-$#             $ entry.pop("start-str")
-$#             $ entry.pop("end-str", None)
-$#             <form method=post action=/micropub>
-$#             <input type=hidden name=in-reply-to value="$entry_url">
-$#             <select name=rsvp>
-$#             <option value=yes>Yes</option>
-$#             <option value=no>No</option>
-$#             <option value=maybe>Maybe</option>
-$#             </select>
-$#             <button>RSVP</button>
-$#             </form>
-$#         <p style=text-align:right>\
-$#         $if author := entry.pop("author", None):
-$#             $if author_url := author.pop("url", None):
-$#                 $if uri(author_url).minimized not in all_urls:
-$#                     $author_url
-$#         <small>
-$#         $if location := entry.pop("location", None):
-$#             $if "latitude" in location:
-$#                 <a href=/map?lat=$location['latitude']&lng=$location['longitude']>\
-$#                 $location["latitude"], $location["longitude"]</a>
-$#         $if published := entry.pop("published", None):
-$#             <time value="$published.get('datetime')" datetime="$published" class="dt-published">$published.get('datetime')</time>
-$#             $# $get_dt(published).diff_for_humans()
-$#             $# $if updated := entry.pop("updated", None):
-$#             $#     $if updated != published:
-$#             $#         , <small>updated $get_dt(updated).diff_for_humans()</small>
-$#             $ entry.pop("published-str", None)
-$#             $ entry.pop("updated", None)
-$#             $ entry.pop("updated-str", None)
-$#         <br><a href=$entry_url>$uri(entry_url).path</a>
-$#         $if syndication_urls := entry.pop("syndication", None):
-$#             $for syndication_url in syndication_urls:
-$#                 $if tw_match := re.match(r"https://twitter.com/(\w+)/status/(\d+)", syndication_url):
-$#                     $ user, tweet = tw_match.groups()
-$#                     <a href=https://twitter.com/$user/status/$tweet><img
-$#                     src=/sites/twitter.com/icon.png style=height:1em class="Twitter logo"></a>
-$#                     $# <a href=https://twitter.com/$user>$user</a> /
-$#                     $# <a href=https://twitter.com/$user/status/$tweet>$tweet</a>
-$#                 $else:
-$#                     $syndication_url\
-$#                 $if not loop.last:
-$#                     , 
-$#         </small></p>
-$#         $ entry.pop("uid", None)  # FIXME: what is it good for?
-$#         $if entry:
-$#             $:render_uninterpreted(f"h-{entry_type}", entry, "properties")
-$#         </div>
-$#         $if details["whostyle"]:
-$#             </div>'>
-$#             </iframe>
-$#     $if rel_next := rels.pop("next", None):
-$#         <p>next: <a href=$rel_next[0]>$rel_next[0]</a></p>
-$#     $if rel_prev := rels.pop("prev", None):
-$#         <p>previous: <a href=$rel_prev[0]>$rel_prev[0]</a></p>
-$#     </div>
-$# $else:
-$#     <p><em>No <a href=https://indieweb.org/feed#How_to_Publish>content
-$#     feed</a> available.</em></p>
+$ feed = details["feed"]
+$if feed["items"]:
+    <div class=h-feed>
+    $for entry in feed["items"]:
+        $# <pre>$pformat(entry)</pre>
+        $if details["whostyle"]:
+            <iframe
+            onload="this.style.height=(this.contentWindow.document.body.scrollHeight+25)+'px'"
+            style=border:0;width:100% srcdoc='<link rel=stylesheet href=$uri(details["whostyle"][0]).normalized>
+            <div class=whostyle-$uri(details["url"]).minimized.replace(".", "-")>
+        <div class=entry>
+        $ entry_url = entry.pop("url", [None])[0]
+        $ entry_type = entry.pop("type")[0].partition("-")[2]
+        $ post_type = entry.pop("post-type", None)
+        $if entry_type == "entry":
+            $if in_reply_to := entry.pop("in-reply-to", None):
+                $ reply_url = in_reply_to[0]
+                $if isinstance(reply_url, dict):
+                    $ reply_url = reply_url["properties"]["url"][0]
+                <p>↩️
+                $ gh_issue_re = r"https://github.com/(\w+)/([\w-]+)/issues/(\d+)(#([\w-]+))?"
+                $if gh_match := re.match(gh_issue_re, reply_url):
+                    $ user, repo, issue, _, comment = gh_match.groups()
+                    <img src=/sites/github.com/icon.png style=height:1em alt="GitHub logo">
+                    <a href=https://github.com/$user>$user</a> /
+                    <a href=https://github.com/$user/$repo>$repo</a> /
+                    <a href=https://github.com/$user/$repo/issues>issues</a> /
+                    <a href=https://github.com/$user/$repo/issues/$issue>$issue</a> #
+                    <a href=https://github.com/$user/$repo/issues/$issue#$comment>$comment</a>
+                $elif tw_match := re.match(r"https://twitter.com/(\w+)/status/(\d+)", reply_url):
+                    $ user, tweet = tw_match.groups()
+                    <img src=/sites/twitter.com/icon.png style=height:1em class="Twitter logo">
+                    <a href=https://twitter.com/$user>$user</a> /
+                    <a href=https://twitter.com/$user/status/$tweet>$tweet</a>
+                $else:
+                    <a href=$reply_url>$reply_url</a>
+                </p>
+            $if photo := entry.pop("photo", None):
+                <p><img src=$photo style=max-width:100% alt=$photo /></p>
+            $if entry_name := entry.pop("name", None):
+                <h3>$entry_name</h3>
+            $if summary := entry.pop("summary", None):
+                $if entry_name != summary:
+                    <p>$summary</p>
+            $if like_of := entry.pop("like-of", [None])[0]:
+                <p>♥️ <a href=$like_of>$like_of</a></p>
+            $if content := entry.pop("content", [None])[0]:
+                $if post_type == "article":
+                    <p>$content["value"][:280]&hellip;</p>
+                $else:
+                    <p>$:content["value"]</p>
+            $if categories := entry.pop("category", None):
+                <p><small>
+                $for category in categories:
+                    <code>$category</code>\
+                    $if not loop.last:
+                        ,
+                </small></p>
+        $elif entry_type == "event":
+            <p>$entry.pop("name")<br>
+            <small>$entry.pop("start")&thinsp;&ndash;&thinsp;$entry.pop("end", None)</small></p>
+            $ entry.pop("start-str")
+            $ entry.pop("end-str", None)
+            <form method=post action=/micropub>
+            <input type=hidden name=in-reply-to value="$entry_url">
+            <select name=rsvp>
+            <option value=yes>Yes</option>
+            <option value=no>No</option>
+            <option value=maybe>Maybe</option>
+            </select>
+            <button>RSVP</button>
+            </form>
+        <p style=text-align:right>\
+        $if author := entry.pop("author", None):
+            $if author_url := author.pop("url", None):
+                $if uri(author_url).minimized not in all_urls:
+                    $author_url
+        <small>
+        $if location := entry.pop("location", None):
+            $if "latitude" in location:
+                <a href=/map?lat=$location['latitude']&lng=$location['longitude']>\
+                $location["latitude"], $location["longitude"]</a>
+        $if published := entry.pop("published", [None])[0]:
+            $# <time value="$published.get('datetime')" datetime="$published" class="dt-published">$published.get('datetime')</time>
+            $published
+            $# $get_dt(published).diff_for_humans()
+            $# $if updated := entry.pop("updated", None):
+            $#     $if updated != published:
+            $#         , <small>updated $get_dt(updated).diff_for_humans()</small>
+            $ entry.pop("published-str", None)
+            $ entry.pop("updated", None)
+            $ entry.pop("updated-str", None)
+
+        <br><a href=$entry_url>$uri(entry_url).path</a>
+
+        $if syndication_urls := entry.pop("syndication", None):
+            $for syndication_url in syndication_urls:
+                $if tw_match := re.match(r"https://twitter.com/(\w+)/status/(\d+)", syndication_url):
+                    $ user, tweet = tw_match.groups()
+                    <a href=https://twitter.com/$user/status/$tweet><img
+                    src=/sites/twitter.com/icon.png style=height:1em class="Twitter logo"></a>
+                    $# <a href=https://twitter.com/$user>$user</a> /
+                    $# <a href=https://twitter.com/$user/status/$tweet>$tweet</a>
+                $else:
+                    $syndication_url\
+                $if not loop.last:
+                    ,
+        </small></p>
+        $ entry.pop("uid", None)  # FIXME: what is it good for?
+        $if entry:
+            $:render_uninterpreted(f"h-{entry_type}", entry, "properties")
+        </div>
+        $if details["whostyle"]:
+            </div>'>
+            </iframe>
+    $if rel_next := rels.pop("next", None):
+        <p>next: <a href=$rel_next[0]>$rel_next[0]</a></p>
+    $if rel_prev := rels.pop("prev", None):
+        <p>previous: <a href=$rel_prev[0]>$rel_prev[0]</a></p>
+    </div>
+$else:
+    <p><em>No <a href=https://indieweb.org/feed#How_to_Publish>content
+    feed</a> available.</em></p>
 </div>
 
 </div>