Hayblock versions/0.1.0 Beta 2

import random # Various things needing a random thing import time # Time import datetime # Date and time import requests # Make HTTP requests import re # Regex import os # Generic py OS module stuff import shutil # File copy import json # Json stuff import urllib # More website things stuff
 * 1) Module imports

import hblang # "lang" module
 * 1) External file imports

code = open("code.txt","r").read.split("\n") logs = [] doing = 0 module = "" command = "" params = []
 * 1) Get code and define helper vars

showerrors = True errorcount = 0 ram = [] vars = {} lockedvars = [] imported = []
 * 1) Define more vars

posmodules = ["sys","var","math","tt","datetime","web","os","json","lang","coffee"]
 * 1) Define possible modules

def log(message): logs.append(f"At line {doing + 1}: {message}")
 * 1) Generic log and error functions

def error(message): log(f"Error at line {doing + 1}: {message}") global errorcount errorcount += 1 if showerrors: print(f"Error at line {doing + 1}:\n {message}")

str0to9 = ["0","1","2","3","4","5","6","7","8","9"]
 * 1) Is number checker

def isNumber(tocheck): hasdecimals = False for i in range(len(str(tocheck))): if not str(tocheck)[i] in str0to9: if str(tocheck)[i] == ".": hasdecimals = True else: return "nan" if hasdecimals: return "decimal" else: return "whole"

def getVar(varname): if varname in vars: return vars[varname] else: error(f"Attempted to get data in variable {varname}, which doesn't exist.")
 * 1) Get variable

def getType(tocheck): if str(tocheck)[0] == "\"":   return "string"  elif str(tocheck)[0] == "-":    return "varinput"  elif tocheck == "true" or tocheck == "false":    return "bool"  elif isNumber(tocheck) == "whole" or isNumber(tocheck) == "decimal":    return "number"  else:    return "invalid"
 * 1) Get type of variable

def tify(list): return ", ".join(list)
 * 1) Join list into commas

def param(num): # Use param(0) instead of params[0] try: if len(params[num]) < 1: error(f"Expected positional parameter {num + 1}, but nothing found.") else: return params[num] except IndexError: error(f"Expected positional parameter {num + 1}, but nothing found.")
 * 1) Get param/params

def funcReturn(message): print(f"A function returned: {message}") # Temporary
 * 1) Get what the function returned

def checkParam(wanted,tocheck): if getType(tocheck) == "string": if "string" in wanted: return tocheck[1:] else: error(f"Invalid data type given. Need {tify(wanted)}, but got {getType(tocheck)}.") elif getType(tocheck) == "bool": if "bool" in wanted: return tocheck else: error(f"Invalid data type given. Need {tify(wanted)}, but got {getType(tocheck)}.") elif getType(tocheck) == "number": if "number" in wanted: return tocheck else: error(f"Invalid data type given. Need {tify(wanted)}, but got {getType(tocheck)}.") elif getType(tocheck) == "varinput": return getVar(tocheck[1:]) else: error(f"Invalid data type given. Need {tify(wanted)}, but got {getType(tocheck)}.")
 * 1) Check parameter types and count

monthnames = { 1:"January", 2:"Febuary", 3:"March", 4:"April", 5:"May", 6:"June", 7:"July", 8:"August", 9:"September", 10:"October", 11:"November", 12:"December", } downames = { 0:"Monday", 1:"Tuesday", 2:"Wednesday", 3:"Thursday", 4:"Friday", 5:"Saturday", 6:"Sunday", }
 * 1) Utility dicts


 * 1) Start main loop

while len(code) > doing: if len(code[doing].replace(" ","")) < 1: log("A blank line has been skipped over.") doing += 1 elif f"{code[doing][0]}{code[doing][1]}" == "#-": log("A comment has been skipped over.") doing += 1 else: params = code[doing].split(".") try: module = params.pop(0) except IndexError: error("No module is found.") try: command = params.pop(0) except IndexError: error("No command is found.") if module in imported:

