from flask import Flask, Response, jsonify, render_template from base64 import b64encode import feedparser import re from dotenv import load_dotenv, find_dotenv load_dotenv(find_dotenv()) import requests import json import os import random GOODREADS_RSS_URL = os.getenv("GOODREADS_RSS_URL") PROGRESS_REGEX = r".*\"([^\"]*)") def last_activity(path): activityFeed = feedparser.parse(GOODREADS_RSS_URL) data = "" entries = activityFeed.entries pr = re.compile(PROGRESS_REGEX) rr = re.compile(READ_REGEX) book, author, img, progress = '', '', '', '' for i in entries: i["summary"] = i["summary"].replace("<","<").replace(">",">").replace(""","\"").replace("\n","") print(i["summary"]) res = pr.search(i["summary"]) if res: book, author, img = res.group(1,2,3) progress = int(100*int(res.group(4))/int(res.group(5))) else: res = rr.search(i["summary"]) if res: book, author, img = res.group(1,2,3) progress = 100 else: continue break svg = makeSVG(book, author, progress, img) resp = Response(svg, mimetype="image/svg+xml") resp.headers["Cache-Control"] = "s-maxage=1" return resp if __name__ == "__main__": app.run(debug=True)