summaryrefslogtreecommitdiffstats
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rwxr-xr-xmain.py46
1 files changed, 35 insertions, 11 deletions
diff --git a/main.py b/main.py
index f47af9a..64602d6 100755
--- a/main.py
+++ b/main.py
@@ -11,7 +11,7 @@ from configparser import ConfigParser
def usage():
- print(os.path.basename(sys.argv[0]) + "[-h|--help] [-s|--skip] [-t|--title title] [-c|--correspondent "
+ print(os.path.basename(sys.argv[0]) + " [-h|--help] [-t|--title title] [-c|--correspondent "
"correspondent] [--tags tags] file")
print(" -h|--help prints this help and exits")
print(" -t|--title title to give to the file")
@@ -26,17 +26,26 @@ def read_config():
sever_info = config_object["SERVER_CONFIG"]
state = config_object["STATE"]
- return sever_info["remote"], sever_info["remote_path"], sever_info["user"], state["current_id"]
+ # if the year in the config doesn't match the current one, reset id back to 1
+ year = state["year"]
-def update_id(new_id):
+ file_id = state["current_id"]
+
+ if str(year) != str(datetime.now().strftime("%Y")):
+ file_id = 1
+
+ return sever_info["remote"], sever_info["remote_path"], sever_info["user"], file_id
+
+
+def update_state(new_id):
config_object = ConfigParser()
config_object.read(os.environ.get('XDG_CONFIG_HOME') + "/paperless_upload.ini")
state = config_object["STATE"]
- # Update the password
state["current_id"] = str(new_id)
+ state["year"] = str(datetime.now().strftime("%Y"))
# Write changes back to file
with open(os.environ.get('XDG_CONFIG_HOME') + "/paperless_upload.ini", 'w') as conf:
@@ -78,25 +87,40 @@ def upload(remote, remote_path, username, file_id, path, title, correspondent, t
# current date and time
now = datetime.now()
zulu_format = "%Y%m%d%H%M%S"
- time1 = now.strftime(zulu_format)
+ year_format = "%Y"
+ time_stamp = now.strftime(zulu_format)
+ check_in_year = now.strftime(year_format)
# https://paperless.readthedocs.io/en/latest/guesswork.html?highlight=guesswork
# --> "Date - Correspondent - Title - tag,tag,tag.pdf"
- guess_work_name = time1 + "Z - " + correspondent + " - " + title
+ prefix = f"{time_stamp}Z - {correspondent} - {title} - id{file_id},y{check_in_year}"
if tags:
- guess_work_name = guess_work_name + " - id" + str(file_id) + "," + tags + ".pdf"
+ guess_work_name = f"{prefix},{tags}.pdf"
else:
- guess_work_name = guess_work_name + " - id" + str(file_id) + ".pdf"
+ guess_work_name = f"{prefix}.pdf"
+
+ print("")
+ print(f" #######################################")
+ print(f" # file the document \"{title}\" with the following infos")
+ print(f" # year: {check_in_year}")
+ print(f" # id: {file_id}")
+ print(f" # tags: {tags}")
+ print(f" #######################################")
remote_file = (remote_path + guess_work_name).replace(" ", "\\\\ ")
command = f"scp {path} {username}@{remote}:\"{remote_file}\""
- print("# use the following command to upload:")
+ print("")
+ print(" #######################################")
+ print(" # use the following command to upload")
+ print("")
print(command)
+ print("")
+ print(" #######################################")
def main():
try:
- opts, args = getopt.getopt(sys.argv[1:], "ht:c:", ["help", "title", "correspondent", "tags"])
+ opts, args = getopt.getopt(sys.argv[1:], "ht:c:a:", ["help", "title=", "correspondent=", "tags="])
except getopt.GetoptError as err:
# print help information and exit:
print(err) # will print something like "option -a not recognized"
@@ -137,7 +161,7 @@ def main():
traceback.print_exc()
sys.exit(5)
else:
- update_id(int(file_id) + 1)
+ update_state(int(file_id) + 1)
if __name__ == "__main__":