if module == "sys": if command == "print": print(checkParam(["string"],param(0))) elif module == "var": slr1 = checkParam(["string"],param(0)) if command == "create": if slr1 in vars: error(f"Variable {slr1} already exists.") else: vars[slr1] = "" elif command == "edit": if slr1 in lockedvars: error(f"Attempted to edit locked variable {slr1}.") elif slr1 in vars: vars[slr1] = checkParam(["string"],param(1)) else: error(f"Attempted to edit variable {slr1}, which doesn't exist.") elif command == "lock": if slr1 in lockedvars: error(f"Attempted to lock variable {slr1}, but it is already locked.") elif slr1 in vars: lockedvars.append(checkParam(["string"],param(0))) else: error(f"Attempted to lock variable {slr1}, but it doesn't exist.") elif command == "unlock": if slr1 in lockedvars: lockedvars.remove(checkParam(["string"],param(0))) elif slr1 in vars: error(f"Attempted to unlock variable {slr1}, but it is already unlocked.") else: error(f"Attempted to unlock variable {slr1}, but it doesn't exist.") elif command == "delete": if slr1 in lockedvars: error(f"Attempted to delete locked variable {slr1}.") elif slr1 in vars: del vars[slr1] else: error(f"Attempted to delete variable {slr1}, but it doesn't exist.") elif command == "list": if len(vars) < 1: error("No variables exist.") else: funcReturn(tify(vars)) elif command == "lockedlist": if len(lockedvars) < 1: error("No locked variables exist.") else: funcReturn(tify(lockedvars)) elif command == "type": funcReturn(getType(slr1)) elif command == "typecheck": funcReturn(checkParam(param(0),param(1))) elif command == "get": funcReturn(getVar(slr1)) elif command == "exists": funcReturn(str(slr1 in vars)) elif command == "islocked": funcReturn(str(slr1 in lockedvars))

elif module == "math": # Mostly generated by copilot slr1 = checkParam(["string"],param(0)) if command == "add": funcReturn(slr1 + checkParam(["number"],param(1))) elif command == "subtract": funcReturn(slr1 - checkParam(["number"],param(1))) elif command == "multiply": funcReturn(slr1 * checkParam(["number"],param(1))) elif command == "divide": funcReturn(slr1 / checkParam(["number"],param(1))) elif command == "modulo": funcReturn(slr1 % checkParam(["number"],param(1))) elif command == "power": funcReturn(slr1 ** checkParam(["number"],param(1))) elif command == "infinity": funcReturn("9" * 260) # Temporary elif command == "floor": funcReturn(math.floor(slr1)) elif command == "ceil": funcReturn(math.ceil(slr1)) elif command == "round": funcReturn(round(slr1)) elif command == "random": funcReturn(random.randint(slr1,checkParam(["number"],param(1)))) elif command == "truefalse": if random.randint(0,1) == 0: funcReturn("false") else: funcReturn("true") elif command == "pi": funcReturn(math.pi) elif command == "euler": funcReturn(math.e)       elif command == "tau": funcReturn(math.tau) elif command == "sin": funcReturn(math.sin(slr1)) elif command == "cos": funcReturn(math.cos(slr1)) elif command == "tan": funcReturn(math.tan(slr1)) elif command == "asin": funcReturn(math.asin(slr1)) elif command == "acos": funcReturn(math.acos(slr1)) elif command == "atan": funcReturn(math.atan(slr1)) elif command == "factorial": funcReturn(math.factorial(slr1)) elif command == "abs": funcReturn(math.fabs(slr1)) elif command == "deg": funcReturn(math.degrees(slr1)) elif command == "meanvalue": funcReturn(math.mean(slr1))

