Add script that checks if pad is already moved

This commit is contained in:
Nick Hahn 2022-09-17 11:40:16 +02:00
parent dea3fa9fe6
commit 6f7c991948
2 changed files with 29 additions and 0 deletions

2
.gitignore vendored
View file

@ -2,7 +2,9 @@
__pycache__ __pycache__
venv/ venv/
images/ images/
pads/
pads.json pads.json
new_pads.json
# ---> Node # ---> Node
# Logs # Logs
logs logs

27
hedgedoc-is-moved.py Normal file
View file

@ -0,0 +1,27 @@
import requests
import json
import os
from os.path import exists
pads_json = []
new_json= []
if exists("pads.json"):
with open("pads.json", "r") as f:
old_file = json.load(f)
pads_json.extend(old_file)
for pad in pads_json:
print("Downloading: " + pad['oldUrl'] + "/download")
r = requests.head(pad['oldUrl'] + "/download")
if int(r.headers['content-length']) > 150:
new_json.append(pad)
with open("new_pads.json", "w") as f:
f.write(json.dumps(new_json))
else:
print("Give me pads.json")