• eddo888

    would be awesome if editorial supported ifiles integration, either "icloud drive" or "on 'my iphone"

    then we could use WorkingCopy for git !

    posted in Editorial read more
  • eddo888

    @Daniel.Dalsgaard

    works better using python3
    python2 is great but not perfect

    posted in Pythonista read more
  • eddo888

    @MartinPacker

    Standards are meant to be broken, software darwinisim in action. :-)

    posted in Editorial read more
  • eddo888

    two excellent modules to use are

    • requests , to retrieve html content
    • beautiful soup (bs4), to parse html content

    you can load these with StaSh and use "pip install requests bs4"

    posted in Pythonista read more
  • eddo888

    you can call pythonista from shortcuts and get a reply from pythonista,

    here is a client pythonista app, put in the home folder in the "on the iphone" section

    #!/usr/bin/env python
    # sys.args[0]=workflow.py
    
    import sys,json,urllib
    from datetime import datetime
    import console,webbrowser,clipboard
    
    def main():
        console.clear()
        console.set_font('Menlo',12)
        console.set_color(1,1,1)
        
        #print json.dumps(sys.argv, indent=4)
        
        dtf = '%Y-%m-%d %H:%M:%S'
        output = dict(
        when=datetime.now().strftime(dtf),
        args=sys.argv
        )
        
        result = json.dumps(output,indent=4)
        print(result)
        
        x_callback=sys.argv[-1]
        
        if not '://' in x_callback:
            return
            
        url = x_callback + '?argv=' + urllib.quote(result)
        
        webbrowser.open(url)
        
    if __name__ == '__main__': main()
    

    here is the workflow,

    x-callback-url = "pythonista://workflow.py?action=run&argv=1&argv=2"

    note the change to the x-success parameter
    "success key"=args

    posted in Pythonista read more
  • eddo888

    will you support task notation for markdown ?

    • [x] done
    • [ ] not done

    translates to checkboxes in html/pdf

    is used on github a lot

    posted in Editorial read more
  • eddo888

    yes please

    posted in Editorial read more
  • eddo888

    yes please !

    posted in General Discussion read more
  • eddo888

    install StaSh then you can mkdir ~/.aws
    and edit ~/.aws/credentials

    https://forum.omz-software.com/topic/1919/stash-shell-like-an-expert-in-pythonista

    posted in Pythonista read more
  • eddo888

    would love to see editor code folding
    screen realestate on an idevice is precious
    folding would help maximize this

    posted in Pythonista read more
  • eddo888

    https://crossbar.io

    event and rpc based realtime comms

    posted in Pythonista read more
  • eddo888

    Hi, yes you can' the trick if your using workflow is to use a custom x-success callback that is "args" which will allow pythonista to return the value.

    here is a sample pythonista script that will return a result to workflow.io

    #!/usr/bin/env python
    # workflow.py
    
    import sys,json,urllib
    from datetime import datetime
    import console,webbrowser,clipboard
    
    def main():
        console.clear()
        console.set_font('Menlo',12)
        console.set_color(1,1,1)
        
        #print json.dumps(sys.argv, indent=4)
        
        dtf = '%Y-%m-%d %H:%M:%S'
        output = dict(
            when=datetime.now().strftime(dtf),
            args=sys.argv
        )
        
        result = json.dumps(output,indent=4)
        print(result)
        
        x_callback=sys.argv[-1]
        
        if not '://' in x_callback:
            return
            
        url = x_callback + '?argv=' + urllib.quote(result)
        
        webbrowser.open(url)
        
    if __name__ == '__main__': main()
    

    and to call is use this x-callback-url request

    pythonista://workflow.py?action=run&argv=1&argv=2
    

    Here is a dropbox link to a workflow.io flow that uses the above pythonista workflow.py code.

    workflow.io to pythonista.py
    Cheers Dave.

    posted in Pythonista read more
  • eddo888

    @ywangd pip tls 1.2 upgrade
    Hi, recently pypi enforced TLSv1.2 so now old TLSv1.0 clients can't connect. Could you please update the pip client to work with TLSv1.2 ?

    Cheers Dave.

    posted in Pythonista read more
  • eddo888

    Thanks for taking the time to respond and guide, I hope you have a fun weekend. Cheers Dave

    posted in Pythonista read more
  • eddo888

    def params(data):
        if len(data) == 0:
            return ''
        p = '&'.join(
            map(
                lambda x: 
                    '%s=%s'%(x,urllib.quote(data[x])),
                data.keys()
            )
        )
        print data
        print urllib.urlencode(data)
        print p
        
        return '?%s'%p
    
    

    yields

    {'statement': 'select * from MyTable'}
    statement=select+%2A+from+MyTable
    statement=select%20%2A%20from%20MyTable
    

    the client receiving the params preferrs %20 to +

    posted in Pythonista read more
  • eddo888

    cheers thought i was in confluence not markdown :-)

    posted in Pythonista read more
  • eddo888

    here is my uodated and sligjtly modified x_callback_url.py

    # coding: utf-8
    import swizzle
    from objc_util import *
    import sys, re, os, argparse
    import ctypes, json, urllib, uuid, urllib
    import webbrowser 
    
    def argue():
        parser = argparse.ArgumentParser()
    
        parser.add_argument('-v', '--verbose',  action='store_true',  help='verbose mode')
        parser.add_argument('-t', '--test',    action='store_true',  help='run test')
        
        return parser.parse_args()
    
    def params(data):
        if len(data) == 0:
            return ''
        p = '&'.join(
            map(
                lambda x: 
                    '%s=%s'%(x,urllib.quote(data[x])),
                data.keys()
            )
        )
        return '?%s'%p
    
    def reverse(url):
        query = NSURLComponents.componentsWithURL_resolvingAgainstBaseURL_(nsurl(url), False)
        parameters = dict()
        if query.queryItems() is not None:
            for queryItem in query.queryItems():
                parameters[str(queryItem.name())] = str(queryItem.value())
        return parameters
    
    def open_url(url, handler):
        global _handler
        global _requestID
        _requestID = uuid.uuid1()
        _handler = handler
        x_success = urllib.quote('pythonista://?request=%s'%_requestID)
        url_with_uuid = url.replace('?','?x-success=%s&'%x_success)
        #sys.stderr.write('> %s\n'% url_with_uuid)
        webbrowser.open(url_with_uuid)
    
    def openPythonistaURL_(_self, _sel, url):
        url_str = str(ObjCInstance(url))
        #sys.stderr.write('< %s\n'%url_str)
        global _call_me, _handler, _requestID
    
        if '?request=%s'%_requestID in url_str:
            url_str = url_str.replace('?request=%s&'%_requestID, '?')
            parameters = reverse(url_str)
            if _handler:
                _handler(parameters)
            return True
            
        elif _call_me in url_str:
            #print url_str
            parameters = reverse(url_str)
            x_parameters = dict()
            for x in [
                'x-source',
                'x-success',
                'x-error',
                'x-cancel',
                'x-script',
            ]:
                if x in parameters.keys():
                    x_parameters[x] = parameters[x]
                    del parameters[x]
            
            #print '%s\n%s'%(
            #    json.dumps(x_parameters),
            #    json.dumps(parameters)
            #)
            
            if 'x-script' not in x_parameters.keys():
                return
            
            try:
                import importlib
                mod = importlib.import_module(
                    x_parameters['x-script']
                )
                res = str(mod.main(parameters))
                url=x_parameters['x-success']+'?args=%s'%urllib.quote(res)
            except:
                error=str(sys.exc_info()[0])
                url=x_parameters['x-error']+'?args=%s'%urllib.quote(error)
                
            #print url
            webbrowser.open(url)
            return True
    
        else:
            #print('original url=%s'%url_str)
            obj = ObjCInstance(_self)
            original_method = getattr(obj, 'original'+c.sel_getName(_sel), None)
            if original_method:
                _annotation = ObjCInstance(annotation) if annotation else None
                return original_method(
                    ObjCInstance(app), 
                    ObjCInstance(url), ObjCInstance(source_app), 
                    _annotation
                )
            return
    
    def test():
        data={
            'statement' : 'select * from MyTable'
        }
        
        url='generaldb://x-callback-url/execute-select-statement' + params(data)
        print url
            
        def myhandler(parameters):
            print parameters
            for row in parameters['rows'].split('\n'):
                print row
            return
        
        open_url(url,myhandler)
        
    def setup():
        global NSURLComponents, _call_me, _handler, _requestID
        _call_me = 'pythonista://x-callback-url'
        _handler = None
        _requestID = None
        NSURLComponents = ObjCClass('NSURLComponents')
        appDelegate = UIApplication.sharedApplication().delegate()
        
        # Do the swizzling
        cls = ObjCInstance(c.object_getClass(appDelegate.ptr))
        swizzle.swizzle(
            cls, 
            'openPythonistaURL:', openPythonistaURL_
        )
        #print 'swizzled'
        return
    
    def main():
        setup()
        args = argue()
        if args.test : test(); return
        print 'setup complete:'#, sys.argv
        #webbrowser.open('workflow://')
        return    
    
    if __name__ == '__main__': main()
    
    

    posted in Pythonista read more
  • eddo888

    ended up using
    openPythonistaURL:
    instead of
    application:openURL:sourceApplication:annotation:

    cheers D

    posted in Pythonista read more
Internal error.

Oops! Looks like something went wrong!