Added Progress tracking

This commit is contained in:
Leon 2022-02-22 16:04:34 +01:00
parent d3101cc0a6
commit 6ca4d6685c
4 changed files with 44 additions and 6 deletions

3
.gitignore vendored
View File

@ -2,4 +2,5 @@ config.py
log.txt
failed.txt
__pycache__/
.idea/
.idea/
mangas.progress

View File

@ -43,6 +43,7 @@ I tried to test the languages as best as I could, but if I missed something plea
2. Init Playwright using `playwright install`
3. Rename `config.template.py` to `config.py` and edit the url, email and password to match the ones of your komga instance (User needs to have permission to edit the metadata).
The "mangas" array can be filled with the names of mangas which are supposed to be updated, if it is left empty every manga will be updated.
"keepProgress" can be set to either "True" or "False". If it is set to true, successfully updated Mangas will be stored in a list and not be updated on the next run.
4. Run the script using `python mangaMetadata.py`
@ -57,8 +58,8 @@ docker run \
--name anisearchkomga \
pfuenzle/anisearchkomga:latest
```
You can also use the optional environment variable `MANGAS="Manga1,Manga2"` to give a comma seperated list of mangas which are supposed to be updated. If it is left blank, every manga will be updated.
Hint: Replace \ with ` when using Powershell
### Additional Environment Variables
- `MANGAS="Manga1,Manga2"` - This can be used to give a comma seperated list of mangas which are supposed to be updated. If it is left blank, every manga will be updated.
- `KEEPPROGRESS=True` - This can be set to either true or false. If it is set to true, a list of all successfully updated mangas will be saved and mangas in this list will not be updated on the next run. If you want to persist the list on the disk, you have to also add a volume as following: `-v /path/to/mangas.progress:/app/mangas.progress`, where `/path/to/mangas.progress` has to be replaced with the path to an empty existing file.

View File

@ -2,4 +2,5 @@ anisearchlang="German"
komgaurl="https://komga.com"
komgaemail="adminemail@komga.com"
komgapassword="12345"
mangas = [""]
mangas = []
keepProgress = True

View File

@ -31,6 +31,15 @@ try:
ENV_MANGAS = os.environ['MANGAS']
except:
ENV_MANGAS = "NONE"
try:
ENV_PROGRESS = os.environ['KEEPPROGRESS']
if(ENV_PROGRESS.lower() == "true"):
ENV_PROGRESS = True
else:
ENV_PROGRESS = False
except:
ENV_PROGRESS = False
if (ENV_URL == "" and ENV_EMAIL == "" and ENV_PASS == "" and ENV_LANG == ""):
try:
@ -43,6 +52,7 @@ elif (ENV_URL != "" and ENV_EMAIL != "" and ENV_PASS != "" and ENV_LANG != ""):
komgaemail = ENV_EMAIL
komgapassword = ENV_PASS
anisearchlang = ENV_LANG
keepProgress = ENV_PROGRESS
mangas = []
if(ENV_MANGAS != "NONE"):
for manga in ENV_MANGAS.split(","):
@ -362,7 +372,7 @@ page = browser.new_page()
page.goto(getBaseURL())
print("Using user" + komgaemail)
print("Using user " + komgaemail)
x = requests.get(komgaurl + '/api/v1/series?size=50000', auth = (komgaemail, komgapassword))
@ -385,6 +395,25 @@ class failedtries():
failed = []
progressfilename = "mangas.progress"
def addMangaProgress(seriesID):
if(keepProgress == False):
return
progfile = open(progressfilename, "a+")
progfile.write(str(seriesID) + "\n")
progfile.close()
progresslist = []
if(keepProgress):
print("Loading list of successfully updated mangas")
try:
with open(progressfilename) as file:
progresslist = [line.rstrip() for line in file]
except:
print("Failed to load list of mangas")
failedfile = open("failed.txt", "w")
for series in json_string['content']:
seriesnum += 1
@ -394,6 +423,9 @@ for series in json_string['content']:
print("Number: " + str(seriesnum) + "/" + str(expected))
name = series['name']
seriesID = series['id']
if(str(seriesID) in progresslist):
print("Manga " + str(name) + " was already updated, skipping...")
continue
print("Updating: " + str(name))
md = getMangaMetadata(name)
if(md.isvalid == False):
@ -427,6 +459,7 @@ for series in json_string['content']:
print("----------------------------------------------------")
print("Successfully updated " + str(name))
print("----------------------------------------------------")
addMangaProgress(seriesID)
time.sleep(10)
else:
try:
@ -472,10 +505,12 @@ for f in failed:
print("++++++++++++++++++++++++++++++++++++++++++++++++++++")
print("Successfully updated " + str(f.name))
print("++++++++++++++++++++++++++++++++++++++++++++++++++++")
addMangaProgress(seriesID)
time.sleep(10)
else:
print("----------------------------------------------------")
print("Failed again to update " + str(f.name) + ", not trying again")
print("----------------------------------------------------")
addMangaProgress(seriesID)
time.sleep(10)
continue