omz:forum

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

    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 4
    • Posts 9
    • Best 0
    • Controversial 0
    • Groups 0

    jrh147

    @jrh147

    0
    Reputation
    717
    Profile views
    9
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    jrh147 Unfollow Follow

    Latest posts made by jrh147

    • Method takes exactly 2 arguments...but it doesn't...

      I have a script that works great when run from within Pythonista. It calls another script by passing three arguments to it:

      final = kraken(response['kraked_url'], path, name)
      

      And this is what kraken() looks like:

      def kraken(image_link,path,name):
      

      However, when I run it as an iOS extension (which is what I really want to do), it ends up giving me this error:

      TypeError: kraken() takes exactly 2 arguments (3 given)
      

      What can I do to fix this?

      posted in Pythonista
      jrh147
      jrh147
    • Simple Button to Choose Path

      Completely new to UI Buttons and what not. I went through and created an interface with a couple buttons and ALL I want to be able to do is to grab the value of the button pushed so I can use it for a file path...

      This seems super easy but I can't find anything anywhere that simply describes how to do it. All I can do is change the title of it to "Hello"! LOL

      Thank you for any help...

      posted in Pythonista
      jrh147
      jrh147
    • RE: Dropbox access .txt file

      I'm trying to do the same here but keep running into a 401 error.

      I followed the above advice, and run the dropboxlogin.py script to test it out and I just get the error. I found this on Linking Dropbox and Pythonista but the instructions seemed to have change for Dropbox.

      I created the app, generated a user token, set it to full Dropbox and then changed the dropboxlogin script to show the app key, the app secret and dropbox for access. That page says you can run the script to test it out but I get a 401 error.

      I try and run the script above, the one where you change the filename and again a 401 error. I really want to be able to do this, to read in data from a CSV on Dropbox, but can't seem to find clear instructions on how to get started. Thanks in advance.

      posted in Pythonista
      jrh147
      jrh147
    • Encoding images in Base64

      I need to encode images in base64 for the purposes of passing them through an x-callback-url. I have this code but it's not working:

      #coding: utf-8
      import workflow
      import clipboard
      import photos
      import base64
      
      source_selection = workflow.get_variable('source')
      
      if source_selection == 'photo':
      	image_selection = photos.pick_image()
      else:
      	image_selection = clipboard.get_image()
      	if not image_selection:
      		console.alert('No Image', 'Clipboard does not contain an image')
      		
      w, h = image_selection.size
      
      encoded = base64.b64encode(str(image_selection)
      
      workflow.set_variable('encodedImage', str(encoded))
      		
      workflow.set_variable('origSize', str(w))
      

      Any ideas?

      posted in Editorial
      jrh147
      jrh147
    • RE: Parsing YAML with Python

      Wow. Amazingly thorough help. Thank you so much. I hadn't thought of additional "---" but appreciate the code should that be a problem in the future. Everything works as expected so again, thank you.

      posted in Editorial
      jrh147
      jrh147
    • RE: Parsing YAML with Python

      Oh nice. Thanks! First weekend using Python (if you couldn't tell)

      And I spoke too soon. It worked fine if my text only had YAML front matter. If it has anything after the second '---' I get the "Error Scanner while scanning a block scalar ... " Error

      I think this is because it expects the entire thing to be YAML. Anyway I can stop scanning up to the second ---.

      posted in Editorial
      jrh147
      jrh147
    • RE: Parsing YAML with Python

      That worked great. For anyone following along this is what I ended up with. It checks to see whether or not the key 'link' exists before adding it to the clipboard as well. Thanks!

      #coding: utf-8
      import yaml
      import editor
      import clipboard
      
      m = yaml.load(editor.get_text().replace('-', ''))
      
      tweet = m['title']
      
      if "link" in m:
      	tweet = tweet + ' ' + m['link']
      
      clipboard.set(tweet)
      
      posted in Editorial
      jrh147
      jrh147
    • RE: Parsing YAML with Python

      @ccc said:

      Try this:

      my_dict = yaml.load(editor.get_text())

      I got the error code "expected a single document, but found another document" pointing to the "---" as the culprits

      posted in Editorial
      jrh147
      jrh147
    • Parsing YAML with Python

      I have a simple Markdown file with YAML header that looks something like this:

      ---
      title: "Mary had a little lamb"
      link: http://google.com
      ---
      

      I want to extract some of the YAML data to use later in a workflow. So far I have this but it just gives me errors. Ideally once I extract the title key I would also like to strip the quotation marks but not sure how to do that yet either. Maybe there is an easier way?

      #coding: utf-8
      import console
      import yaml
      import editor
      
      from StringIO import StringIO
      text = StringIO(editor.get_text())
      
      doc = list(yaml.load_all(text))
      
      tweet_link = doc["link"]
      tweet_title = doc["title"]
      
      
      console.hud_alert(tweet_link)
      
      posted in Editorial
      jrh147
      jrh147