elif module == "tt": # TT = text tools = string module, most of the module is github copilot generated slr1 = checkParam(["string"],param(0)) if command == "length": funcReturn(len(slr1)) elif command == "upper": funcReturn(slr1.upper) elif command == "lower": funcReturn(slr1.lower) elif command == "sub": funcReturn(slr1[checkParam(["number"],param(1)):checkParam(["number"],param(2))]) elif command == "replace": funcReturn(slr1.replace(checkParam(["string"],param(1)),checkParam(["string"],param(2)))) elif command == "upfirst": funcReturn(slr1.capitalize) elif command == "upwords": funcReturn(slr1.title) elif command == "wrap": while " " in slr1: slr1 = slr1.replace(" "," ") funcReturn(slr1) elif command == "split": funcReturn(slr1.split(checkParam(["string"],param(1)))) elif command == "count": funcReturn(slr1.count(checkParam(["string"],param(1)))) elif command == "startswith": funcReturn(slr1.startswith(checkParam(["string"],param(1)))) elif command == "endswith": funcReturn(slr1.endswith(checkParam(["string"],param(1)))) elif command == "includes": funcReturn(slr1.find(checkParam(["string"],param(1))) != -1) elif command == "index": funcReturn(slr1.find(checkParam(["string"],param(1)))) elif command == "uplow": if slr1.islower: funcReturn("lower") elif slr1.isupper: funcReturn("upper") else: funcReturn("mixed") elif command == "isnum": funcReturn(slr1.isnumeric) elif command == "isblank": funcReturn(len(slr1.replace(" ","")) < 1) elif command == "findlast": funcReturn(slr1.rfind(checkParam(["string"],param(1)))) elif command == "swapcase": funcReturn(slr1.swapcase) elif command == "reverse": funcReturn(slr1[::-1]) elif command == "search": # Regex funcReturn(re.search(checkParam(["string"],param(1)),slr1)) elif command == "findall": # Another regex funcReturn(re.findall(checkParam(["string"],param(1)),slr1)) elif command == "split": # Even another regex funcReturn(re.split(checkParam(["string"],param(1)),slr1)) elif command == "sub": # Last regex funcReturn(re.sub(checkParam(["string"],param(1)),checkParam(["string"],param(2)),slr1)) elif command == "hasmainkeys": # A predefined regex funcReturn(not str(re.search("[a-zA-Z0-9]",slr1)) == "None")

elif module == "datetime": # Also mostly generated by copilot if command == "wait": time.sleep(checkParam(["number"],param(0))) elif command == "now": funcReturn(datetime.datetime.now) elif command == "timestamp": funcReturn(time.time) elif command == "millennium": funcReturn(datetime.datetime.now.year // 1000) elif command == "century": funcReturn(datetime.datetime.now.year // 100) elif command == "decade": funcReturn(datetime.datetime.now.year // 10) elif command == "year": funcReturn(datetime.datetime.now.year) elif command == "month": funcReturn(datetime.datetime.now.month) elif command == "monthname": funcReturn(monthnames[datetime.datetime.now.month]) elif command == "week": funcReturn(datetime.datetime.now.isocalendar[1]) elif command == "dow": # Day of week funcReturn(datetime.datetime.now.weekday) elif command == "downame": funcReturn(downames[datetime.datetime.now.weekday]) elif command == "day": funcReturn(datetime.datetime.now.day) elif command == "hour": funcReturn(datetime.datetime.now.hour) elif command == "minute": funcReturn(datetime.datetime.now.minute) elif command == "second": funcReturn(datetime.datetime.now.second) elif command == "ms": funcReturn(datetime.datetime.now.microsecond) elif command == "format": funcReturn(datetime.datetime.now.strftime(checkParam(["string"],param(0)))) elif command == "with": funcReturn(datetime.datetime.now + datetime.timedelta(checkParam(["number"],param(0)))) elif command == "diff": funcReturn(datetime.datetime.now - datetime.timedelta(checkParam(["number"],param(0)))) elif command == "date": funcReturn(datetime.datetime.now.date) elif command == "time": funcReturn(datetime.datetime.now.time)

elif module == "web": slr1 = checkParam(["string"],param(0)) if command == "gethtml": slr2 = requests.get(slr1) funcReturn(slr2.text) elif command == "request": slr2 = requests.request(checkParam(["string"],param(1)),slr1) funcReturn(slr2.text) elif command == "extract": funcReturn(re.search("(?P https?://[^\s]+)",slr1).group("url")) elif command == "extractall": funcReturn(re.findall("(?P https?://[^\s]+)",slr1).group("url")) elif command == "urlencode": funcReturn(urllib.parse.quote(slr1)) elif command == "urldecode": funcReturn(urllib.parse.unquote(slr1)) elif command == "hasahref": # Another predefined regex, detects for a href tags funcReturn(not str(re.search("]*?\s+)?href=([\"'])(.*?)\\1",slr1)) == "None")

