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.
Share - Copy raw text from URL (my gist helper)
-
I am just sharing this because I find it useful script for getting the raw text of a gist when on a mobile device. Selecting/copying etc... in GitHub does not play so nicely with mobile devices. At least thats my experience. This is a quick and dirty tool and is meant to be. It's more for when I just want to look at a gist in Pythonista and run it out of curiosity. There are many other ways to achieve the same result. Still pretty easy. This way is just pretty fast for me. I have workflow app for example, but often I am just curious. I dont want to add it to workflow etc...
Also, if you are a novice like me, shows how you can do some amazing things very easy in Pythonista. (Well, its not so amazing, but the requests lib is doing some amazing things for you)
import requests import clipboard import console ''' Get Raw Text From URL A wrench script to copy the text of a url to the clipboard. I did this so I can get the text of a gist quickly. To use, when you are viewing the gist in a web browser, click the raw button on the page. Then use the share btn on the page to copy the url. Then run this scipt, the script does a very weak test to see if it should fill in the input_alert for you. otherwise paste or type it in. Then requests attempts to get the url. If the status_code == 200, means we got something. A hud is displayed saying how many bytes where copied to the clipboard. Look, this is just a quick and dirty tool i did for my own use. I know there are many ways to achieve the same result, using eg. the share sheet Maybe there is an easy way to get the text of the gist without going to the raw page. I am not sure. Could have also given an option to put the text into a file and open it in the editor. But I wanted to keep it simple for myself. I already have a wrench item to quickly create a new file in a particular dir. @Phuket2 Pythonistia Forum ''' if __name__ == '__main__': clip_txt = clipboard.get() # do a simple lame test to see if we think we have a url of interest # on the clipboard. Just saves having to do a paste if not clip_txt.startswith('https://gist'): clip_txt = "" url = console.input_alert('Enter URL of raw text', "", clip_txt) resp = requests.get(url, timeout=5) if resp.status_code != 200: # I think this is the correct way to handle a requests error. requests.raise_for_status() clipboard.set(resp.text) console.hud_alert('{} bytes copied'.format(len(resp.text)))