From c578e5ecc1d59a5e8a535e64b642e65f8bbfac1d Mon Sep 17 00:00:00 2001 From: "theo@manjaro" Date: Wed, 20 Dec 2023 15:57:22 -0500 Subject: [PATCH] Show retroachievements awards on a dedicated page --- default_rareview.gmi | 7 ++++++ {fr => en}/about.gmi | 30 ++++++++-------------- page_template.html | 7 ++++-- publish.py | 55 ++++++++++++++++++++++++++++++++++++++--- ra.py | 37 +++++++++++++++------------ raindex_template.gmi | 11 +++++++++ rareview/signature.html | 3 +++ 7 files changed, 109 insertions(+), 41 deletions(-) create mode 100644 default_rareview.gmi rename {fr => en}/about.gmi (57%) create mode 100644 raindex_template.gmi create mode 100644 rareview/signature.html diff --git a/default_rareview.gmi b/default_rareview.gmi new file mode 100644 index 0000000..1237681 --- /dev/null +++ b/default_rareview.gmi @@ -0,0 +1,7 @@ +# $AWARDNAME + +Award got on the $AWARDDATE + +=> $AWARDGAMEURL View this game on RetroAchievements + +No review written yet, come back later! diff --git a/fr/about.gmi b/en/about.gmi similarity index 57% rename from fr/about.gmi rename to en/about.gmi index 1cdc4d0..233d27d 100644 --- a/fr/about.gmi +++ b/en/about.gmi @@ -5,6 +5,11 @@ => atom.xml Flux RSS complet => atom_fr.xml Flux RSS, en français seulement => atom_en.xml RSS feed, in English only +=> atom_rareview.xml RSS feed, only RetroAchievements reviews + +## Contact + +=> /contact.gmi Contact page ## En français (English at the bottom) @@ -12,22 +17,15 @@ Salut! Moi c'est Théo (il/iel), j'étudie l'informatique à l'Université de Strasbourg! -Affectif et fatigué, je suis un grand fan de jeux vidéos (principalement rétros). Mes favoris sont les jeux de plateforme, style Celeste, Super Meat Boy, 1001 Spikes, ou autres. J'ai eu la chance de grandir avec une GameBoy Color dans les mains, et une GameCube dans le salon. Je programme aussi quand j'en trouve la motivation, en python, en C, Lua ou en Zig. -Pendant mon temps libre, je m'intéresse aussi à la cuisine, à la philosophie, à l'éthique, et à la sociologie. À la croisée de ces intérêts se trouve mon régime végétarien. Il y a tellement de choses à découvrir, à changer, à faire. +Affectif et fatigué, je suis un grand fan de jeux vidéos (principalement rétros). Mes favoris sont les jeux de plateforme. Je programme aussi quand j'en trouve la motivation. +Pendant mon temps libre, je m'intéresse aussi à la cuisine, à la philosophie, à l'éthique, et à la sociologie. À la croisée de ces intérêts se trouve mon régime végétarien. ### À propos de ce site -#### Le contenu - -Ce que j'écris ici est avant tout destiné à mon moi du futur, n'implique donc que moi, et n'est pas professionnel. -Au lieu de me répéter si je dois expliquer quelque chose à des moments différents, j'écris. Formaliser mes idées m'aide beaucoup, cela me permet de me faire une mise au point, en plus de servir de mémo. - Ce site fait parti d'un webring, le fediring, rassemblant diverses sites (souvent anglophones) dont les auteur.e.s ont une présence sur le fédiverse. => https://fediring.net/ Le site du fediring -#### D'un point de vue technique - Généré à partir du même générateur que Ploum.net (même si légèrement modifié), un grand merci à ellui pour avoir laissé ses sources en libre accès! => https://ploum.net/ Le site de Ploum @@ -42,22 +40,16 @@ Mon site est hébergé chez sourcehut, est généré statiquement, et ne comport Hi! I'm Théo (he/they), studying computer science at Strasbourg's university (in France)! -I'm an always cuddly, often tired, video game fan (I mainly play retro ones these days). My favorites are platformer games, like Celeste, Super Meat Boy, 1001 Spikes, or others. I've been lucky enough to grow up with a GameBoy Color in my hand, and a GameCube in my living room. I'm also programming sometimes, in python, C, Lua and Zig. +I'm an always cuddly, often tired, video game fan (I mainly play retro ones these days). My favorites are platformer games. I'm also programming sometimes. I'm also interested in cooking, philosophy, ethics, and sociology. I try not to cause suffering, notably trough what I'm eating. -There's so much to discover, so much to change, so much to do, that sometimes it gets a bit scary. ### About this site -I'm mainly writing for myself and my future self, it is a personnal blog. Having my thoughts written somewhere is helpful when I need to explain the same thing at different times. -Writting also helps me focus on my thoughts. - This site is part of a webring, the fediring, composed of other great sites. The point of this one is to link people that have a presence on the fediverse. => https://fediring.net/ Fediring's website -#### On the technical side - -This site use the same generator (with some minor modifications) as Ploum's one. Huge thanks to them for making it! +This site use the same generator (with some modifications) as Ploum's one. Huge thanks to them for making it! => https://ploum.net/ Ploum's site @@ -65,9 +57,7 @@ My site is currently hosted at SourceHut's. => https://sr.ht/ SourceHut's site -## Contact - -=> /contact.gmi Contact page +## Misc I also made a 88x31 button for this site! You can integrate it in your site with the following code : diff --git a/page_template.html b/page_template.html index dfff72e..7bb8d0a 100644 --- a/page_template.html +++ b/page_template.html @@ -8,6 +8,7 @@ + @@ -54,7 +55,7 @@ a { color:var(--fg-alt); text-decoration:none; - padding:1em 0; + border:1em 0; } a:hover { text-decoration:underline; @@ -80,6 +81,7 @@ text-align: center; font-variant: small-caps; font-weight: bold; + padding: 1em; } .horizontal { text-align: center; @@ -102,7 +104,8 @@
diff --git a/publish.py b/publish.py index cd8613f..f2ae819 100755 --- a/publish.py +++ b/publish.py @@ -9,6 +9,8 @@ import html from datetime import datetime import textwrap import unicodedata +import ra +import racredentials global_title = "webair.xyz" global_subtitle = "Theo's web corner" @@ -33,6 +35,8 @@ old_post_url = ["2005-01-25","2013-05-17","2011-02-07","2012-03-19","2012-01-18" html_page_template = "page_template.html" email_template = "email_template.html" gemini_page_template = "page_template.gmi" +raindex_template = "raindex_template.gmi" +raindex_destination = "rareview/retroachievements.gmi" image_extensions = [".png", ".jpg", ".jpeg"] @@ -263,7 +267,7 @@ def build_list(allposts,folder,local=False): allposts = build_list(allposts,ff,local=local) elif f.endswith(".gmi") and "index" not in f and "template" not in f: if len(folder) > 2: - lang = folder[:2] + lang = folder else: lang = "fr" post = build_post(p,lang=lang,local=local) @@ -340,7 +344,7 @@ def build_index(allposts,folder,short=False): index = {} if folder: indexname = "index_" + folder.strip("/").replace("/","_") - lang = folder[:2] + lang = folder else: if short: indexname = "index" @@ -505,6 +509,43 @@ def copy_static_files(source, dest): os.popen(f"cp -r {source}/* {dest}/") +def generate_raindex(awards, dest): + content = "" + with open(raindex_template) as f: + content = f.read() + content += "\n" + for award in reversed(awards): + content += f"=> {award.url} {award.type} {award.name}\n" + with open(dest, "w") as f: + f.write(content) + + +def generate_default_rareviews(awards): + for award in awards: + default_page = "" + with open("default_rareview.gmi", "r") as f: + default_page = f.read() + filepath = Path(award.url) + # Check if a file with same name doesn't exists in current folder + if not os.path.exists(filepath): + # Check if a review was not already written + if not os.path.exists(os.path.join("rareview", filepath)): + # Write a default page + with open(filepath, "w") as f: + f.write( + default_page.replace("$AWARDNAME", award.name) + .replace("$AWARDDATE", award.date) + .replace("$AWARDGAMEURL", award.gameurl) + ) + # Build a post with it + post = build_post(filepath, lang="rareview") + writehtml(post) + writegmi(post) + os.remove(filepath) + else: + print(f"Warning, file {filepath} exists in root folder, skipping.") + + # Main call if __name__ == "__main__": # Check for the destination folders @@ -513,10 +554,14 @@ if __name__ == "__main__": os.mkdir(dir) all_posts = [] local = False + # Generate the RetroAchievements index page + awards = ra.getAwards(racredentials.user, racredentials.key) + generate_raindex(awards, raindex_destination) + # Normal generation if len(sys.argv) > 1: local = sys.argv[1] == "local" print("building locally") - for folder in ["", "fr", "en"]: + for folder in ["", "fr", "en", "rareview"]: all_posts = build_list(all_posts, folder, local=local) all_posts = build_index(all_posts, folder) write_atom_index(all_posts, folder) @@ -527,4 +572,8 @@ if __name__ == "__main__": for p in all_posts: writehtml(p) writegmi(p) + # Generate default RaReview pages + generate_default_rareviews(awards) + # Delete the generated raindex + os.remove(raindex_destination) copy_static_files("static", htmldir) diff --git a/ra.py b/ra.py index 30ff68a..23e559a 100644 --- a/ra.py +++ b/ra.py @@ -23,9 +23,11 @@ class Award: # Only keep letters, and replace spaces stripped = "" for c in name.strip(): - if ord("a") <= ord(c) <= ord("z") or ord("0") <= ord(c) <= ord("9"): + if ord("a") <= ord(c) <= ord("z"): stripped += c - elif c == " ": + elif ord("0") <= ord(c) <= ord("9"): + stripped += c + else: stripped += "-" # delete multiple following dashes splitted = stripped.split("-") @@ -42,21 +44,24 @@ def request(path): def getAwards(user, key): - response = request(f"API_GetUserAwards.php?z={user}&y={key}&u={user}")[ - "VisibleUserAwards" - ] - indexed = {} - # Returns only the mastered award - # in case there's both a completed and master award - for award in [Award(x) for x in response]: - if award.name in indexed.keys(): - if indexed[award.name].type == "Game Beaten": + response = request(f"API_GetUserAwards.php?z={user}&y={key}&u={user}") + if "VisibleUserAwards" in response.keys(): + response = response["VisibleUserAwards"] + indexed = {} + # Returns only the mastered award + # in case there's both a completed and master award + for award in [Award(x) for x in response]: + if award.name in indexed.keys(): + if indexed[award.name].type == "Game Beaten": + indexed[award.name] = award + else: indexed[award.name] = award - else: - indexed[award.name] = award - sorted = list(indexed.values()) - sorted.sort(key=lambda x: x.date) - return sorted + sorted = list(indexed.values()) + sorted.sort(key=lambda x: x.date) + return sorted + else: + print(response) + return [] if __name__ == "__main__": diff --git a/raindex_template.gmi b/raindex_template.gmi new file mode 100644 index 0000000..b6c9174 --- /dev/null +++ b/raindex_template.gmi @@ -0,0 +1,11 @@ +# RetroAchievements Awards + +Here's a list of my most recently mastered/completed games on RetroAchievements. + +=> https://retroachievements.org/user/ayte/ My profile + +I wrote reviews for some of them. + +=> /index_rareview.gmi All the reviews I wrote + +## The full list of awards diff --git a/rareview/signature.html b/rareview/signature.html new file mode 100644 index 0000000..dba47d9 --- /dev/null +++ b/rareview/signature.html @@ -0,0 +1,3 @@ +

If you can read this, then maybe you're interested in subscribing to my reviews by RSS.

+

You can see the full list of my RetroAchievements Awards here.

+

Thanks for your time ❤