elif module == "os": slr1 = checkParam(["string"],param(0)) if command == "openfile": curfile1 = open(slr1) elif command == "readfile": funcReturn(curfile1.read) elif command == "editfile": if os.path.exists(slr1): curfile1.write(slr1) else: error(f"File {slr1} doesn't exist and can't be edited.") elif command == "createfile": if os.path.exists(slr1): error(f"File {slr1} already exists.") else: curfile1 = open(slr1,"w") elif command == "deletefile": os.remove(slr1) elif command == "closefile": curfile1.close elif command == "exists": funcReturn(os.path.exists(slr1)) elif command == "isblank": if os.path.isfile(slr1): funcReturn(os.path.getsize(slr1) == 0) else: error(f"File {slr1} doesn't exist.") elif command == "iswritable": curfile1.writable elif command == "os": funcReturn(os.name) elif command == "cwd": funcReturn(os.getcwd) elif command == "exit": log("Exiting...") exit elif command == "changedir": os.chdir(slr1) elif command == "makedir": os.mkdir(slr1) elif command == "deldir": os.rmdir(slr1) elif command == "listdir": funcReturn(os.listdir(slr1)) elif command == "renamefile": os.rename(slr1,checkParam(["string"],param(1))) elif command == "copyfile": shutil.copyfile(slr1,checkParam(["string"],param(1))) elif module == "json": # Entirely copilot generated, so there might be duplicated/weirdly placed functions, this will be reviewed and corrected later on       slr1 = checkParam(["string"],param(0)) if command == "load": funcReturn(json.loads(slr1)) elif command == "dump": funcReturn(json.dumps(slr1)) elif command == "pretty": funcReturn(json.dumps(slr1,indent=2)) elif command == "get": funcReturn(json.loads(slr1)[checkParam(["string"],param(1))]) elif command == "set": slr2 = json.loads(slr1) slr2[checkParam(["string"],param(1))] = checkParam(["string"],param(2)) funcReturn(json.dumps(slr2)) elif command == "del": slr2 = json.loads(slr1) del slr2[checkParam(["string"],param(1))] funcReturn(json.dumps(slr2)) elif command == "keys": funcReturn(json.loads(slr1).keys) elif command == "values": funcReturn(json.loads(slr1).values) elif command == "items": funcReturn(json.loads(slr1).items) elif command == "len": funcReturn(len(json.loads(slr1))) elif command == "type": funcReturn(type(json.loads(slr1))) elif command == "isarray": funcReturn(isinstance(json.loads(slr1),list)) elif command == "isobject": funcReturn(isinstance(json.loads(slr1),dict)) elif command == "isstring": funcReturn(isinstance(json.loads(slr1),str)) elif command == "isnumber": funcReturn(isinstance(json.loads(slr1),int)) elif command == "isbool": funcReturn(isinstance(json.loads(slr1),bool)) elif command == "isnull": funcReturn(json.loads(slr1) == None) elif command == "isempty": funcReturn(json.loads(slr1) == "")

elif module == "lang": # Use slr1 (single line ram) when a parameter is required for every function in the module! if command == "translate": funcReturn(hblang.translateLangToLang(checkParam(["string"],param(0)),checkParam(["string"],param(1)),checkParam(["string"],param(2)))) elif command == "getlang": funcReturn(hblang.getLang(checkParam(["string"],param(0)))) elif command == "name": funcReturn(hblang.codeToLang(checkParam(["string"],param(0)))) elif command == "code": funcReturn(hblang.langToCode(checkParam(["string"],param(0)))) elif command == "accent": funcReturn(hblang.nameToAccent(checkParam(["string"],param(0)))) elif command == "whatis": funcReturn(hblang.accentToName(checkParam(["string"],param(0)))) elif command == "langs": funcReturn(hblang.allLangs) elif command == "accents": funcReturn(hblang.allAccents) elif module == "coffee": if command == "makecoffee": print("Okay, making the coffee, please wait a bit...") time.sleep(random.randint(2,6)) print("Coffee's done! \u2615")

