| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- #!/usr/bin/env python3
- # Copyright Penta (c) 2018/2021 - Under BSD License
- # Library import
- import os
- import re
- import asyncio
- import urllib.request
- import string
- import time
- import socket
- from html2text import HTML2Text
- from bs4 import BeautifulSoup
- from configparser import ConfigParser
- # Custom library
- from myanimebot.myanimelist import get_thumbnail
- import myanimebot.globals as globals
- # Script version
- VERSION = "1.2"
- globals.logger.info("Booting the MyAnimeBot Thumbnail Refresher " + VERSION + "...")
- def main() :
- globals.logger.info("Starting the refresher task...")
-
- count = 0
-
- cursor = globals.conn.cursor(buffered=True)
- cursor.execute("SELECT guid, title, thumbnail FROM t_animes")
- datas = cursor.fetchall()
-
- globals.logger.info(str(len(datas)) + " medias are going to be checked.")
- for data in datas:
- try:
- image = get_thumbnail(data[0])
-
- if (image == data[2]) :
- if (image != "") :
- globals.logger.debug("Thumbnail for " + str(data[1]) + " already up to date.")
- else :
- globals.logger.info("Thumbnail for " + str(data[1]) + " still empty.")
- else :
- if (image != "") :
- cursor.execute("UPDATE t_animes SET thumbnail = %s WHERE guid = %s", [image, data[0]])
- globals.conn.commit()
-
- globals.logger.info("Updated thumbnail found for \"" + str(data[1]) + "\": %s", image)
- count += 1
- else :
- try :
- urllib.request.urlopen(data[2])
- globals.logger.info("Thumbnail for \"" + str(data[1]) + "\" is now empty, avoiding change.")
- except :
- globals.logger.info("Thumbnail for \"" + str(data[1]) + "\" has been deleted!")
- except Exception as e :
- globals.logger.warning("Error while updating thumbnail for '" + str(data[1]) + "': " + str(e))
- time.sleep(3)
-
- globals.logger.info("All thumbnails checked!")
- cursor.close()
-
- globals.logger.info(str(count) + " new thumbnails, time taken: %ss" % round((time.time() - startTime), 2))
- # Starting main function
- if __name__ == "__main__" :
- startTime = time.time()
- main()
- globals.logger.info("Thumbnail refresher script stopped")
-
- # We close all the ressources
- globals.conn.close()
|