Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello โ I'm @olemoritz on Twitter.
Webview and Reader mode
-
@mikael I tried your script with the NYTimes url above and got these errors:
WARN: et2 snippet should only load once per page
ERROR: Pinterest Tag Error: 'load' command was called multiple times. Previously for tag id '%s', now for tag id '%s'.
ERROR: TypeError: null is not an object (evaluating 'r.articleNode().innerHTML') (https://www.nytimes.com/2019/01/29/climate/global-warming-extreme-weather.html, line: 1, column: 81)
ERROR: Script error. (, line: 0, column: 0)Is this what you are talking about?
-
@ihf Just to know what you think, did you try mine?
-
@cvp Yes, just now and it also fails on the Nytimes articles. Is it working for you? If so, I will send the error messages.
-
-
Yes, but look at where the article ends.
-
@ihf I don't have any error.
-
I canโt reproduce the error (I may have run it under python 2.7). I can get what you are seeing but the article is truncated.
-
@ihf When I try in Safari, I get the same result, except some lines at end saying there are 4 articles more
-
-
@ihf As I use the standard Apple Safari view, I suppose we can't get better, no?
-
@cvp I tried on some Macstories and it worked perfectly. What I was seeing may be peculiar to the NYtimes as I cannot login so there are limits to what it will show.
Thanks so much for working on this. Now I will try to incorporate this into rss_reader.py
-
@ihf ๐ good luck
-
@ihf If you go back in normal mode, at bottom, you get
-
-
Safari view is new to me and very much fun, but if the original intent was to get some RSS items cleaned up, I do not see anything in the Safari view API to get the cleaned HTML out of the view. Can it take a
file:
URL so that we can use it just as a viewer? Or would it be able to handle just the online RSS feed address? -
From what I read, it ONLY supports http and https urls -- no file://, data://, or other loading from stored HTML. Furthermore, you basically have no access to anything happening inside it, for security. There seem to be delegate methods for things like redirect, and Done/Action buttons.
I still think that readability.J's combined with wkwebview might be the way to handle custom rss reader
-
You are right, Apple doc says
Choosing the Best Web Viewing Class If your app lets users view websites from anywhere on the Internet, use the SFSafariViewController class. If your app customizes, interacts with, or controls the display of web content, use the WKWebView class.
-
Using Flask, we could access local html Files...
import ui from objc_util import * from flask import Flask import threading import os app = Flask(__name__) @app.route('/') def entry_point(): global local_html fil = os.path.expanduser('~/Documents/'+local_html) data = open(fil).read() return data def safariViewControllerDidFinish_(_self, _cmd, _controller): #print('SafariViewControllerDidFinish_') SFSafariViewController = ObjCInstance(_controller) #print(SFSafariViewController.uiview) try: SFSafariViewController.uiview.close() except Exception as e: SFSafariViewController.uiview().close() methods = [safariViewControllerDidFinish_,] protocols = ['SFSafariViewControllerDelegate'] try: MySFSafariViewControllerDelegate = ObjCClass('MySFSafariViewControllerDelegate') except: MySFSafariViewControllerDelegate = create_objc_class('MySFSafariViewControllerDelegate', methods=methods, protocols=protocols) #@on_main_thread def MySFSafariViewController(url, w, h, mode='sheet', popover_location=None): uiview = ui.View() uiview.frame = (0,0,w,h) uiview.background_color = 'white' if mode == 'sheet': uiview.present('sheet',hide_title_bar=True) elif mode == 'popover': if popover_location: uiview.present('popover', hide_title_bar=True, popover_location=popover_location) else: return else: return SFSafariViewController = ObjCClass('SFSafariViewController').alloc().initWithURL_entersReaderIfAvailable_(url,True) # Use new delegate class: delegate = MySFSafariViewControllerDelegate.alloc().init() SFSafariViewController.delegate = delegate SFSafariViewController.setModalPresentationStyle_(3) SFSafariViewController.uiview = uiview # used by delegate objc_uiview = ObjCInstance(uiview) SUIViewController = ObjCClass('SUIViewController') vc = SUIViewController.viewControllerForView_(objc_uiview) vc.presentViewController_animated_completion_(SFSafariViewController, True, None) def main(url,local=None): global local_html # demo code mv = ui.View() mv.background_color = 'white' mv.name = 'Test SFSafariViewController' mv.present() ns_url = nsurl(url) if 'http://127.0.0.1:5000/' in url: # local html local_html = local threads = threading.enumerate() already = False for thread in threads: if thread.name == 'flask': already = True break if not already: # run Flask in separate thread threading.Thread(target=app.run,name='flask').start() MySFSafariViewController(ns_url,600,500) #MySFSafariViewController(url,600,500, mode ='popover', popover_location=(mv.width-40,60)) if __name__ == '__main__': #main('https://www.macstories.net/stories/my-must-have-ios-apps-2018-edition/2/') main('http://127.0.0.1:5000/' ,local='MesTests/test.html')
-
Maybe I best go back and explain what exactly I was trying to achieve. I have been using this RSS reader script for years ([https://github.com/dlo/PythonistaRSSReader]. It takes RSS feed urls and displays the latest titles for each feed. The titles can be touched to take you to the actual posting. I would like it to utilize the Reader mode where it is available. If there is a better RSS reader script available (or an enhanced version of this one, that would be nice to know as well).
-
@ihf, if I understand correctly, you are not downloading the articles themselves, thus just opening them in the Safari view would be an working solution. Looking at the docs, the method for opening directly into Reader mode has been deprecated, and the option is now a bit hidden in the configuration object, but still there.