-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp Initialiser.py
More file actions
51 lines (46 loc) · 11.1 KB
/
App Initialiser.py
File metadata and controls
51 lines (46 loc) · 11.1 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import os
# Define the folder and file structure
structure = {
"index.html": None,
"README.md": None,
"LICENSE.md": "# Creative Commons Attribution 4.0 International License (CC BY 4.0)\n\n© Copyright 2025 kay-who-codes\n\nYou are free to:\n\n- **Share** — copy and redistribute the material in any medium, mode, or format for any purpose, even commercially.\n- **Adapt** — remix, transform, and build upon the material for any purpose, even commercially.\n\nThe above rights are granted on the following condition:\n\n- **Attribution** — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.\n\nNo additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.\n\n[Full text of the license](https://creativecommons.org/licenses/by/4.0/)",
"js": {
"app.js": None,
"header.js": "// ADD HEADER\nfetch('https://kay-who-codes.github.io/Kay-App-Assets/Full-Header.html')\n .then(response => {\n if (!response.ok) {\n throw new Error('Failed to load header');\n }\n return response.text();\n })\n .then(data => {\n document.getElementById('header').innerHTML = data;\n\n // Update the header link dynamically\n const headerLink = document.querySelector('.header-link');\n if (headerLink) {\n // Option 1: Extract from URL\n const pathSegments = window.location.pathname.split('/').filter(segment => segment);\n const repoName = pathSegments[0] || 'APP_NAME_GOES_HERE';\n const appName = repoName.replace(/-/g, ' ');\n \n headerLink.textContent = appName;\n headerLink.href = `https://github.com/kay-who-codes/${repoName}`;\n }\n\n // Add event listeners after injecting the header\n const dropbtn = document.querySelector('.dropbtn');\n if (dropbtn) {\n dropbtn.addEventListener('click', toggleDropdown);\n }\n\n // Close dropdown when clicking outside\n window.addEventListener('click', (event) => {\n const dropdown = document.querySelector('.dropdown');\n if (dropdown && !dropdown.contains(event.target)) {\n dropdown.classList.remove('show');\n }\n });\n })\n .catch(error => {\n console.error('Error loading header:', error);\n document.getElementById('header').innerHTML = '<p>Header failed to load.</p>';\n });\n\n// Toggle dropdown visibility\nfunction toggleDropdown() {\n const dropdown = document.querySelector('.dropdown');\n dropdown.classList.toggle('show');\n}",
},
"css": {
"style.css": None,
"header.css": " /* Header Bar Styles */\n .header-bar {\n position: absolute; /* Ensures it stays at the top of the page, not fixed on the screen */\n top: 0;\n left: 0;\n width: 100%;\n display: flex;\n justify-content: space-between;\n align-items: center;\n padding: 5px 10px;\n background-color: #3b3b3b00;\n color: var(--text-color);\n z-index: 1000; /* Ensures it stays above other content */\n transition: background-color 0.3s ease, color 0.3s ease;\n }\n \n .header-link {\n color: #b8b8b8dc;\n font-size: 20px;\n text-decoration: none;\n font-weight: bold;\n margin-left: 10px;\n }\n\n .header-link:hover {\n color: #757575;\n }\n\n /* Dropdown menu styles */\n .dropdown {\n position: relative;\n }\n\n .dropbtn {\n background-color: #505050ec;\n color: white;\n padding: 8px 16px;\n border: none;\n border-radius: 5px;\n cursor: pointer;\n font-size: 16px;\n margin-right: 15px;\n }\n\n .dropbtn:hover {\n background-color: #333;\n }\n\n .dropdown-content {\n display: none;\n position: absolute;\n right: 0;\n background-color: #1d1d1d;\n border: 1px solid #535353;\n border-radius: 5px;\n box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);\n z-index: 1001;\n min-width: 220px;\n max-height: 380px; /* Set a maximum height for the dropdown */\n overflow-y: auto; /* Enable vertical scrolling */\n padding: 10px 0;\n }\n\n .dropdown-content a {\n color: white;\n text-decoration: none;\n padding: 8px 16px;\n display: block;\n font-size: 14px;\n }\n\n .dropdown-content a:hover {\n background-color: #535353;\n }\n\n .dropdown.show .dropdown-content {\n display: block;\n }",
},
"Non App": {
"Update Log": {
"Update Logger.py": "import os\nfrom datetime import datetime\nfrom tkinter import Tk, Label, Entry, Button, StringVar, messagebox\n\n# Get the directory of the current script\nscript_dir = os.path.dirname(os.path.abspath(__file__))\nfile_path = os.path.join(script_dir, \"Update Log.txt\")\n\ndef save_update(update_details):\n update_number = 1\n current_datetime = datetime.now().strftime(\"%d %b %Y @ %H:%M\")\n \n if os.path.exists(file_path):\n with open(file_path, \"r\") as file:\n content = file.read()\n # Count the number of updates\n update_number = content.count(\"App Update:\") + 1\n \n new_entry = (\n f\"App Update: {update_number}\\n\"\n f\"Date of Update: {current_datetime}\\n\"\n f\"Details: {update_details}\\n\\n\"\n )\n \n with open(file_path, \"a\") as file:\n file.write(new_entry)\n \n messagebox.showinfo(\"Success\", f\"Update logged successfully as entry {update_number}.\")\n\ndef create_gui():\n def on_submit(event=None):\n details = update_details.get()\n if not details.strip():\n messagebox.showwarning(\"Input Error\", \"Please provide update details.\")\n return\n save_update(details)\n root.destroy()\n\n # GUI setup\n root = Tk()\n root.title(\"Update Logger\")\n root.geometry(\"400x200\")\n root.configure(bg=\"white\")\n\n Label(\n root, \n text=\"Update details:\", \n bg=\"white\", \n fg=\"black\", \n font=(\"Arial\", 12, \"bold\")\n ).pack(pady=10)\n\n update_details = StringVar()\n entry = Entry(\n root, \n textvariable=update_details, \n font=(\"Arial\", 12), \n width=40, \n bg=\"lightgrey\"\n )\n entry.pack(pady=5)\n entry.focus_set()\n\n Button(\n root, \n text=\"Submit\", \n command=on_submit, \n bg=\"blue\", \n fg=\"white\", \n font=(\"Arial\", 12, \"bold\")\n ).pack(pady=20)\n\n root.bind('<Return>', on_submit)\n\n root.mainloop()\n\n# Main Execution\nif __name__ == \"__main__\":\n create_gui()",
},
},
"Assets": {
"click.txt": None,
},
".github": {
"workflows": {
"Publish and Host.yml": "name: Publish and Host\n\non:\n workflow_dispatch: # Allows manual triggering from the GitHub UI\n\njobs:\n change_visibility_and_publish:\n runs-on: ubuntu-latest\n steps:\n - name: Change repository visibility to public\n env:\n Kay_PAT: ${{ secrets.Kay_PAT }}\n OWNER: ${{ github.repository_owner }}\n REPO: ${{ github.event.repository.name }}\n run: |\n echo \"Making repository public...\"\n RESPONSE=$(curl -L -X PATCH https://api.github.com/repos/$OWNER/$REPO \\\n -H \"Authorization: token $Kay_PAT\" \\\n -H \"Accept: application/vnd.github.v3+json\" \\\n -d '{\"private\": false}')\n \n echo \"Response: $RESPONSE\"\n \n if echo \"$RESPONSE\" | grep -q \"Bad credentials\"; then\n echo \"ERROR: Invalid GitHub token!\"\n exit 1\n fi\n \n echo \"Repository is now public.\"\n\n - name: Checkout Repository\n uses: actions/checkout@v4\n\n - name: Enable GitHub Pages from the Main Branch\n env:\n Kay_PAT: ${{ secrets.Kay_PAT }}\n OWNER: ${{ github.repository_owner }}\n REPO: ${{ github.event.repository.name }}\n run: |\n echo \"Enabling GitHub Pages from the main branch...\"\n curl -L -X POST https://api.github.com/repos/$OWNER/$REPO/pages \\\n -H \"Authorization: token $Kay_PAT\" \\\n -H \"Accept: application/vnd.github.v3+json\" \\\n -d '{\"source\":{\"branch\":\"main\",\"path\":\"/\"}}'\n\n - name: Deploy GitHub Pages\n uses: peaceiris/actions-gh-pages@v4\n with:\n github_token: ${{ secrets.Kay_PAT }}\n publish_dir: ./ # Adjust if needed (e.g., `./docs` or `./public`)",
"Unhost & Privatise.yml": "name: Unhost & Privatise\n\non:\n workflow_dispatch: # Allows manual triggering from the GitHub UI\n\njobs:\n remove_pages_and_make_private:\n runs-on: ubuntu-latest\n steps:\n - name: Remove GitHub Pages Deployment\n env:\n Kay_PAT: ${{ secrets.Kay_PAT }}\n OWNER: ${{ github.repository_owner }}\n REPO: ${{ github.event.repository.name }}\n run: |\n echo \"Disabling GitHub Pages for repository...\"\n RESPONSE=$(curl -L -X DELETE https://api.github.com/repos/$OWNER/$REPO/pages \\\n -H \"Authorization: token $Kay_PAT\" \\\n -H \"Accept: application/vnd.github.v3+json\")\n\n echo \"Response: $RESPONSE\"\n\n if echo \"$RESPONSE\" | grep -q \"Bad credentials\"; then\n echo \"ERROR: Invalid GitHub token!\"\n exit 1\n fi\n \n echo \"GitHub Pages has been disabled.\"\n\n - name: Make Repository Private\n env:\n Kay_PAT: ${{ secrets.Kay_PAT }}\n OWNER: ${{ github.repository_owner }}\n REPO: ${{ github.event.repository.name }}\n run: |\n echo \"Making repository private...\"\n RESPONSE=$(curl -L -X PATCH https://api.github.com/repos/$OWNER/$REPO \\\n -H \"Authorization: token $Kay_PAT\" \\\n -H \"Accept: application/vnd.github.v3+json\" \\\n -d '{\"private\": true}')\n \n echo \"Response: $RESPONSE\"\n \n if echo \"$RESPONSE\" | grep -q \"Bad credentials\"; then\n echo \"ERROR: Invalid GitHub token!\"\n exit 1\n fi\n\n echo \"Repository is now private.\"",
},
},
}
def create_structure(base_path, structure):
for name, content in structure.items():
path = os.path.join(base_path, name)
if isinstance(content, dict):
# Create a directory and recurse
os.makedirs(path, exist_ok=True)
create_structure(path, content)
else:
# Create a file with pre-populated content (if provided)
with open(path, "w") as f:
if content is not None:
f.write(content)
# Get the directory where the script is located
script_dir = os.path.dirname(os.path.abspath(__file__))
# Create the folder and file structure
create_structure(script_dir, structure)
print("Folder and file structure created successfully with pre-populated content.")