omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    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.


    Time to release a new version to App Store

    Pythonista
    7
    56
    23862
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • cvp
      cvp @Matteo last edited by

      @Matteo The doc I use is only the Apple developer doc...You find there all classes documentation.
      Often, I only type dir(ObjCInstance(any Pythonista object)) and I spend some time to check the methods and properties listed

      1 Reply Last reply Reply Quote 0
      • cvp
        cvp @Matteo last edited by cvp

        @Matteo You can't imagine what you can find with our big friend Google
        Try this little script, only to see what you could do with Pythonista
        And read this interesting topic and this one

        # https://rambo.codes/ios/2019/01/11/hacking-with-private-apis-on-ipad.html
        import ui
        from objc_util import *
        
        NSBundle = ObjCClass('NSBundle')
        UIWindow = ObjCClass('UIWindow')
        UIColor  = ObjCClass('UIColor')
        
        window = UIWindow.new()
        window.setBackgroundColor_(UIColor.darkGrayColor())
        NSBundle.bundleWithPath_('/System/Library/PrivateFrameworks/SpringBoardUIServices.framework').load()
        controller = ObjCClass('SBUIPowerDownViewController').new()
        window.setRootViewController_(controller)
        window.setHidden_(False)
        
        def close():
        	window.setHidden_(True)
        	
        ui.delay(close,5)
        
        1 Reply Last reply Reply Quote 2
        • ?
          A Former User @Matteo last edited by

          @Matteo Like this? https://pillow.readthedocs.io/en/stable/releasenotes/3.4.0.html#append-images-to-gif

          And for siri, we can get weather from different resources. Or we just roll the dice to make a decision.

          cvp 1 Reply Last reply Reply Quote 1
          • cvp
            cvp @Guest last edited by

            @lpl said:

            for siri, we can get weather from different resources

            Sorry, I don't understand what you want to do with Siri

            ? 1 Reply Last reply Reply Quote 0
            • ?
              A Former User @cvp last edited by

              @cvp
              -- Hi, siri how is the weather?
              -- Here are some reports from different resources.

              -- Hi, siri. Should I go with her?
              -- I roll the dice. The answer is yes.

              cvp 1 Reply Last reply Reply Quote 0
              • cvp
                cvp @Guest last edited by cvp

                @lpl I think you can do that with the beta version, isn'it?

                You have even Examples/Roll Dice.py

                ? 1 Reply Last reply Reply Quote 0
                • ?
                  A Former User @cvp last edited by

                  @cvp yeah. I'm using this.

                  cvp 1 Reply Last reply Reply Quote 0
                  • cvp
                    cvp @Guest last edited by cvp

                    @lpl you can use requests to get internet info in Shortcuts, even in background mode

                    #!python3
                    import requests
                    import shortcuts
                    def main():
                    	if shortcuts.is_shortcut():
                    		#shortcuts.set_tap_action(shortcuts.ACTION_SHOW_RESULTS)
                    		url = 'https://www.google.be/search?client=safari&q=meteo+local'
                    		r = requests.get(url)
                    		html = r.text
                    		shortcuts.set_html_output(html)
                    if __name__ == '__main__':
                    	main()
                    
                    ? 1 Reply Last reply Reply Quote 0
                    • ?
                      A Former User @cvp last edited by A Former User

                      @cvp Sorry, I don't like shortcuts and it is hard to debug on shortcuts. But I think I'll try this, that sounds interesting. Do you have a documentation about this module?

                      cvp 2 Replies Last reply Reply Quote 0
                      • cvp
                        cvp @Guest last edited by cvp

                        @lpl It is a standard module of the beta version.
                        Thus you find documentation by the normal way:

                        • select the word shortcuts in your edited script, choose help, as usual.
                        • Or the ? In the console part, then "What’s New in Pythonista"

                        Edit: shortcuts is not the Apple app Shortcuts but a module added by omz in the beta, thus is not difficult to debug. In background mode = without running the full Pythonista app.

                        1 Reply Last reply Reply Quote 0
                        • cvp
                          cvp @Guest last edited by cvp

                          @lpl you can even run a Pythonista script with Siri without using the new Shortcuts module:

                          #!python3
                          import ast
                          import requests
                          #import shortcuts
                          city = 'Waterloo,be'
                          url = "http://api.openweathermap.org/data/2.5/weather?q="+city+"&APPID=beb97c1ce62559bba4e81e28de8be095"
                          r = requests.get(url)
                          dict = ast.literal_eval(r.text)
                          for k in dict:
                          	print(k,dict[k])
                          

                          Edit: you can run and thus test this script in Pythonista normal mode, then configure as a Siri shortcut linked to a sentence, like "get my weather"...

                          1 Reply Last reply Reply Quote 0
                          • ccc
                            ccc last edited by ccc

                            for key, value in requests.get(url).json().items():
                                print(key, value)  # or
                                print(f"{key}: {value}")
                            
                            cvp 1 Reply Last reply Reply Quote 0
                            • cvp
                              cvp @ccc last edited by cvp

                              @ccc I knew there was something better 😀

                              Edit: print(f”{key}: {value}”) Refused

                              Edit: invalid double quote

                              	print(f"{key} : {value}")
                              
                              1 Reply Last reply Reply Quote 0
                              • ccc
                                ccc last edited by

                                Thx. Fixed inline above.

                                ? 1 Reply Last reply Reply Quote 0
                                • ?
                                  A Former User @ccc last edited by

                                  @cvp try f-str
                                  f"http://api.openweathermap.org/data/2.5/weather?q={city}&APPID=beb97c1ce62559bba4e81e28de8be095"

                                  cvp 1 Reply Last reply Reply Quote 0
                                  • ccc
                                    ccc last edited by

                                    import location, requests, speech
                                    
                                    loc = location.reverse_geocode(location.get_location())
                                    city_country = "{City},{Country}".format(**loc[0])
                                    print(f"Weather in {city_country}:")
                                    url = "http://api.openweathermap.org/data/2.5/weather?APPID=beb97c1ce62559bba4e81e28de8be095&q="
                                    weather = requests.get(url + city_country).json()
                                    for key, value in weather.items():
                                        print(f"{key}: {value}")
                                    speech.say(f"It is currently {weather['weather'][0]['main']} in {city_country}.")
                                    
                                    cvp 1 Reply Last reply Reply Quote 2
                                    • cvp
                                      cvp @ccc last edited by

                                      @ccc if you want to use Siri shortcut, you can, instead of speech, use

                                      shortcuts.set_spoken_output(f"It is currently {weather['weather'][0]['main']} in {city_country}.")
                                      
                                      1 Reply Last reply Reply Quote 0
                                      • cvp
                                        cvp @Guest last edited by cvp

                                        @lpl yes, for me this is ok and better than my ..."+city+"... thanks for advice

                                        city = 'Waterloo,be'
                                        url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&APPID=beb97c1ce62559bba4e81e28de8be095"
                                        
                                        1 Reply Last reply Reply Quote 0
                                        • Matteo
                                          Matteo last edited by ccc

                                          @lpl ok yes you are right sometimes it is not possible to do something with current versions of some libs in Pythonista, the only thing I can suggest is to try searching alternatives in Python world, you should search for some pure-python libs that can help you about your specific task: trust me, in Python world someone thinks something, and it already exists at 99,999% (python is so famous...;-))

                                          @cvp @ccc and many others, thanks that you continue to share useful info and propose code with which many other users can experiment!

                                          Bye bye

                                          ? 1 Reply Last reply Reply Quote 1
                                          • ?
                                            A Former User @Matteo last edited by

                                            @Matteo But the performance is terrible. Try lxml.

                                            Matteo 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post
                                            Powered by NodeBB Forums | Contributors