@21natzil/

Community Repl

Python

The repl for everyone

fork
loading
Files
  • main.py
  • H.py
  • haz.py
  • kogs.py
  • test.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import importlib
import os

def collect_projects():
	mods = []
	for file in os.listdir('.'):
		if not file.endswith('.py') or file.startswith('_'):
			continue
		module = importlib.import_module(file[:-3])
		if hasattr(module, 'META'):
			mods.append(module)
	return mods


if __name__ == '__main__':
	print("Welcome to the community repl! This repl is for everyone, but we do ask that you respect these rules: Do not edit the main.py file, or anyone else's unless given permission.")

	print("Select a project, or enter 'create' to make your own project.")
	projects = collect_projects()
	for mod in projects:
		print("  * {title} | By {author} | {desc}".format(**mod.META))
	while True:
		option = input("> ")
		if option.lower() == 'create':
			print("To make your own project, make sure you have a dict at global level named META, with keys 'title', 'author' and 'desc'. Then, your project must have a run function, which will be called when someone useses the project.")
		else:
			p = next((p for p in projects if p.META['title'] == option), None)
			if p is None:
				print("Could not find project '{}'".format(option))
			else:
				p.run()
				print("Project ended!")