@21natzil/

Code Jam 5 (A5rocks#9289)

Python

Today is the day I stay in obscurity!

fork
loading
Files
  • main.py
  • models.py
  • requirements.txt

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.4435422647920899","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"CgojIE9rYXksIHRoaXMgaXMgRVBJQwojICBfX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18KIyAvICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgXAojIHwgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICB8CiMgfCAgICAgIFRoZSBweU5JWCBPcGVyYXRpbmcgU3lzdGVtICAgICAgIHwKIyB8ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgfAojIFxfX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX18vCiMKIwojIFZpc2l0IHRoZSB3ZWJzaXRlIGZvciB0aGUgZG9jdW1lbnRhdGlvbiA6IAojCiMgQ2hlY2sgb3V0IHRoZSBwYWNrYWdlIG1hbmFnZXIgOgoKIyBUT0RPOiBtb25nb2RiCgojIFRoZSBQYWNrYWdlIEltcG9ydGVyIChjcmVkaXRzIHRvIGh0dHBzOi8vc3RhY2tvdmVyZmxvdy5jb20vcXVlc3Rpb25zLzE4NzQ3MDQzL2ltcG9ydC1weXRob24tbW9kdWxlLW92ZXItdGhlLWludGVybmV0LW11bHRpcGxlLXByb3RvY29scy1vci1keW5hbWljYWxseS1jcmVhdGUpCiMgTWFrZSB0aGUgcGFja2FnZSBpbXBvcnRlcgoKZnJvbSByZXF1ZXN0cyBpbXBvcnQgZ2V0CmZyb20gaW1wIGltcG9ydCBuZXdfbW9kdWxlCmZyb20gbW9kZWxzIGltcG9ydCAqCmRlZiBwa2dfYWRkKHBrZ19uYW1lKToKCXJvb3QgPSAnaHR0cDovL3B5bml4LS1hNXJvY2tzLnJlcGwuY28vcGtnLWNvbnRyb2w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46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77

# Okay, this is EPIC
#  _______________________________________
# /                                       \
# |                                       |
# |      The pyNIX Operating System       |
# |                                       |
# \_______________________________________/
#
#
# Visit the website for the documentation : 
#
# Check out the package manager :

# TODO: mongodb

# The Package Importer (credits to https://stackoverflow.com/questions/18747043/import-python-module-over-the-internet-multiple-protocols-or-dynamically-create)
# Make the package importer

from requests import get
from imp import new_module
from models import *
def pkg_add(pkg_name):
	root = 'http://pynix--a5rocks.repl.co/pkg-control/'
	package_valid = get(f'{root}{pkg_name}/valid').text
	if package_valid == 'True':
		package_code = get(f'{root}{pkg_name}/pkg.py').text
		pkg_module = new_module(pkg_name)
		exec(package_code, pkg_module.__dict__)
		return pkg_module
	else:
		raise ValueError

# Initialization
user = User()
pkgs = []
command_list = {}
default_pkgs = ['authentication', 'filesystem']

for pkg in default_pkgs:
	pkgs.append(pkg_add(pkg))
	command_list.update(pkgs[-1].commands)

# The loop behind the OS
while True:
	command_and_args = input(f'@{user.username}: ')
	command = command_and_args.split(' ')[0].lower()
	args = command_and_args.split(' ')[1:]
	command_context = Context(user, command_and_args)

	# Package control first
	if command == 'pkg':
		if args == []:
			print('You entered nothing!')
		elif args[0] == 'add':
			if len(args) == 1:
				print('Please include a package to add')
			else:
				try:
					pkgs.append(pkg_add(args[1]))
				except:
					print(f'\'{args[1]}\' is not an available package. Run \'pkg list\' to get all the available packages.')
				else:
					command_list.update(pkgs[-1].commands)
		elif args[0] == 'list':
			print(get('https://pynix--a5rocks.repl.co/pkg-control/list/source.txt').text)
		elif args[0] == 'current':
			print('\n'.join([str(pkg) for pkg in pkgs]))
	elif command in command_list:
		try:
			print(command_list[command](command_context))
		except Exception as e:
			print(f'\'{command}\' failed because of:\n{e}')
	else:
		print(f'\'{command}\' is not a loaded command.')
	print('')