omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. henryaukc
    3. Topics

    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.


    • Profile
    • Following 1
    • Followers 1
    • Topics 7
    • Posts 33
    • Best 3
    • Controversial 0
    • Groups 0

    Topics created by henryaukc

    • henryaukc

      Any script to read the old Mac iPhotos files and transfer to my iPad Pro?
      Pythonista • • henryaukc

      5
      0
      Votes
      5
      Posts
      761
      Views

      cvp

      @henryaukc to know name of external folder, you have to create this little script on this folder and run it

      import editor print(editor.get_path())

      You will get something like

      '/private/var/mobile/Library/LiveFiles/com.apple.filesystems.userfsd/xxxxxxx/'
    • henryaukc

      Trying to move to Pyto but….
      Pythonista • • henryaukc

      10
      1
      Votes
      10
      Posts
      3320
      Views

      ccc

      First answer on https://github.com/ColdGrub1384/Pyto/blob/main/docs/faq.rst

    • henryaukc

      How to have the code name of a certain Emoji?
      Pythonista • • henryaukc

      3
      0
      Votes
      3
      Posts
      2009
      Views

      henryaukc

      Got it! Thanks

    • henryaukc

      Upload any files from Any App via Pythonista Script to my Raspberry Pi connected Harddisk
      Pythonista • • henryaukc

      8
      0
      Votes
      8
      Posts
      6315
      Views

      henryaukc

      It works very well. Thanks a lot!

    • henryaukc

      How to login Facebook with Request module for further access?
      Pythonista • • henryaukc

      4
      0
      Votes
      4
      Posts
      4245
      Views

      henryaukc

      Sorry, maybe I was not checking thoroughly or it is not working anymore, my script to login facebook fails now....

      Can someone shed some light on it?

      import requests from urllib.parse import urlparse import os import pickle import datetime class MyLoginSession: """ a class which handles and saves login sessions. It also keeps track of proxy settings. It does also maintine a cache-file for restoring session data from earlier script executions. """ def __init__(self, loginUrl, loginData, loginTestUrl, loginTestString, sessionFileAppendix = '_session.dat', maxSessionTimeSeconds = 30 * 60, proxies = None, userAgent = 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1', debug = True): """ save some information needed to login the session you'll have to provide 'loginTestString' which will be looked for in the responses html to make sure, you've properly been logged in 'proxies' is of format { 'https' : 'https://user:pass@server:port', 'http' : ... 'loginData' will be sent as post data (dictionary of id : value). 'maxSessionTimeSeconds' will be used to determine when to re-login. """ urlData = urlparse(loginUrl) self.proxies = proxies self.loginData = loginData self.loginUrl = loginUrl self.loginTestUrl = loginTestUrl self.maxSessionTime = maxSessionTimeSeconds self.sessionFile = urlData.netloc + sessionFileAppendix self.userAgent = userAgent self.loginTestString = loginTestString self.debug = debug self.login() def modification_date(self, filename): """ return last file modification date as datetime object """ t = os.path.getmtime(filename) return datetime.datetime.fromtimestamp(t) def login(self, forceLogin = False): """ login to a session. Try to read last saved session from cache file. If this fails do proper login. If the last cache access was too old, also perform a proper login. Always updates session cache file. """ wasReadFromCache = False if self.debug: print('loading or generating session...') if os.path.exists(self.sessionFile) and not forceLogin: if os.path.getsize(self.sessionFile) > 0: time = self.modification_date(self.sessionFile) if self.debug: print('loginURL:' + loginUrl) # only load if file less than 30 minutes old lastModification = (datetime.datetime.now() - time).seconds if lastModification < self.maxSessionTime: with open(self.sessionFile, "rb") as f: self.session = pickle.load(f) wasReadFromCache = True if self.debug: print("loaded session from cache (last access %ds ago) " % lastModification) if not wasReadFromCache: self.session = requests.Session() self.session.headers.update({'user-agent' : self.userAgent}) res = self.session.post(self.loginUrl, data = self.loginData, proxies = self.proxies) if self.debug: print('created new session with login' ) self.saveSessionToCache() # test login res = self.session.get(self.loginTestUrl) if res.text.find(self.loginTestString) > 0: print(res.text) raise Exception("could not log into provided site '%s'" " (did not find successful login string)" % self.loginUrl) def saveSessionToCache(self): """ save session to a cache file """ # always save (to update timeout) with open(self.sessionFile, "wb") as f: pickle.dump(self.session, f) if self.debug: print('updated session cache-file %s' % self.sessionFile) def retrieveContent(self, url, method = "get", postData = None): """ return the content of the url with respect to the session. If 'method' is not 'get', the url will be called with 'postData' as a post request. """ if method == 'get': res = self.session.get(url , proxies = self.proxies) else: res = self.session.get(url , data = postData, proxies = self.proxies) res.encoding = 'utf-8' # the session has been updated on the server, so also update in cache self.saveSessionToCache() return res if __name__ == "__main__": # proxies = {'https' : 'https://user:pass@server:port', # 'http' : 'http://user:pass@server:port'} # after I checking the source code of Facebook login form, I changed 'user' to 'email' and it also failed loginData = { 'user' : 'My Login Name', 'password' : 'My Password'} # these are not my real login & password loginUrl = 'https://www.facebook.com/login.php' loginTestUrl = 'https://www.facebook.com/home.php?ref=home' failedStr = 'facebook.com/login/' s = MyLoginSession(loginUrl, loginData, loginTestUrl, failedStr, #proxies = proxies ) res = s.retrieveContent('https://www.facebook.com/home.php?ref=home') res.encoding = 'utf-8' print(res.text) ''' <input type="text" class="inputtext _55r1 inputtext _1kbt inputtext _1kbt" name="email" id="email" tabindex="1" placeholder="Email address or phone number" value="" autofocus="1" aria-label="Email address or phone number"> </div> <div class="clearfix _5466 _44mg"> <input type="password" class="inputtext _55r1 inputtext _1kbt inputtext _1kbt" name="pass" id="pass" tabindex="1" placeholder="Password" aria-label="Password"> '''```
    • henryaukc

      [Feature Request] Password to lock Pythonista App for Parental Control
      Pythonista • • henryaukc

      20
      0
      Votes
      20
      Posts
      9243
      Views

      cvp

      @henryaukc said

      how to use objc to remove the X button?

      Please, for the fun, try this script and you will see the start/stop button disappear

      from objc_util import * import ui w=ObjCClass('UIApplication').sharedApplication().keyWindow() main_view=w.rootViewController().view() def get_toolbar(view, indent): #get main editor toolbar, by recursively walking the view sv=view.subviews() for v in sv: #print(indent,v._get_objc_classname()) if 'UIImageView' in str(v._get_objc_classname()): # <UIImage:0x281108240 named(main: Stop2) {28, 28}> #print(v.image()) o = v.image() if o: with ui.ImageContext(32,32) as ctx: o.drawAtPoint_(CGPoint(0,0)) ui_image = ctx.get_image() #ui_image.show() #print() if 'Stop2' in str(o): #print('+'*40) OMBarButton = v.superview().superview() OMBarButton.removeFromSuperview() tb= get_toolbar(v, indent+' ') get_toolbar(main_view, '')

    • henryaukc

      Play Video on iOS Quick Look?
      Pythonista • • henryaukc

      9
      0
      Votes
      9
      Posts
      6973
      Views

      henryaukc

      @abcabc the function "download_file" works like a charm! So I have updated my script with it. Thanks a lot.

      https://gist.github.com/henryaukc/6fd00b8baee4c069a2b44e574829469f

      BTW, can I know why my function can't work in that particular case? I can use it to download the same video from sd_src but not hd_src so I think it may due to memory constraint? And it is ok to download in pythonista environment but not through appex, is it some memory constraint when calling the app extension or some memory leak problems in triggering the scripts through extension? I just wanna learn more about it. Thanks

      def download_file(url, tmpfile=None): if not tmpfile: local_filename = url.split('/')[-1] else: local_filename = tmpfile with open(local_filename, 'wb') as f: r = requests.get(url, stream=True) total_length = r.headers.get('content-length') if not total_length: print("Content mode...") f.write(r.content) else: print("Chunk mode...") # the below is used when getting that link dl = 0 total_length = float(total_length) for chunk in r.iter_content(1024): dl += len(chunk) f.write(chunk) return local_filename