omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular
    1. Home
    2. aldoblack

    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 0
    • Followers 0
    • Topics 1
    • Posts 5
    • Best 0
    • Controversial 0
    • Groups 0

    aldoblack

    @aldoblack

    0
    Reputation
    288
    Profile views
    5
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    aldoblack Unfollow Follow

    Latest posts made by aldoblack

    • RE: Script crashes when making bulk upload into local server (Synology NAS)

      @ccc tried but still crashes. This is the code:

      import appex
      import photos
      import requests
      import os
      import editor
      import sys
      from objc_util import *
      
      from datetime import datetime
      
      
      class Synology(object):
          def __init__(self, url, port, account, passwd):
              """
              
              :param url: IP/URL or Synology. So far it only supports HTTP.
              :param port:
              :param account:
              :param passwd:
              :returnv:
              """
              self.url = url
              self.port = port
              
              self.account = account
              self.passwd = passwd
      
              self.sid = None
      
              # self.session = requests.Session()
      
          def login(self):
              print("Logging in...")
      
              param = {
                  "version": "2",
                  "method": "login",
                  "account": self.account,
                  "passwd": self.passwd,
                  "session": "FileStation",
                  "format": "cookie"
              }
      
              url = f"http://{self.url}:{self.port}/webapi/auth.cgi?api=SYNO.API.Auth"
      
              r = requests.get(url, param, verify=False)
              r = r.json()
      
              if not r["success"]:
                  raise Exception("Authenticatoin failed. Note that account with 2FA enabled does not work.")
      
              print("Logging successful.")
      
              self.sid = r["data"]["sid"]
              return self.sid
      
          def upload_file(self, files):
              upload_url = f"http://{self.url}:{self.port}/webapi/entry.cgi?api=SYNO.FileStation.Upload&version=2&method=upload&_sid={self.sid}"
      
              args = {
                  "path": "/home/b",
                  "create_parents": "true",
                  "overwrite": "true"
              }
      
              # Ignpre this ugly code. I am trying to figure out if I can do bulk upload.
              file = {'file': (files[0]["fname"], files[0]["payload"], 'application/octet-stream')}
              # file = [('files', (x["fname"], x["payload"], "application/octet-stream")) for x in files]
      
              r = requests.post(upload_url, data=args, files=file, verify=False)
      
              del upload_url
              del args
              del file
              del r
              del files
      
      
      
      def main():
          # if not appex.is_running_extension():
          #   print("Sript is intended to be un from sharing extension.")
          #   return
      
          print("Starting...")
          s = Synology(url="1.1.1.1", port="1000", account="1", passwd="1")
          s.login()
      
      
          startTime = datetime.now()
      
          all_photos = photos.get_assets()
      
          # images = []
      
          for idx, asset in enumerate(all_photos):
      
              if idx % 100 == 0:
                  print(f"Uploading... {idx}/{len(all_photos)}")
      
              #fname = str(ObjCInstance(asset).valueForKey_('filename'))
              #payload = asset.get_image_data(original=True)
      
              # images = [{"fname": fname, "payload": payload}]
      
              s.upload_file([{"fname": str(ObjCInstance(asset).valueForKey_('filename')), "payload": asset.get_image_data(original=True)}])
              del asset
              # print(fname)
      
          print(datetime.now() - startTime)
      
      if __name__ == "__main__":
          main()
      
      posted in Pythonista
      aldoblack
      aldoblack
    • RE: Next release?

      That's a shame. I just started with Pythonista and I am loving it.

      posted in Pythonista
      aldoblack
      aldoblack
    • RE: Robocopy entire photo directory to NAS?

      So far this is the code that I'm using uploading with Synology REST API. It works well until Pythonista crashes when uploading photos between 900-1000.

      import appex
      import photos
      import requests
      import os
      import editor
      import sys
      from objc_util import *
      
      from datetime import datetime
      
      
      class Synology(object):
          def __init__(self, url, port, account, passwd):
              """
              
              :param url: IP/URL or Synology. So far it only supports HTTP.
              :param port:
              :param account:
              :param passwd:
              :returnv:
              """
              self.url = url
              self.port = port
              
              self.account = account
              self.passwd = passwd
      
              self.sid = None
      
              # self.session = requests.Session()
      
          def login(self):
              print("Logging in...")
      
              param = {
                  "version": "2",
                  "method": "login",
                  "account": self.account,
                  "passwd": self.passwd,
                  "session": "FileStation",
                  "format": "cookie"
              }
      
              url = f"http://{self.url}:{self.port}/webapi/auth.cgi?api=SYNO.API.Auth"
      
              r = requests.get(url, param, verify=False)
              r = r.json()
      
              if not r["success"]:
                  raise Exception("Authenticatoin failed. Note that account with 2FA enabled does not work.")
      
              print("Logging successful.")
      
              self.sid = r["data"]["sid"]
              return self.sid
      
          def upload_file(self, files):
              upload_url = f"http://{self.url}:{self.port}/webapi/entry.cgi?api=SYNO.FileStation.Upload&version=2&method=upload&_sid={self.sid}"
      
              args = {
                  "path": "/home/b",
                  "create_parents": "true",
                  "overwrite": "true"
              }
      
              # Ignore this ugly code. I am trying to figure out if I can do bulk upload in one request.
              file = {'file': (files[0]["fname"], files[0]["payload"], 'application/octet-stream')}
              # file = [('files', (x["fname"], x["payload"], "application/octet-stream")) for x in files]
      
              r = requests.post(upload_url, data=args, files=file, verify=False)
      
      
      
      def main():
          # if not appex.is_running_extension():
          # 	print("Sript is intended to be un from sharing extension.")
          # 	return
      
          print("Starting...")
          s = Synology(url="1.1.1.1", port="2000", account="user", passwd="pass")
          s.login()
              
          startTime = datetime.now()
      
          all_photos = photos.get_assets()
          images = []
      
          for idx, asset in enumerate(all_photos):
      
              if idx % 10 == 0:
                  print(f"Uploading... {idx}/{len(all_photos)}")
      
              fname = str(ObjCInstance(asset).valueForKey_('filename'))
              payload = asset.get_image_data(original=True)
      
              images = [{"fname": fname, "payload": payload}]
      
              s.upload_file(images)
      
              # print(fname)
      
          print(datetime.now() - startTime)
      
      if __name__ == "__main__":
          main()
      
      posted in Pythonista
      aldoblack
      aldoblack
    • Script crashes when making bulk upload into local server (Synology NAS)

      I am writing a script to upload files and photos into my Synology NAS server and during testing the script crashes after a period of time. I have around 1400 photos in my phone and it always crashes between 900-1000. At first I thought that it might be some corrupt file that makes this crash and tested starting from file 800 and onwards but it does not crash.

      Any idea what causes this crash when trying to upload files between 900-1000? There are no error codes, the app just closes.

      posted in Pythonista
      aldoblack
      aldoblack
    • RE: Pythonista (seems to?) run in background if script starts a Picture in Picture video

      Did you find any solution? I am trying to run Pythonista in background as well.

      posted in Pythonista
      aldoblack
      aldoblack