• paultopia

    @mikael That would be cool! I can stick this into a proper repo if you want ...

    posted in Pythonista read more
  • paultopia

    A common task I have: I want to write down some numbers or a simple formula of some kind, and then go ahead and do something with the numbers or solve a simple equation with them. Examples: writing down how much I paid for each bill in a note or drafts, then summing them; working out a simple algebra equation for something like a mildly complicated tax/tip situation and then solving it.

    There are lots of calculators in the built-in Pythonista examples, but none which quite met my needs for dealing with pre-written text. There are also special-purpose apps for things like ticker-tape calculators, but I don't think any of them do algebra, and, besides, why pay for a separate app when pythonista is right there plus has the full power of sympy available?

    So I wrote my own little script. Takes share sheet or clipboard input string. If it's just a list of numbers, sums them. If there are arithmetic operators, evaluates the expression. If it's a simple one-variable expression, assumes it's an equation with the other side zero and feeds it to sympy to solve. If it's a one-variable equation, back to sympy. Should handle most basic day-to-day ticker-tape math needs, in only 75-ish lines of actual code.

    https://gist.github.com/paultopia/16e69f9f72ad0a5000fa5b4575ddeee2

    posted in Pythonista read more
  • paultopia

    From the safari share sheet, the following snippet of code

    url = appex.get_url()
    print(url)
    if url is None:
        url = clipboard.get()
    print(url)
    

    if I just run it straight from a web page in mobile safari, it prints None and None

    But if I first copy the url to the clipboard, it prints the URL both times.

    Is there some weird multithreading thing happening here? Can't figure out why else this would be happening.

    posted in Pythonista read more
  • paultopia

    I've been doing some experiments with sharing image files into pythonista from the built-in photos app, to do things like zip up and share elsewhere. But I seem to get inconsistent data.

    Here's my very simple experimental code:

    import appex
    
    def test_save_images():
        images = appex.get_images_data()
        for idx, image in enumerate(images):
            filename = "zfile-" + str(idx) + ".jpg"
            with open(filename, "wb") as ot:
                ot.write(image)
    
    if __name__ == '__main__':
        test_save_images()
    
    

    Then I go into the built-in photos app, select two of photos, and share them into pythonista via "run pythonista script."

    So far, I've done this twice, and neither time has it worked properly.

    The first time, instead of saving both photos into the pythonista filesystem, it saved one photo, twice.

    The second time, it saved both photos, but it saved a total of three photos---it saved one photo once, and one photo twice.

    I obviously find this a little confusing. Why is get_images_data not passing the number of photos that I would expect into the script?

    posted in Pythonista read more
  • paultopia

    Dear kind leader @omz --- now that this has happened, is there any chance you could bundle tweepy with the next version of Pythonista?

    posted in Pythonista read more
  • paultopia

    Hey y'all. I've banged together a simple Dropbox-syncing weight tracker with moving averages (like the old "Hacker's Diet"). The idea is to just stick it in your phone in the long-press menu and then it should be minimal friction to track weight.

    https://gist.github.com/paultopia/95a4c659f2d1971e2e08711d807065d2

    (Though come to think of it, I haven't tested that the dialog menu works right on long-press, or that it sizes right on the phone screen, I just banged it out and tested on the ipad... but I imagine it should work fine on phone)

    posted in Pythonista read more
  • paultopia

    Simple tweetstorm poster (break up long posts into numbered tweets), making use of the lovely api wrapper and ui wrapper omz built into the app. https://gist.github.com/paultopia/13263b605862121e11a737155b2c7779

    posted in Pythonista read more
  • paultopia

    Super-annoying behavior on Twitter: the sort of person who follows you to get you to follow them back and inflate their follower count/promote their junk, then silently unfollows you.

    Problem: twitter terms of service forbid automated unfollowing, while it would be pretty easy to do that anyway, why draw an account ban unnecessarily?

    Solution: find people whom you follow but who don't follow you back, open their twitter pages in a browser tab and decide whether to keep or get rid of them individually, but in a loop. Complies with the letter if not the spirit of Twitter terms.

    Could use a real UI or at least a button or something, but I haven't yet learned how to use the UI module, so.

    https://gist.github.com/paultopia/236bfe61782cd7e5ad7f0a4f00edd202

    posted in Pythonista read more

Internal error.

Oops! Looks like something went wrong!