website for beta festival 2024
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

153 lines
5.0 KiB

6 months ago
from flask import Flask, render_template
import contentful
from dotenv import load_dotenv
import os
3 months ago
import markdown
6 months ago
load_dotenv()
app = Flask(__name__, static_folder='public')
# Set your Contentful space ID and access token
SPACE_ID = os.getenv('SPACE_ID')
ACCESS_TOKEN = os.getenv('ACCESS_TOKEN')
client = contentful.Client(SPACE_ID, ACCESS_TOKEN)
@app.route('/')
def index():
3 months ago
sup_img = get_support_images()
return render_template('index.html', title='', sup_img_list=sup_img)
6 months ago
@app.route('/grph')
def graphics():
return render_template('grph.html')
6 months ago
@app.route('/events')
def events():
events = get_all_content('event')
return render_template('list.html', title='Events', content=events)
6 months ago
@app.route('/exhibitions')
def exhibitions():
return render_template('list.html', title='Exhibitions')
@app.route('/exhibitions/<ex_type>')
def exhibition_type(ex_type):
if ex_type == "local-artists-network":
ex_type = "LAN"
elif ex_type == "unsettling-the-algorithm":
ex_type = "UTA"
elif ex_type == "ethics-studio":
ex_type = "ES"
6 months ago
exhibitions = get_all_content('exhibition')
return render_template('list-exhibitions.html', title="Exhibitions", content=exhibitions, ex_type=ex_type)
6 months ago
@app.route('/conferences')
def conference():
6 months ago
conferences = get_all_content('conference')
return render_template('list.html', title='Conferences', content=conferences)
6 months ago
6 months ago
@app.route('/<type>/<title>')
def event_article(type, title):
data = get_content_by_title(title, type)
return render_template('article.html', title=title, content=data)
@app.route('/<type>/<ex_type>/<title>')
def event_articles(type, title, ex_type):
data = get_content_by_title(title, type)
return render_template('article.html', title=title, content=data)
@app.route('/locations')
def locations():
return render_template('locations.html', title='Locations')
6 months ago
6 months ago
def get_all_content(type):
entries = client.entries({'content_type': type})
6 months ago
content_list = process_content(entries, type)
6 months ago
return content_list
def get_content_by_title(title, pre_type):
type = pre_type[:-1]
entries = client.entries({'query': title, 'limit': 5})
exact_matches = [entry for entry in entries if getattr(entry, f'title_of_{type}') == title]
6 months ago
content_list = process_content(exact_matches, type)
return content_list
def process_content(entries, type):
content_list = []
exh_type = None
6 months ago
for entry in entries:
# Clear arrays
times = []
dates = []
6 months ago
if type == 'event':
times = getattr(entry, f'{type}_times')
dates = getattr(entry, f'{type}_dates')
if type == 'conference':
date_time_obj = getattr(entry, f'{type}_start_date_time')
date_str, time_str = format_datetime(date_time_obj)
try:
end_time_str = getattr(entry, f'{type}_end_date_time')
except:
end_time_str = None
if end_time_str != None:
end_time_str = end_time_str.strftime('%I%p').upper().lstrip('0')
concat_time_str = time_str + '->' + end_time_str
else:
concat_time_str = time_str
dates.append(date_str)
times.append(concat_time_str)
if type == 'exhibition':
exh_type = getattr(entry, f'{type}_type')
6 months ago
try:
bookUrl = getattr(entry, 'book_url')
except:
bookUrl = None
6 months ago
content = {
'title': getattr(entry, f'title_of_{type}'),
3 months ago
'information': markdown.markdown(getattr(entry, f'{type}_information')),
6 months ago
'image': 'https:{0}'.format(getattr(entry, f'{type}_reference_image').url()),
'artists': getattr(entry, f'{type}_artists'),
6 months ago
'dates': dates,
'times': times,
'location': getattr(entry, f'{type}_location'),
'bookUrl': bookUrl,
'exh_type': exh_type
6 months ago
}
content_list.append(content)
# Sort the content list by the 'title' key alphabetically
content_list.sort(key=lambda x: x['title'].lower())
return content_list
6 months ago
3 months ago
def get_support_images():
# Specify the folder where images are stored
image_folder = os.path.join(app.static_folder, 'images/support')
# Define a list of supported image file extensions
valid_extensions = ['.jpg', '.jpeg', '.png', '.gif', '.bmp']
# List to hold the image file names
image_files = []
# Loop through files in the directory
for filename in os.listdir(image_folder):
# Check if the file is an image (by extension)
if os.path.splitext(filename)[1].lower() in valid_extensions:
image_files.append(filename)
return image_files
6 months ago
def format_datetime(dt):
date_str = dt.strftime('%d.%m.%y')
time_str = dt.strftime('%I%p').upper().lstrip('0')
return date_str, time_str
if __name__ == '__main__':
app.run(debug=True)