Commit c2b06599 authored by Marius DAVID's avatar Marius DAVID
Browse files

More update for 2025

parent 8f7833c2
Loading
Loading
Loading
Loading
Loading
+9 −9
Original line number Diff line number Diff line
@@ -12,8 +12,8 @@ def slugify(s):
	return s

class EntryManager:
	def __init__(self):
		self.folder = "entries/"
	def __init__(self, folder):
		self.folder = folder
		self.load_data()

	def load_data(self):
+42 −25
Original line number Diff line number Diff line
@@ -6,11 +6,25 @@
from entry_manager import EntryManager
#from lib.github_forge import GithubForge
from lib.gitlab_forge import GitlabForge
from click import edit
import hashlib

EDITIONS = {
	"2024": {
		"community": "2024lemmycanvasatlas",
		"entry_folder": "entries/"
	},
	"2025": {
		"community": "2025fedicanvasatlas",
		"entry_folder": "entries2025/"
	}
}

class LemmyFetcher:
	def __init__(self, entry_manager):
		self.entry_manager = entry_manager
	def __init__(self, edition):
		assert edition in EDITIONS
		self.edition = edition
		self.entry_manager = EntryManager(EDITIONS[self.edition]["entry_folder"])
		self.forge = GitlabForge()
		self.forge.from_env()
		self.read_ids = set()
@@ -46,7 +60,7 @@ def mark_post_as_failed(self, post_id, body):
	def hash_body(self, body):
		return hashlib.md5(body.encode()).hexdigest()

	def process_post(self, post_body, make_pr = False):
	def process_post(self, post_body, make_pr):
		post_id = post_body["id"]

		if str(post_id) in self.read_ids:
@@ -93,7 +107,7 @@ def process_post(self, post_body, make_pr = False):
			if branch != "main":
				raise BaseException("Not on main branch, refusing to continue: " + branch)
			# check if any content in entries is dirty
			if "entries/" in subprocess.check_output(["git", "status", "--porcelain"], text=True):
			if EDITIONS[self.edition]["entry_folder"] in subprocess.check_output(["git", "status", "--porcelain"], text=True):
				raise BaseException("Some change in entries are uncommited, refusing to continue")
			# check new branch does not already exist
			if new_branch_name in subprocess.check_output(["git", "branch", "--list", new_branch_name], text=True):
@@ -112,7 +126,7 @@ def process_post(self, post_body, make_pr = False):

		if make_pr:
			if success:
				subprocess.check_call(["git", "add", "entries/"])
				subprocess.check_call(["git", "add", EDITIONS[self.edition]["entry_folder"]])
				subprocess.check_call(["git", "-c", "user.name=lemmy_canvas_bot", "-c", "user.email=lemmy_canvas_bot@mariusdavid.fr", "commit", "-m", "Add submission from Lemmy post " + str(post_id)])
				subprocess.check_call(["git", "push", "--force", "origin", new_branch_name])
				pr_url = self.forge.does_pr_already_exist(new_branch_name)
@@ -123,7 +137,7 @@ def process_post(self, post_body, make_pr = False):
					print("branch pushed, PR already exists")
				self.send_comment(post_id, "Thanks for your submission! The automatic PR has been opened at: " + pr_url)
			else:
				subprocess.check_call(["git", "restore", "--source=HEAD", "entries/"])
				subprocess.check_call(["git", "restore", "--source=HEAD", EDITIONS[self.edition]["entry_folder"]])
			subprocess.check_call(["git", "checkout", "main"])
			self.read_ids.add(str(post_id))
			f = open("processed_posts/" + str(post_id), "w")
@@ -142,7 +156,7 @@ def send_comment(self, post_id, comment):

	def crawl_latest(self):
		req = requests.get("https://toast.ooo/api/v3/post/list", params={
			"community_name": "2024lemmycanvasatlas",
			"community_name": EDITIONS[self.edition]["community"],
			"type_": "All",
			"sort": "New",
			"limit": 50
@@ -152,15 +166,18 @@ def crawl_latest(self):

		data = req.json()

		print("Fetched " + str(len(data["posts"])) + " post fetched");
		for post in data["posts"]:
			try:
				self.process_post(post["post"], True)
			except Exception as e:
				print("Failed to process post in an horrible way: " + str(post["post"]["id"]) + ": " + str(e))
				print("Failed to process post in an horrible way: " + str(post["post"]["id"]) + " edition " + str(self.edition) + " : " + str(e))
				print(traceback.format_exc())
				subprocess.check_call(["git", "checkout", "main"])


em = EntryManager()
lm = LemmyFetcher(em)
lm.crawl_latest()
 No newline at end of file
lm2025 = LemmyFetcher("2025")
lm2025.crawl_latest()

lm2024 = LemmyFetcher("2024")
lm2024.crawl_latest()
(321 KiB)

File moved.

Preview suppressed by a .gitattributes entry or the file's encoding is unsupported.

+57.7 KiB
Loading image diff...
+2 −2
Original line number Diff line number Diff line
@@ -47,7 +47,7 @@ const variationsConfig = {
		versions: [
			{
				timestamp: "Final",
				url: "./_img/fedicanvas/final.png",
				url: "./_img/fedicanvas2024/final.png",
			}
		],
		icon: '<svg width="14" height="14" version="1.1" viewBox="0 0 14 14" xmlns="http://www.w3.org/2000/svg" fill="currentColor"><g><rect y="8" width="6" height="6"/><rect x="6" width="8" height="8"/></g></svg>'
Loading