elif module == "import": if command in imported: error(f"Module {command} can't be imported again because it is already imported.") elif command in posmodules: imported.append(command) else: error(f"Module {command} can't be imported because it doesn't exist.") elif module in posmodules: error(f"Module {module} is not imported.") else: error(f"Module {module} is not imported and doesn't exist.") doing += 1 : import requests

def translateLangToLang(text,fromLang,toLang): url = f"https://translate.googleapis.com/translate_a/single?client=gtx&sl={fromLang}&tl={toLang}&dt=t&q={text}" response = requests.get(url) response = response.json return response[0][0][0]

def getLang(text): url = f"https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=en&dt=t&q={text}" response = requests.get(url) response = response.json return response[2]

langcodes = { "af":"Afrikaans", "sq":"Albanian", "am":"Amharic", "ar":"Arabic", "hy":"Armenian", "az":"Azerbaijani", "eu":"Basque", "be":"Belarusian", "bn":"Bengali", "bs":"Bosnian", "bg":"Bulgarian", "ca":"Catalan", "ceb":"Cebuano", "ny":"Chichewa", "zh-CN":"Chinese (Simplified)", "zh-TW":"Chinese (Traditional)", "co":"Corsican", "hr":"Croatian", "cs":"Czech", "da":"Danish", "nl":"Dutch", "en":"English", "eo":"Esperanto", "et":"Estonian", "tl":"Filipino", "fi":"Finnish", "fr":"French", "fy":"Frisian", "gl":"Galician", "ka":"Georgian", "de":"German", "el":"Greek", "gu":"Gujarati", "ht":"Haitian Creole", "ha":"Hausa", "haw":"Hawaiian", "iw":"Hebrew", "hi":"Hindi", "hmn":"Hmong", "hu":"Hungarian", "is":"Icelandic", "ig":"Igbo", "id":"Indonesian", "ga":"Irish", "it":"Italian", "ja":"Japanese", "jw":"Javanese", "kn":"Kannada", "kk":"Kazakh", "km":"Khmer", "ko":"Korean", "ku":"Kurdish (Kurmanji)", "ky":"Kyrgyz", "lo":"Lao", "la":"Latin", "lv":"Latvian", "lt":"Lithuanian", "lb":"Luxembourgish", "mk":"Macedonian", "mg":"Malagasy", "ms":"Malay", "ml":"Malayalam", "mt":"Maltese", "mi":"Maori", "mr":"Marathi", "mn":"Mongolian", "my":"Myanmar (Burmese)", "ne":"Nepali", "no":"Norwegian", "ps":"Pashto", "fa":"Persian", "pl":"Polish", "pt":"Portuguese", "ma":"Punjabi", "ro":"Romanian", "ru":"Russian", "sm":"Samoan", "sr":"Serbian", "st":"Sesotho", "sn":"Shona", "sd":"Sindhi", "si":"Sinhala", "sk":"Slovak", "sl":"Slovenian", "so":"Somali", "es":"Spanish", "su":"Sundanese", "sw":"Swahili", "sv":"Swedish", "tg":"Tajik", "ta":"Tamil", "te":"Telugu", "th":"Thai", "tr":"Turkish", "uk":"Ukrainian", "ur":"Urdu", "uz":"Uzbek", "vi":"Vietnamese", "cy":"Welsh", "xh":"Xhosa", "yi":"Yiddish", "yo":"Yoruba", "zu":"Zulu" }

def codeToLang(code): try: return langcodes[code] except KeyError: return "unk"

def langToCode(lang): for key, value in langcodes.items: if value == lang: return key return "Unknown"

accents = { "Acute":"◌́ ", "Grave":"◌̀ ", "Circ":"◌̂ ", "Tilde":"◌̃ ", "Macr":"◌̄ ", "Breve":"◌̆ ", "Dot":"◌̇ ", "Dblac":"◌̈ ", "Ring":"◌̊ ", "Cedil":"◌̌ ", "Ogon":"◌̋ ", }

def nameToAccent(name): try: return accents[name] except KeyError: return "unk"

def accentToName(accent): for key, value in accents.items: if value == accent: return key return "Unknown"

allLangs = langcodes.values allAccents = accents.keys
 * 1) Both of these returns tuple-like things for now, will fix later