diff --git a/PixelfedImporter.py b/PixelfedImporter.py index 6dd2dff..9d557aa 100644 --- a/PixelfedImporter.py +++ b/PixelfedImporter.py @@ -96,7 +96,7 @@ def createNewPost(access_token, url, ImageID, ImageDescription): except requests.exceptions.RequestException as e: print(f"An error occurred during the API call: {e}") -def sendImages(Token, url, imagedir, uploadType): +def sendImages(Token, url, imagedir, uploadType, deleteFile): files = getImages(imagedir) tags = getTags("tags.txt") tagDescription = "" @@ -118,6 +118,11 @@ def sendImages(Token, url, imagedir, uploadType): newFileID = newFile.get("id") if uploadType == 1: createNewPost(Token, url, newFileID, tagDescription) + + if deleteFile: + for f in files: + if os.path.exists(f): + os.remove(f) return True if __name__ == "__main__": @@ -128,5 +133,6 @@ if __name__ == "__main__": accessToken = config.get("access_token") imagedir = config.get("image_path") uploadType = config.get("upload_type") - - sendImages(accessToken, url, imagedir, uploadType) \ No newline at end of file + deleteFile = config.get("delete_file") + + sendImages(accessToken, url, imagedir, uploadType, deleteFile) \ No newline at end of file diff --git a/README.md b/README.md index 33ab960..549a11b 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,8 @@ To use this you need a config.json if this cannot be created automatically, here "server_url": "URL TO YOUR PIXELFED", "access_token": "YOUR ACCESS TOKEN", "image_path": "PATH TO YOUR IMAGES", - "upload_type": 0|1 + "upload_type": 0|1, + "delete_file": true|false } ```