Browse Source

Fixed want to read bug

main
Yiğit Çolakoğlu 4 years ago
parent
commit
b9e77fd2ac
2 changed files with 12 additions and 8 deletions
  1. +11
    -7
      api/book.py
  2. +1
    -1
      api/templates/goodreads.html.j2

+ 11
- 7
api/book.py View File

@ -14,14 +14,16 @@ import random
GOODREADS_RSS_URL = os.getenv("GOODREADS_RSS_URL") GOODREADS_RSS_URL = os.getenv("GOODREADS_RSS_URL")
PROGRESS_REGEX = r".*<img .* alt=\"([^\"]*) by ([^\"]*)\".*src=\"([^\"]*)\".*.* is on page ([0-9]*) of ([0-9]*) of <a.*" PROGRESS_REGEX = r".*<img .* alt=\"([^\"]*) by ([^\"]*)\".*src=\"([^\"]*)\".*.* is on page ([0-9]*) of ([0-9]*) of <a.*"
READ_REGEX = r".*<img .* alt=\"([^\"]*) by ([^\"]*)\".*src=\"([^\"]*)\".*"
READ_REGEX = r".*<img .* alt=\"([^\"]*) by ([^\"]*)\".*src=\"([^\"]*)\".*has read.*"
def loadImageB64(url): def loadImageB64(url):
resposne = requests.get(url) resposne = requests.get(url)
return b64encode(resposne.content).decode("ascii") return b64encode(resposne.content).decode("ascii")
def makeSVG(book, author, progress, img_url): def makeSVG(book, author, progress, img_url):
img = loadImageB64(img_url)
img = ''
if img_url != '':
img = loadImageB64(img_url)
dataDict = { dataDict = {
"progress": progress, "progress": progress,
@ -43,8 +45,10 @@ def last_activity(path):
entries = activityFeed.entries entries = activityFeed.entries
pr = re.compile(PROGRESS_REGEX) pr = re.compile(PROGRESS_REGEX)
rr = re.compile(READ_REGEX) rr = re.compile(READ_REGEX)
book, author, img, progress = '', '', '', ''
for i in entries: for i in entries:
i["summary"] = i["summary"].replace("&lt;","<").replace("&gt;",">").replace("&quot;","\"").replace("\n","") i["summary"] = i["summary"].replace("&lt;","<").replace("&gt;",">").replace("&quot;","\"").replace("\n","")
print(i["summary"])
res = pr.search(i["summary"]) res = pr.search(i["summary"])
if res: if res:
book, author, img = res.group(1,2,3) book, author, img = res.group(1,2,3)
@ -56,11 +60,11 @@ def last_activity(path):
progress = 100 progress = 100
else: else:
continue continue
svg = makeSVG(book, author, progress, img)
resp = Response(svg, mimetype="image/svg+xml")
resp.headers["Cache-Control"] = "s-maxage=1"
return resp
return data
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__": if __name__ == "__main__":
app.run(debug=True) app.run(debug=True)


+ 1
- 1
api/templates/goodreads.html.j2 View File

@ -87,9 +87,9 @@
} }
</style> </style>
{% if book_name %}
<div class="main"> <div class="main">
{% if book_name %}
<a class="art" href="{}" target="_BLANK"> <a class="art" href="{}" target="_BLANK">
<center> <center>
<img src="data:image/png;base64, {{img}}" class="cover" /> <img src="data:image/png;base64, {{img}}" class="cover" />


Loading…
Cancel
Save