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
-
@lpl I think you can do that with the beta version, isn'it?
You have even Examples/Roll Dice.py
-
@cvp yeah. I'm using this.
-
@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()
-
@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?
-
@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.
-
@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"...
-
for key, value in requests.get(url).json().items(): print(key, value) # or print(f"{key}: {value}")
-
@ccc I knew there was something better π
Edit: print(fβ{key}: {value}β) Refused
Edit: invalid double quote
print(f"{key} : {value}")
-
Thx. Fixed inline above.
-
-
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}.")
-
@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}.")
-
@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"
-
@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
-
@Matteo But the performance is terrible. Try lxml.
-
@lpl Hi, sorry but I don't know lxml library, never used it. But I'm agree with you that a c compiled library is faster than a pure python equivalent code. However I'm not completely agree with you about "terrible" performance. In my opinion I would consider with "terrible" performance a pure python code that runs for some hours instead of some seconds of an equivalent c compiled code. Which kind of test have you performed to state that the performance is terrible?
In other words, with practical example: let's suppose that an algorithm has time complexity O(n^3) and you write a pure python code and the equivalent C code that both execute the algorithm. Well, based on the input (that, simplifying, can be 10kbyte, 100 kbyte, 1000 kbyte and so on), how much time the execution of the pure python code costs compared to the C one if both are executed on same machine and in the same conditions (machine with same X% free RAM and CPU power)?
Thank you
Bye -
@lpl What exactly are you trying to do in Pythonista where XML performance is a showstopper? It would be good to have real world use cases to use in trying to convince Apple to be more reasonable in its app reviews.
-
@Matteo Try cchardet https://github.com/PyYoshi/cChardet/blob/master/README.rst . 0.37 call/s VS 1467.77 call /s β 1/3600
-
@ccc How about Pandas?
-
I am afraid that I do not understand. Pyto has Pandas but not lxml. What is the use case?