omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. comfortablynick

    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.


    • Profile
    • Following 0
    • Followers 0
    • Topics 0
    • Posts 10
    • Best 2
    • Controversial 0
    • Groups 0

    comfortablynick

    @comfortablynick

    2
    Reputation
    717
    Profile views
    10
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    comfortablynick Unfollow Follow

    Best posts made by comfortablynick

    • RE: Is possible to run Black on Pythonista?

      I was wondering the same thing, and I finally got this working. I think the problem was with the attrs package. One of the errors made it look like I needed attr (no 's'), but that is a different unrelated package.

      I installed black with Stash pip, as well as attrs and any other package it needed, until I could run black.py without errors.

      I put together this little script to format a document in the editor. I'm sure there's a better way to do it, but this seems to work beautifully when added to the tools menu in Pythonista.

      #!/usr/bin/env python3
      """Format editor contents/selection in Pythonista with Black formatter."""
      import editor
      import black
      import console
      import time
      
      # Options
      LINE_LEN = 88  # Default: 88
      FAST = False  # True = skip syntax check
      
      # Get text and selection
      text = editor.get_text()
      start, end = editor.get_selection()
      selection = text[start:end]
      
      if len(selection) > 0:
          raw_text = selection
      else:
          raw_text = text
      
      try:
          start_tm = time.time()
          formatted = black.format_file_contents(
              raw_text, line_length=LINE_LEN, fast=int(FAST)
          )
      except black.NothingChanged:
          console.hud_alert(
              f"No formatting needed! ({time.time() - start_tm:.4f}s)", "success"
          )
      except Exception as err:
          console.hud_alert(err, "error")
      else:
          new_text = formatted[:-1]
          if len(selection) > 0:
              editor.replace_text(start, end, new_text)
              editor.set_selection(start, start + len(new_text))
          else:
              editor.replace_text(0, len(text), new_text)
              editor.set_selection(start, end)
          console.hud_alert(
              f"Reformatted! ({time.time() - start_tm:.4f}s)", "success")
      
      posted in Pythonista
      comfortablynick
      comfortablynick
    • RE: Git support?

      I love being able to use Working Copy and Pythonista together. Is there any way to execute scripts from Working Copy via appex or callback URL (e.g., from Workflow)?

      It's great that we can open the scripts from Working Copy, but it would be a lot more useful if we could execute them without saving a local copy in Pythonista.

      posted in Pythonista
      comfortablynick
      comfortablynick

    Latest posts made by comfortablynick

    • RE: iOS 13

      Thanks for mentioning Pyto; I'm glad there's competition. It's less polished than Pythonista (right now) but has some exciting features. The native pip is so much easier than Stash.

      posted in Pythonista
      comfortablynick
      comfortablynick
    • RE: Local scripts cannot be accessed via Files app/document picker

      @SmartGoat said:

      1. Is Working Copy able to detect iCloud Drive files changes to commit it in github ?

      Yes, that feature has been added.

      1. if yes, why not putting your Pythonista files directly in the iCloud Drive folder of Pythonista ?

      That is an option, one that I intend to use at some point. I'm using it currently for Scriptable, and it works great. I can edit a Scriptable script on my iPhone, then I open up Working Copy on my iPad (where I set up the sync) and see the change ready to be committed.

      One reason why (2) isn't a complete solution, is that Pythonista doesn't see iCloud in PYTHONPATH. In order to add user-defined modules, I believe they have to go in one of the site-packages directories in the device file system. But for version control of most scripts in Pythonista, the Working Copy sync function should work well with the Pythonista iCloud folder.

      posted in Pythonista
      comfortablynick
      comfortablynick
    • RE: Local scripts cannot be accessed via Files app/document picker

      This would be really useful. Now that Working Copy can sync files from iCloud Drive, my dream would be to someday have all of my Pythonista files in Git.

      posted in Pythonista
      comfortablynick
      comfortablynick
    • RE: Import / Read Google Sheets document

      I would use the Google Sheets Python API. They have a QuickStart example. I haven't done a script for Sheets in Pythonista, but I have done one for Gmail and it worked fine.

      posted in Pythonista
      comfortablynick
      comfortablynick
    • RE: Is possible to run Black on Pythonista?

      I was wondering the same thing, and I finally got this working. I think the problem was with the attrs package. One of the errors made it look like I needed attr (no 's'), but that is a different unrelated package.

      I installed black with Stash pip, as well as attrs and any other package it needed, until I could run black.py without errors.

      I put together this little script to format a document in the editor. I'm sure there's a better way to do it, but this seems to work beautifully when added to the tools menu in Pythonista.

      #!/usr/bin/env python3
      """Format editor contents/selection in Pythonista with Black formatter."""
      import editor
      import black
      import console
      import time
      
      # Options
      LINE_LEN = 88  # Default: 88
      FAST = False  # True = skip syntax check
      
      # Get text and selection
      text = editor.get_text()
      start, end = editor.get_selection()
      selection = text[start:end]
      
      if len(selection) > 0:
          raw_text = selection
      else:
          raw_text = text
      
      try:
          start_tm = time.time()
          formatted = black.format_file_contents(
              raw_text, line_length=LINE_LEN, fast=int(FAST)
          )
      except black.NothingChanged:
          console.hud_alert(
              f"No formatting needed! ({time.time() - start_tm:.4f}s)", "success"
          )
      except Exception as err:
          console.hud_alert(err, "error")
      else:
          new_text = formatted[:-1]
          if len(selection) > 0:
              editor.replace_text(start, end, new_text)
              editor.set_selection(start, start + len(new_text))
          else:
              editor.replace_text(0, len(text), new_text)
              editor.set_selection(start, end)
          console.hud_alert(
              f"Reformatted! ({time.time() - start_tm:.4f}s)", "success")
      
      posted in Pythonista
      comfortablynick
      comfortablynick
    • RE: Calling all gurus

      Sounds like a cool idea; I would love to participate in any way I can.

      posted in Pythonista
      comfortablynick
      comfortablynick
    • RE: It has been 9 months since the latest version

      @JonB said:

      The app was never promised regular updates. It works out of the box to do what it promises to do, and offers a lot of customizability to have it do what you want.

      Well, every app needs regular updates. Most devs have to make tweaks at least with each major iOS version. Then there are changes needed due to new hardware, etc. I'm sure some users will hold off on pulling the trigger on a somewhat pricy app if they see it's not being updated regularly.

      I was looking to get Editorial, but it's been even longer since it has seen an update. There's no way I'm going to pay for an app that hasn't even been updated for the iPhone X screen.

      I hope he does open source Pythonista if he's no longer interested in maintaining it. A great app like this needs to stay at the head of the pack. I'm seeing updates of other scripting apps integrating directly with Siri Shortcuts, and it just reminds me of how awesome it would be to do that with Python instead of JavaScript.

      posted in Pythonista
      comfortablynick
      comfortablynick
    • RE: It has been 9 months since the latest version

      I would also happily pay for a subscription if that helps us get more active development. It would be a shame to have such a wonderful app not be kept up to date. I usually wouldn't even purchase an app that hasn't been updated in 9 months.

      It's nice to see other apps tightly integrating with Shortcuts (Scriptable is a promising app, and Drafts also does well at this). I would much rather automate things with Python than JavaScript. I hope Pythonista eventually gets full x-callback-url support so it can be used more in that regard.

      posted in Pythonista
      comfortablynick
      comfortablynick
    • RE: safari appex.get_web_page_info

      This issue is really annoying me. Oddly enough, it works 100% of the time on my iPad. On my iPhone, however, functions using appex from Safari only work ~25% of the time. It doesn't matter whether I try to get the URL or web page data directly.

      Is there anything I can do to make this work on the iPhone the way it does on the iPad?

      Here's an example of a general script I use to see what comes through the share sheet:

      import appex
      from bs4 import BeautifulSoup
      
      
      def main():
          if appex.is_running_extension():
              print(f'# APPEX DATA #\n{"=" * 15}\n')
              methods = [
                  method for method in dir(appex)
                  if callable(getattr(appex, method)) and
                  method.startswith('get') and method != 'get_input'
              ]
              for method in methods:
                  result = getattr(appex, method)()
                  name = method.partition("_")[2]
                  if result:
                      print(f'{name}\n{"-"*15}')
                      if name == 'web_page_info':
                          for k, v in result.items():
                              if k == 'html':
                                  soup = BeautifulSoup(v, 'html.parser')
                                  v = soup.prettify()
                              print(f'{k}: {v}')
                          print('\n')
                      else:
                          print(f'{result}\n\n')
          else:
              raise ReferenceError(
                  'Requires appex: (must be run from iOS share sheet!)')
      
      
      if __name__ == '__main__':
          main()
      posted in Pythonista
      comfortablynick
      comfortablynick
    • RE: Git support?

      I love being able to use Working Copy and Pythonista together. Is there any way to execute scripts from Working Copy via appex or callback URL (e.g., from Workflow)?

      It's great that we can open the scripts from Working Copy, but it would be a lot more useful if we could execute them without saving a local copy in Pythonista.

      posted in Pythonista
      comfortablynick
      comfortablynick