read token from file

This commit is contained in:
Sarah 2022-06-27 00:11:06 +01:00
parent cef9dddac4
commit e37c50257f
12 changed files with 189 additions and 12 deletions

26
add_img_text.py Normal file
View File

@ -0,0 +1,26 @@
from wiki_pages import FilmsByCountry
from vcinema_utils import VCinemaUtils
import argparse
from collections import OrderedDict
import imageio
from progress.bar import IncrementalBar
from pygifsicle import optimize
from PIL import Image, ImageFont, ImageDraw, ImageFont
import io
with open("test.png", "rb") as f:
img_bytes = f.read()
stream = io.BytesIO(img_bytes)
img = Image.open(stream)
print(img.height)
map_editable = ImageDraw.Draw(img)
font = ImageFont.truetype("/System/Library/Fonts/Supplemental/Arial.ttf", 48)
map_editable.text((0, 655-50), "{}".format("2022-04-88"), (255, 64, 0), font=font)
img.show()

32
country_count.csv Normal file
View File

@ -0,0 +1,32 @@
Country,Count,Alpha
Hong Kong,8,HKG
Canada,15,CAN
United Kingdom,20,GBR
United States,147,USA
Germany,9,DEU
Russia,3,RUS
Czechia,1,CZE
Philippines,2,PHL
New Zealand,4,NZL
Australia,5,AUS
Japan,7,JPN
Italy,4,ITA
Uganda,2,UGA
France,4,FRA
South Korea,2,KOR
South Africa,1,ZAF
North Korea,1,PRK
Taiwan,1,TWN
Belgium,2,BEL
Luxembourg,1,LUX
China,3,CHN
Turkey,2,TUR
Israel,1,ISR
Nigeria,1,NGA
Mexico,1,MEX
Spain,1,ESP
Thailand,2,THA
Vietnam,1,VNM
Kazakhstan,1,KAZ
Ireland,1,IRL
India,1,IND
1 Country Count Alpha
2 Hong Kong 8 HKG
3 Canada 15 CAN
4 United Kingdom 20 GBR
5 United States 147 USA
6 Germany 9 DEU
7 Russia 3 RUS
8 Czechia 1 CZE
9 Philippines 2 PHL
10 New Zealand 4 NZL
11 Australia 5 AUS
12 Japan 7 JPN
13 Italy 4 ITA
14 Uganda 2 UGA
15 France 4 FRA
16 South Korea 2 KOR
17 South Africa 1 ZAF
18 North Korea 1 PRK
19 Taiwan 1 TWN
20 Belgium 2 BEL
21 Luxembourg 1 LUX
22 China 3 CHN
23 Turkey 2 TUR
24 Israel 1 ISR
25 Nigeria 1 NGA
26 Mexico 1 MEX
27 Spain 1 ESP
28 Thailand 2 THA
29 Vietnam 1 VNM
30 Kazakhstan 1 KAZ
31 Ireland 1 IRL
32 India 1 IND

0
country_counts.csv Normal file
View File

BIN
lapse.gif Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.0 MiB

13
map_test.py Normal file
View File

@ -0,0 +1,13 @@
import plotly.express as px
import pycountry
df = px.data.gapminder().query("year==2007")
print(df.head())
fig = px.choropleth(df, locations="iso_alpha",
color="lifeExp", # lifeExp is a column of gapminder
hover_name="country", # column to add to hover information
color_continuous_scale=px.colors.sequential.Plasma)
fig.show()

76
plot_countries.py Normal file
View File

@ -0,0 +1,76 @@
from bookstack import Bookstack
from update_films_by_country import get_films_by_country, build_page as build_films_by_country_page, FILMS_BY_COUNTRY_PAGE_ID
from update_films_by_year import get_films_by_year, build_page as build_films_by_year_page, FILMS_BY_YEAR_PAGE_ID
from vcinema_utils import VCinemaUtils
from update_viewings_csv import update_viewings_csv
import argparse
from progress.bar import IncrementalBar
import plotly.express as px
import pandas
import geopandas
import numpy as np
from urllib.request import urlopen
import json
country_alpha3 = {}
def plot_countries(token_id, token_secret):
df = pandas.read_csv('country_count.csv', header=0)
url = 'https://raw.githubusercontent.com/datasets/geo-countries/master/data/countries.geojson'
with urlopen(url) as response:
countries = json.load(response)
print(countries['features'][0]['properties'].keys())
fig = px.choropleth_mapbox(df,geojson=countries,locations=df['Alpha'],color=np.log10(df['Count']),hover_name=df['Country'],hover_data=[df['Count']],color_continuous_scale=px.colors.sequential.YlGn, featureidkey="properties.ISO_A3",mapbox_style="stamen-terrain",opacity=0.5)
fig.update_geos(fitbounds="locations")
fig.update_traces(hovertemplate="<b>%{hovertext}</b><br>Count: %{customdata}")
fig.update_layout(coloraxis_showscale=False)
fig.show()
#
def test():
from urllib.request import urlopen
import json
with urlopen('https://raw.githubusercontent.com/plotly/datasets/master/geojson-counties-fips.json') as response:
counties = json.load(response)
import pandas as pd
df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/fips-unemp-16.csv",
dtype={"fips": str})
import plotly.graph_objects as go
print("DF")
print(df)
fig = go.Figure(go.Choroplethmapbox(geojson=counties, locations=df.fips, z=df.unemp,
colorscale="Viridis", zmin=0, zmax=12,
marker_opacity=0.5, marker_line_width=0))
fig.update_layout(mapbox_style="carto-positron",
mapbox_zoom=3, mapbox_center={"lat": 37.0902, "lon": -95.7129})
fig.update_layout(margin={"r": 0, "t": 0, "l": 0, "b": 0})
fig.show()
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Update wiki pages.')
parser.add_argument('token_id', help='API token ID.')
parser.add_argument('token_secret', help='API token secret.')
args = parser.parse_args()
# test()
plot_countries(args.token_id, args.token_secret)
# pycountry.countries.get(name='American Samoa').alpha2

