Compare commits
5 Commits
9e98a0c636
...
5645c4e575
Author | SHA1 | Date | |
---|---|---|---|
![]() |
5645c4e575 | ||
![]() |
14c60c1bab | ||
![]() |
6e941a13d1 | ||
![]() |
586ccfb997 | ||
![]() |
1067a193cf |
BIN
__pycache__/update_films_by_country.cpython-37.pyc
Normal file
BIN
__pycache__/update_films_by_country.cpython-37.pyc
Normal file
Binary file not shown.
BIN
__pycache__/update_films_by_year.cpython-37.pyc
Normal file
BIN
__pycache__/update_films_by_year.cpython-37.pyc
Normal file
Binary file not shown.
108
update_films_by_country.py
Normal file
108
update_films_by_country.py
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
from vcinema_utils import VCinemaUtils
|
||||||
|
|
||||||
|
import base64
|
||||||
|
from collections import Counter, OrderedDict
|
||||||
|
import csv
|
||||||
|
import os
|
||||||
|
from progress.bar import IncrementalBar
|
||||||
|
from wand.image import Image
|
||||||
|
import worldmap
|
||||||
|
import warnings
|
||||||
|
warnings.filterwarnings("ignore")
|
||||||
|
|
||||||
|
# Page ID of https://wiki.jacknet.io/books/vcinema/page/films-by-country
|
||||||
|
FILMS_BY_COUNTRY_PAGE_ID = 34
|
||||||
|
|
||||||
|
|
||||||
|
def get_films_by_country(viewings):
|
||||||
|
viewings_filtered_by_country = VCinemaUtils.filter_viewings(viewings, "countries")
|
||||||
|
|
||||||
|
return viewings_filtered_by_country
|
||||||
|
|
||||||
|
|
||||||
|
def build_page(films_by_country):
|
||||||
|
country_count = len(films_by_country.keys())
|
||||||
|
with IncrementalBar('Generating table', max=country_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar:
|
||||||
|
film_by_country_table = build_table(films_by_country, bar)
|
||||||
|
|
||||||
|
print("Drawing map")
|
||||||
|
country_counter = Counter(films_by_country)
|
||||||
|
png_data = draw_map(country_counter)
|
||||||
|
encoded = base64.b64encode(png_data).decode("utf-8")
|
||||||
|
image_html = "<img src=\"data:image/png;base64,{}\" />".format(encoded)
|
||||||
|
|
||||||
|
page = image_html + film_by_country_table
|
||||||
|
|
||||||
|
return page
|
||||||
|
|
||||||
|
|
||||||
|
def get_flags_dict():
|
||||||
|
flags = {}
|
||||||
|
|
||||||
|
with open('country_flags.csv', newline='') as f:
|
||||||
|
reader = csv.reader(f, quotechar="\"")
|
||||||
|
next(reader, None) # skip the headers
|
||||||
|
|
||||||
|
for row in reader:
|
||||||
|
flags[row[0]] = row[1]
|
||||||
|
|
||||||
|
return flags
|
||||||
|
|
||||||
|
|
||||||
|
def build_table(films_by_country, bar=None):
|
||||||
|
films_by_country_sorted = OrderedDict(sorted(films_by_country.items(), key=lambda t: t[0]))
|
||||||
|
|
||||||
|
flags = get_flags_dict()
|
||||||
|
|
||||||
|
table = "<table>"
|
||||||
|
|
||||||
|
table += "<thead><tr><th>Country</th><th>Films</th></tr>"
|
||||||
|
table += "<tbody>"
|
||||||
|
|
||||||
|
for country in films_by_country_sorted.keys():
|
||||||
|
row = "<tr>"
|
||||||
|
|
||||||
|
row += "<td>"
|
||||||
|
row += "{} {}".format(str(country), flags[country] if country in flags.keys() else "")
|
||||||
|
row += "</td>"
|
||||||
|
|
||||||
|
row += "<td>"
|
||||||
|
|
||||||
|
film_links = ["<a href=\"https://www.imdb.com/title/tt{}/\">{}</a>".format(film['imdb_id'], film['title'])
|
||||||
|
for film in films_by_country_sorted[country]]
|
||||||
|
|
||||||
|
row += "<br>".join(film_links)
|
||||||
|
|
||||||
|
row += "</td>"
|
||||||
|
row += "</tr>"
|
||||||
|
|
||||||
|
table += row
|
||||||
|
|
||||||
|
if bar is not None:
|
||||||
|
bar.next()
|
||||||
|
|
||||||
|
table += "</tbody>"
|
||||||
|
table += "</table>"
|
||||||
|
|
||||||
|
if bar is not None:
|
||||||
|
bar.finish()
|
||||||
|
|
||||||
|
return table
|
||||||
|
|
||||||
|
|
||||||
|
def draw_map(counter, file_name="vcinema_map.svg"):
|
||||||
|
countries = [k for k, v in counter.items()]
|
||||||
|
counts = [len(v) for _, v in counter.items()]
|
||||||
|
|
||||||
|
max_count = max(counts)
|
||||||
|
|
||||||
|
opacity = [0.5 + (x / (float(max_count))/2.0) for x in counts]
|
||||||
|
|
||||||
|
worldmap.plot(countries, cmap=["#FF4000"], opacity=opacity, filename=file_name, verbose=False)
|
||||||
|
|
||||||
|
with Image(filename=file_name, width=1000, height=655) as i:
|
||||||
|
png_data = i.make_blob("png")
|
||||||
|
|
||||||
|
os.remove(file_name)
|
||||||
|
|
||||||
|
return png_data
|
@ -1,142 +0,0 @@
|
|||||||
import argparse
|
|
||||||
import base64
|
|
||||||
from collections import Counter, OrderedDict
|
|
||||||
import os
|
|
||||||
from progress.bar import Bar
|
|
||||||
from wand.image import Image
|
|
||||||
import worldmap
|
|
||||||
import warnings
|
|
||||||
warnings.filterwarnings("ignore")
|
|
||||||
|
|
||||||
|
|
||||||
from bookstack import Bookstack
|
|
||||||
from vcinema_utils import VCinemaUtils
|
|
||||||
|
|
||||||
|
|
||||||
FLAGS = {
|
|
||||||
"Australia": "🇦🇺",
|
|
||||||
"Belgium": "🇧🇪",
|
|
||||||
"Canada": "🇨🇦",
|
|
||||||
"China": "🇨🇳",
|
|
||||||
"Czech Republic": "🇨🇿",
|
|
||||||
"Czechia": "🇨🇿",
|
|
||||||
"France": "🇫🇷",
|
|
||||||
"Germany": "🇩🇪",
|
|
||||||
"Hong Kong": "🇭🇰",
|
|
||||||
"Hong Kong SAR China": "🇭🇰",
|
|
||||||
"Italy": "🇮🇹",
|
|
||||||
"Israel": "🇮🇱",
|
|
||||||
"Japan": "🇯🇵",
|
|
||||||
"Luxembourg": "🇱🇺",
|
|
||||||
"Mexico": "🇲🇽",
|
|
||||||
"New Zealand": "🇳🇿",
|
|
||||||
"Nigeria": "🇳🇬",
|
|
||||||
"North Korea": "🇰🇵",
|
|
||||||
"Philippines": "🇵🇭",
|
|
||||||
"Russia": "🇷🇺",
|
|
||||||
"Spain": "🇪🇸",
|
|
||||||
"South Africa": "🇿🇦",
|
|
||||||
"South Korea": "🇰🇷",
|
|
||||||
"Taiwan": "🇹🇼",
|
|
||||||
"Thailand": "🇹🇭",
|
|
||||||
"Turkey": "🇹🇷",
|
|
||||||
"Uganda": "🇺🇬",
|
|
||||||
"United Kingdom": "🇬🇧",
|
|
||||||
"United States": "🇺🇸",
|
|
||||||
"West Germany": "⬅️🇩🇪",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def build_table(fby, bar):
|
|
||||||
fby_sorted = OrderedDict(sorted(fby.items(), key=lambda t: t[0]))
|
|
||||||
|
|
||||||
table = "<table>"
|
|
||||||
|
|
||||||
table += "<thead><tr><th>Country</th><th>Films</th></tr>"
|
|
||||||
table += "<tbody>"
|
|
||||||
|
|
||||||
for country in fby_sorted.keys():
|
|
||||||
row = "<tr>"
|
|
||||||
|
|
||||||
row += "<td>"
|
|
||||||
row += "{} {}".format(str(country), FLAGS[country])
|
|
||||||
row += "</td>"
|
|
||||||
|
|
||||||
row += "<td>"
|
|
||||||
|
|
||||||
row += "<br>".join(["<a href=\"{}\">{}</a>".format(film['imdb_id'], film['title']) for film in fby_sorted[country]])
|
|
||||||
|
|
||||||
row += "</td>"
|
|
||||||
row += "</tr>"
|
|
||||||
|
|
||||||
table += row
|
|
||||||
|
|
||||||
bar.next()
|
|
||||||
|
|
||||||
table += "</tbody>"
|
|
||||||
table += "</table>"
|
|
||||||
|
|
||||||
return table
|
|
||||||
|
|
||||||
|
|
||||||
def draw_map(counter, file_name="vcinema_map.svg"):
|
|
||||||
countries = [k for k, v in counter.items()]
|
|
||||||
counts = [len(v) for _, v in counter.items()]
|
|
||||||
|
|
||||||
max_count = max(counts)
|
|
||||||
|
|
||||||
opacity = [0.5 + (x / (float(max_count))/2.0) for x in counts]
|
|
||||||
|
|
||||||
worldmap.plot(countries, cmap=["#ff0000"], opacity=opacity, filename=file_name, verbose=False)
|
|
||||||
|
|
||||||
with Image(filename=file_name, width=1000, height=655) as i:
|
|
||||||
png_data = i.make_blob("png")
|
|
||||||
|
|
||||||
os.remove(file_name)
|
|
||||||
|
|
||||||
return png_data
|
|
||||||
|
|
||||||
|
|
||||||
def update_page(map_png, table, wiki_url, token_id, token_secret):
|
|
||||||
page_id = 34
|
|
||||||
|
|
||||||
encoded = base64.b64encode(map_png).decode("utf-8")
|
|
||||||
|
|
||||||
image_html = "<img src=\"data:image/png;base64,{}\" />".format(encoded)
|
|
||||||
|
|
||||||
page_contents = image_html + table
|
|
||||||
|
|
||||||
Bookstack.update_page(wiki_url, token_id, token_secret, page_id, html=page_contents)
|
|
||||||
|
|
||||||
|
|
||||||
def update_films_by_country_page(token_id, token_secret):
|
|
||||||
print("Retrieving VCinema viewings")
|
|
||||||
viewings = VCinemaUtils.get_vcinema_viewings(token_id, token_secret)
|
|
||||||
|
|
||||||
viewing_count = len(viewings)
|
|
||||||
|
|
||||||
with Bar('Retrieving movie data', max=viewing_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar:
|
|
||||||
VCinemaUtils.add_imdb_data_to_viewings(viewings, ['countries'], bar)
|
|
||||||
|
|
||||||
with Bar('Processing viewing data', max=viewing_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar:
|
|
||||||
viewings_by_country = VCinemaUtils.filter_viewings(viewings, 'countries', bar)
|
|
||||||
|
|
||||||
country_count = len(viewings_by_country.keys())
|
|
||||||
with Bar('Generating table', max=country_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar:
|
|
||||||
film_by_country_table = build_table(viewings_by_country, bar)
|
|
||||||
|
|
||||||
print("Drawing map")
|
|
||||||
country_counter = Counter(viewings_by_country)
|
|
||||||
png_data = draw_map(country_counter)
|
|
||||||
|
|
||||||
update_page(png_data, film_by_country_table, VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
parser = argparse.ArgumentParser(description='Update page displaying VCinema films sorted by country.')
|
|
||||||
parser.add_argument('token_id', help='API token ID.')
|
|
||||||
parser.add_argument('token_secret', help='API token secret.')
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
update_films_by_country_page(args.token_id, args.token_secret)
|
|
31
update_films_by_year.py
Normal file
31
update_films_by_year.py
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
from collections import OrderedDict
|
||||||
|
|
||||||
|
from vcinema_utils import VCinemaUtils
|
||||||
|
|
||||||
|
# Page ID of https://wiki.jacknet.io/books/vcinema/page/films-by-release-year
|
||||||
|
FILMS_BY_YEAR_PAGE_ID = 24
|
||||||
|
|
||||||
|
|
||||||
|
def get_films_by_year(viewings):
|
||||||
|
viewings_filtered_by_year = VCinemaUtils.filter_viewings(viewings, "year")
|
||||||
|
|
||||||
|
return viewings_filtered_by_year
|
||||||
|
|
||||||
|
|
||||||
|
def build_page(films_by_year, progressbar=None):
|
||||||
|
films_by_year_sorted = OrderedDict(sorted(films_by_year.items(), key=lambda t: t[0], reverse=True))
|
||||||
|
|
||||||
|
page_table = "| Year | Films |\n| - | - |"
|
||||||
|
|
||||||
|
for year in films_by_year_sorted.keys():
|
||||||
|
page_table += "\n"
|
||||||
|
page_table += str(year) + " | "
|
||||||
|
page_table += "<br>".join("[{}](https://www.imdb.com/title/tt{}/)".format(film['title'], film['imdb_id']) for film in films_by_year_sorted[year])
|
||||||
|
|
||||||
|
if progressbar is not None:
|
||||||
|
progressbar.next()
|
||||||
|
|
||||||
|
if progressbar is not None:
|
||||||
|
progressbar.finish()
|
||||||
|
|
||||||
|
return page_table
|
@ -1,59 +0,0 @@
|
|||||||
import argparse
|
|
||||||
from collections import OrderedDict
|
|
||||||
from progress.bar import Bar
|
|
||||||
|
|
||||||
from bookstack import Bookstack
|
|
||||||
from vcinema_utils import VCinemaUtils
|
|
||||||
|
|
||||||
|
|
||||||
def build_table(films_by_year, progressbar=None):
|
|
||||||
films_by_year_sorted = OrderedDict(sorted(films_by_year.items(), key=lambda t: t[0], reverse=True))
|
|
||||||
|
|
||||||
page_table = "| Year | Films |\n| - | - |\n"
|
|
||||||
|
|
||||||
for year in films_by_year_sorted.keys():
|
|
||||||
page_table += str(year) + " | "
|
|
||||||
page_table += "<br>".join("[{}](https://www.imdb.com/title/tt{}/)".format(film['title'], film['imdb_id']) for film in films_by_year_sorted[year])
|
|
||||||
page_table += "\n"
|
|
||||||
|
|
||||||
if progressbar is not None:
|
|
||||||
progressbar.next()
|
|
||||||
|
|
||||||
if progressbar is not None:
|
|
||||||
progressbar.finish()
|
|
||||||
|
|
||||||
return page_table
|
|
||||||
|
|
||||||
|
|
||||||
def update_films_by_year_page(token_id, token_secret):
|
|
||||||
print("Retrieving VCinema viewings")
|
|
||||||
viewings = VCinemaUtils.get_vcinema_viewings(token_id, token_secret)
|
|
||||||
|
|
||||||
viewing_count = len(viewings)
|
|
||||||
with Bar('Retrieving movie data', max=viewing_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar:
|
|
||||||
VCinemaUtils.add_imdb_data_to_viewings(viewings, ['year'], bar)
|
|
||||||
|
|
||||||
with Bar('Processing viewing data', max=viewing_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar:
|
|
||||||
viewings_by_year = VCinemaUtils.filter_viewings(viewings, 'year', bar)
|
|
||||||
|
|
||||||
year_count = len(viewings_by_year)
|
|
||||||
with Bar('Generating table', max=year_count, suffix='%(percent).1f%% - %(eta)ds remaining', check_tty=False) as bar:
|
|
||||||
film_by_year_table = build_table(viewings_by_year, bar)
|
|
||||||
|
|
||||||
# Page ID of https://wiki.jacknet.io/books/vcinema/page/films-by-release-year
|
|
||||||
page_id = 24
|
|
||||||
|
|
||||||
print("Updating page")
|
|
||||||
Bookstack.update_page(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, page_id, markdown=film_by_year_table)
|
|
||||||
|
|
||||||
print("Done!")
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
parser = argparse.ArgumentParser(description='Update page displaying VCinema films sorted by release year.')
|
|
||||||
parser.add_argument('token_id', help='API token ID.')
|
|
||||||
parser.add_argument('token_secret', help='API token secret.')
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
|
||||||
|
|
||||||
update_films_by_year_page(args.token_id, args.token_secret)
|
|
501
vcinema_map.svg
501
vcinema_map.svg
File diff suppressed because one or more lines are too long
Before Width: | Height: | Size: 1.3 MiB |
Loading…
x
Reference in New Issue
Block a user