add some more scripts

Signed-off-by: Bogomil Vasilev <smirky@smirky.net>
This commit is contained in:
2022-02-11 14:36:10 +02:00
parent 570014c240
commit 37e29989fe
8 changed files with 455 additions and 21 deletions

View File

@@ -20,7 +20,8 @@ from imdb import IMDb
class MovieList:
""" Class to generate a movie list HTML table """
def __init__(self, src=None):
def __init__(self, src=None, dst=None):
self.prev_html = []
self.html = """<html>
<head>
<title>My Movie List</title>
@@ -49,9 +50,12 @@ class MovieList:
</thead>
<tbody>"""
self.src = src
self.dst = Path(dst) if dst else Path(os.path.dirname(sys.argv[0])) / 'index.html'
self.movie_list = []
self.status_list = []
self.threads = []
self.read_prev_output()
self.html_table = None
def _worker(self, arg, index):
# Scan IMDb for a given movie and append it to the html
@@ -81,8 +85,8 @@ class MovieList:
rating = movie['rating']
genres = ', '.join(movie['genres'])
status = self.status_list[index]
self.html += (
f'\n\t<tr><td>{index + 1}</td>'
self.html_table[index] = (
f'\n{" "*8}<tr><td>{index + 1}</td>'
f'<td><p hidden>{title}</p><a href="{url}" target="_blank">{title}</a></td>'
f'<td>{year}</td><td align="center">{rating}</td>'
f'<td>{genres}</td>'
@@ -106,37 +110,48 @@ class MovieList:
tmp_status = re.sub(r'\]|.*\[', '', tmp_status)
self.movie_list = tmp_names.splitlines()
self.status_list = tmp_status.splitlines()
self.html_table = [None] * len(self.movie_list)
# Progress bar. Enough said
pbar = progressbar.ProgressBar(max_value=len(self.movie_list))
for idx, val in enumerate(self.movie_list):
thread = threading.Thread(target=self._worker, args=(val, idx,))
self.threads.append(thread)
thread.start()
pbar.update(idx+1)
time.sleep(0.2)
if len(self.threads) % 16 == 0:
time.sleep(6)
match = [line for line in self.prev_html if re.sub(r' \(.*\)', '', val) in line]
if match:
# Update movies as DONE in case of change
match = match[0].replace('*', self.status_list[idx])
# Directly insert the current HTML line from the older output
self.html_table[idx] = f'\n{" "*8}<tr><td>{idx + 1}</td>{match[match.find("</td>") + 5:]}'
pbar.update(idx + 1)
else:
thread = threading.Thread(target=self._worker, args=(val, idx))
self.threads.append(thread)
thread.start()
pbar.update(idx+1)
time.sleep(0.2)
if len(self.threads) % 16 == 0:
time.sleep(6)
for thread in self.threads:
thread.join()
self.html += ''.join(self.html_table)
return True
def write(self, dst=None):
""" Write the HTML list to index.html """
if not dst:
dst = Path(os.path.dirname(sys.argv[0])) / 'index.html'
else:
dst = Path(dst)
out_path = dst if dst else self.dst
# Just a fancy scrollbar for the html
scroll = '<script type="text/javascript" src="scroll-indicator.js"></script>'
self.html += ('\n\t</tbody>\n</table>\n' +
'\nGenerated on: ' + time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime()) +
' by ' + sys.argv[0] + scroll + '</body>\n</html>')
with open(dst, 'wb') as fp_handle:
with open(out_path, 'wb') as fp_handle:
fp_handle.write(self.html.encode('utf8'))
def read_prev_output(self):
with open(self.dst, 'rb') as fp_handle:
self.prev_html = fp_handle.read().decode('utf8').split('\n')
def main():
""" Default run """
@@ -150,7 +165,7 @@ def main():
if len(sys.argv) == 3:
dst = sys.argv[2]
mlist = MovieList(src=src)
mlist = MovieList(src=src, dst=dst)
if mlist.gen():
mlist.write(dst=dst)

View File

@@ -108,6 +108,7 @@ Pirates of the Caribbean: The Curse of the Black Pearl (2003) [DONE]
Pirates of the Caribbean: Dead Man's Chest (2006) [DONE]
Pirates of the Caribbean: At World's End (2007) [DONE]
Pirates of the Caribbean: On Stranger Tides (2011) [DONE]
Pirates of the Caribbean: Dead Men Tell No Tales (2017) [*]
Star Wars: Episode I - The Phantom Menace (1999) [DONE]
Star Wars: Episode II - Attack of the Clones (2002) [DONE]
Star Wars: Episode III - Revenge of the Sith (2005) [DONE]
@@ -289,16 +290,16 @@ Spider-Man: Homecoming (2017) [DONE]
Rememory (2017) [DONE]
Wristcutters: A Love Story (2006) [DONE]
Bohemian Rhapsody (2018) [DONE]
Killer's Bodyguard (2017) [*]
Killer's Bodyguard (2017) [DONE]
Danny Collins (2015) [DONE]
Annabelle: Creation (2017) [DONE]
Secrets of State (2008) [*]
Sleepers (1996) [*]
The Disaster Artist (2017) [*]
Sleepers (1996) [DONE]
The Disaster Artist (2017) [DONE]
Slumdog Millionaire (2008) [DONE]
Ready Player One (2018) [DONE]
Dorian Gray (2009) [DONE]
Serenity (2018) [*]
Serenity (2019) [DONE]
Death Wish (2018) [DONE]
Loving Pablo (2017) [DONE]
Get Out (2017) [DONE]
@@ -338,5 +339,72 @@ Man on a Ledge (2012) [DONE]
The Highwaymen (2019) [DONE]
Cold War (2018) [*]
Cold Pursuit (2019) [DONE]
Ad Astra (2019) [*]
Ad Astra (2019) [DONE]
Storm Boy (2019) [DONE]
Extremely Wicked, Shockingly Evil and Vile (2019) [DONE]
The Post (2017) [DONE]
Angel Has Fallen (2019) [DONE]
The Irishman (2019) [DONE]
The Nightingale (2018) [DONE]
Code 8 (2019) [DONE]
Togo (2019) [*]
Knives Out (2019) [DONE]
Children of Men (2006) [DONE]
Bogowie (2014) [DONE]
Spiral (2021) [*]
Ip Man 4 (2019) [DONE]
The Collini Case (2019) [DONE]
The Traitor (2019) [DONE]
Motherless Brooklyn (2019) [DONE]
The Banker (2020) [DONE]
The Gentlemen (2020) [DONE]
The Platform (2019) [DONE]
Radioactive (2019) [DONE]
Radium Girls (2020) [DONE]
The Stanford Prison Experiment (2015) [DONE]
Red Dragon (2002) [DONE]
The Silence of the Lambs (1991) [DONE]
Hannibal (2001) [DONE]
Parasite (2019) [DONE]
Rounds (2019) [DONE]
Murder On The Orient Express (2017) [DONE]
Pinocchio (2019) [DONE]
The Professor and the Madman (2019) [DONE]
Andhadhun (2018) [DONE]
Archive (2020) [DONE]
The Silencing (2020) [DONE]
Underwater (2020) [DONE]
Love and Monsters (2020) [DONE]
Marshall (2017) [DONE]
The Invisible Man (2020) [DONE]
Greenland (2020) [DONE]
Lean on Me (1989) [DONE]
Let Him Go (2020) [DONE]
Super Lopez (2018) [DONE]
Midnight Special (2016) [DONE]
The Father (2020) [DONE]
Another Round (2020) [DONE]
Promising Young Woman (2021) [DONE]
La Daronne (2020) [DONE]
Tangerines (2013) [DONE]
Bridge of Spies (2015) [DONE]
Glass (2019) [DONE]
The Hunt (2020) [DONE]
The Father (2020) [DONE]
The Dry (2020) [DONE]
The Little Things (2021) [DONE]
Arrival (2016) [DONE]
Duel (1971) [DONE]
The Courier (2020) [DONE]
The Bone Collector (1999) [DONE]
Oslo (2021) [DONE]
Wrath of Man (2021) [DONE]
Nobody (2021) [DONE]
Голата истина за група Жигули (2021) [DONE]
Wild Tales (2014) [DONE]
My Son (2021) [DONE]
The Guilty (2021) [DONE]
Finch (2021) [DONE]
Last Night in Soho (2021) [DONE]
Deepwater Horizon (2016) [DONE]
Boss Level (2020) [DONE]