BIN
test.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 KiB

View File

1
token.json Normal file
View File

@ -0,0 +1 @@
{"token_id": "4Xr3a4mOmuFBDK9nOuzBOjCfO5n4mWXp", "token_secret": "kSA3Td1pKFpBYtf5K0quCBqeIS61Fjzt"}

View File

@ -2,6 +2,7 @@ from wiki_pages import FilmsByCountry, FilmsByReference, FilmsByYear, HiddenThem
from vcinema_utils import VCinemaUtils
import argparse
import json
from progress.bar import IncrementalBar
@ -56,12 +57,13 @@ def update_wiki(token_id, token_secret, update_csv, pages):
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='Update wiki pages.')
parser.add_argument('token_id', help='API token ID.')
parser.add_argument('token_secret', help='API token secret.')
parser.add_argument("--do_not_update_csv", action="store_true")
parser.add_argument('--pages', nargs="+", default=['years', 'countries', 'references', 'themes', 'scores'], required=False)
args = parser.parse_args()
update_wiki(args.token_id, args.token_secret, not args.do_not_update_csv, args.pages)
with open('token.json') as json_file:
token = json.load(json_file)
update_wiki(token['token_id'], token['token_secret'], not args.do_not_update_csv, args.pages)

26
wiki_pages/ActorScores.py Normal file
View File

@ -0,0 +1,26 @@
from collections import Counter, OrderedDict
import warnings
from vcinema_utils import VCinemaUtils
warnings.filterwarnings("ignore")
def get_actor_scores(viewings):
for viewing_ind in range(len(viewings)):
viewing = viewings[viewing_ind]
cast_list = []
for cast_member in viewing['cast']:
cast_member_name = (cast_member['name'], cast_member.currentRole)
cast_list.append(cast_member_name)
viewings[viewing_ind]['cast'] = cast_list
viewings_filtered_by_cast_member = VCinemaUtils.filter_viewings(viewings, "cast")
viewings_filtered_by_cast_member = OrderedDict(sorted(viewings_filtered_by_cast_member.items(), key=lambda t: len(t[1]), reverse=True))
return viewings_filtered_by_cast_member

View File

@ -28,27 +28,28 @@ def get_hidden_themes(viewings, token_id, token_secret):
# Add hidden themes
for date, data in viewings_filtered_watch_date.items():
hidden_themes = set()
keyword_counts = {}
if len(data['viewings']) > 1:
viewings_keywords = []
for viewing in data['viewings']:
if 'keywords' in viewing:
viewings_keywords.append(set(viewing['keywords']))
for keyword in viewing['keywords']:
if keyword in keyword_counts.keys():
keyword_counts[keyword] += 1
else:
keyword_counts[keyword] = 1
if len(viewings_keywords) > 1:
hidden_themes = set.intersection(*viewings_keywords)
keyword_counts = {k: v for k, v in sorted(keyword_counts.items(), key=lambda item: item[1], reverse=True)}
if hidden_themes != set():
viewings_filtered_watch_date[date]['hidden_themes'] = list(hidden_themes)
viewings_filtered_watch_date[date]['keyword_counts'] = keyword_counts
return viewings_filtered_watch_date
def update_page(token_id, token_secret, hidden_themes):
page = build_page(hidden_themes)
Bookstack.update_page(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, PAGE_ID, markdown=page)
print(page)
# Bookstack.update_page(VCinemaUtils.JACKNET_WIKI_URL, token_id, token_secret, PAGE_ID, markdown=page)
def build_page(hidden_themes):