Skip to content

Commit

Permalink
Added more countries, and improved code
Browse files Browse the repository at this point in the history
  • Loading branch information
kay-who-codes authored Feb 1, 2025
1 parent b7259e9 commit 9fed8f5
Show file tree
Hide file tree
Showing 7 changed files with 261 additions and 104 deletions.
16 changes: 16 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Creative Commons Attribution 4.0 International License (CC BY 4.0)

Copyright 2025 kay-who-codes

You are free to:

- **Share** — copy and redistribute the material in any medium, mode, or format for any purpose, even commercially.
- **Adapt** — remix, transform, and build upon the material for any purpose, even commercially.

The above rights are granted on the following condition:

- **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.

No additional restrictions — You may not apply legal terms or technological measures that legally restrict others from doing anything the license permits.

[Full text of the license](https://creativecommons.org/licenses/by/4.0/)
54 changes: 54 additions & 0 deletions Non-App/Code Text Grabber v2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import os
import json
import pyperclip

def collect_files_and_copy():
# Get the script's current directory
current_dir = os.path.dirname(os.path.abspath(__file__))

# Initialise file contents
html_content = ''
css_content = ''
js_content = ''
json_extracts = ''

# Loop through files in the current directory
for filename in os.listdir(current_dir):
file_path = os.path.join(current_dir, filename)

# Skip the script itself
if filename == os.path.basename(__file__):
continue

# Read the content of .html, .css, .js, and .json files
if filename.endswith('.html'):
with open(file_path, 'r', encoding='utf-8') as file:
html_content = file.read()
elif filename.endswith('.css'):
with open(file_path, 'r', encoding='utf-8') as file:
css_content = file.read()
elif filename.endswith('.js'):
with open(file_path, 'r', encoding='utf-8') as file:
js_content = file.read()
elif filename.endswith('.json'):
with open(file_path, 'r', encoding='utf-8') as file:
try:
json_data = json.load(file)
if isinstance(json_data, list) and json_data:
first_object = json_data[0]
last_object = json_data[-1]
json_extracts += (f"\n\nFor your reference, here's an extract of the .json data found in \"{filename}\":\n"
f"[\n{first_object},\n{last_object}\n]")
except json.JSONDecodeError:
print(f"Warning: Could not parse JSON file: {filename}")

# Prepare the formatted text
formatted_text = (f".HTML: {html_content}\n\n.CSS: {css_content}\n\n.JS: {js_content}"
f"{json_extracts}")

# Copy the formatted text to the clipboard
pyperclip.copy(formatted_text)
print("Formatted text has been copied to the clipboard.")

# Run the function
collect_files_and_copy()
79 changes: 79 additions & 0 deletions Non-App/Update Log/App Update Logger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import os
from datetime import datetime
from tkinter import Tk, Label, Entry, Button, StringVar, messagebox

# Get the directory of the current script
script_dir = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(script_dir, "Update Log.txt")

def save_update(update_details):
update_number = 1
current_datetime = datetime.now().strftime("%d %b %Y @ %H:%M")

if os.path.exists(file_path):
with open(file_path, "r") as file:
content = file.read()
# Count the number of updates
update_number = content.count("App Update:") + 1

new_entry = (
f"App Update: {update_number}\n"
f"Date of Update: {current_datetime}\n"
f"Details: {update_details}\n\n"
)

with open(file_path, "a") as file:
file.write(new_entry)

messagebox.showinfo("Success", f"Update logged successfully as entry {update_number}.")

def create_gui():
def on_submit(event=None):
details = update_details.get()
if not details.strip():
messagebox.showwarning("Input Error", "Please provide update details.")
return
save_update(details)
root.destroy()

# GUI setup
root = Tk()
root.title("Update Logger")
root.geometry("400x200")
root.configure(bg="white")

Label(
root,
text="Update details:",
bg="white",
fg="black",
font=("Arial", 12, "bold")
).pack(pady=10)

update_details = StringVar()
entry = Entry(
root,
textvariable=update_details,
font=("Arial", 12),
width=40,
bg="lightgrey"
)
entry.pack(pady=5)
entry.focus_set()

Button(
root,
text="Submit",
command=on_submit,
bg="blue",
fg="white",
font=("Arial", 12, "bold")
).pack(pady=20)

root.bind('<Return>', on_submit)

root.mainloop()

# Main Execution
if __name__ == "__main__":
create_gui()
4 changes: 4 additions & 0 deletions Non-App/Update Log/Update Log.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
App Update: 1
Date of Update: 01 Feb 2025 @ 12:06
Details: Added more countries

123 changes: 19 additions & 104 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,104 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>World Economic Clocks</title>
<style>
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #121212;
color: #fff;
margin: 20px;
}
h1 {
font-size: 2.5em;
margin: 20px 0;
color: #f1c40f;
}
.time-container {
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
}
.country-time {
font-size: 1.5em;
padding: 10px;
border-radius: 8px;
background: #222;
width: 350px;
text-align: center;
}
</style>
</head>
<body>

<div class="time-container" id="before-london"></div>

<h1>🏴󠁧󠁢󠁥󠁮󠁧󠁿 London: <span id="london-time"></span></h1>

<div class="time-container" id="after-london"></div>

<script>
// Predefined offsets relative to GMT
const countries = [
{ name: "🇺🇸 USA", city: "Los Angeles", tz: "America/Los_Angeles", offsetGMT: -8 },
{ name: "🇧🇷 Brazil", city: "São Paulo", tz: "America/Sao_Paulo", offsetGMT: -3 },
{ name: "🇺🇸 USA", city: "New York", tz: "America/New_York", offsetGMT: -5 },
{ name: "🇨🇦 Canada", city: "Toronto", tz: "America/Toronto", offsetGMT: -5 },
{ name: "🇩🇪 Germany", city: "Berlin", tz: "Europe/Berlin", offsetGMT: 1 },
{ name: "🇫🇷 France", city: "Paris", tz: "Europe/Paris", offsetGMT: 1 },
{ name: "🇮🇹 Italy", city: "Rome", tz: "Europe/Rome", offsetGMT: 1 },
{ name: "🇷🇺 Russia", city: "Moscow", tz: "Europe/Moscow", offsetGMT: 3 },
{ name: "🇦🇪 UAE", city: "Dubai", tz: "Asia/Dubai", offsetGMT: 4 },
{ name: "🇮🇳 India", city: "Delhi", tz: "Asia/Kolkata", offsetGMT: 5.5 },
{ name: "🇨🇳 China", city: "Beijing", tz: "Asia/Shanghai", offsetGMT: 8 },
{ name: "🇯🇵 Japan", city: "Tokyo", tz: "Asia/Tokyo", offsetGMT: 9 },
{ name: "🇦🇺 Australia", city: "Sydney", tz: "Australia/Sydney", offsetGMT: 11 }
];

function updateTime() {
const now = new Date();

// Get London time
const londonTime = now.toLocaleTimeString("en-GB", { timeZone: "Europe/London", hour: "2-digit", minute: "2-digit", second: "2-digit" });
document.getElementById("london-time").innerText = londonTime;

// Get London's GMT offset dynamically in case of daylight savings
const londonOffset = new Date().getTimezoneOffset() / -60; // Offset in hours

// Sort countries from earliest to latest based on actual GMT offset
const sortedCountries = countries
.map(country => {
const time = now.toLocaleTimeString("en-GB", { timeZone: country.tz, hour: "2-digit", minute: "2-digit" });
const offset = country.offsetGMT - londonOffset;
return { ...country, time, offset };
})
.sort((a, b) => a.offset - b.offset); // Sort by actual offset

const beforeLondon = [];
const afterLondon = [];

sortedCountries.forEach(country => {
const offsetText = country.offset > 0 ? `+${country.offset}` : country.offset;
const countryHTML = `<div class="country-time">${country.name} ${offsetText} (${country.city}): ${country.time}</div>`;

if (country.offset < 0) {
beforeLondon.push(countryHTML);
} else {
afterLondon.push(countryHTML);
}
});

document.getElementById("before-london").innerHTML = beforeLondon.join("");
document.getElementById("after-london").innerHTML = afterLondon.join("");
}

updateTime();
setInterval(updateTime, 1000);
</script>

</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>World Economic Clocks</title>
<link rel="stylesheet" href="style.css">
</head>
<body>

<div class="time-container" id="before-london"></div>

<h1>🏴󠁧󠁢󠁥󠁮󠁧󠁿 London: <span id="london-time"></span></h1>

<div class="time-container" id="after-london"></div>

<script src="script.js"></script>
</body>
</html>
60 changes: 60 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Predefined offsets relative to GMT
const countries = [
{ name: "🇺🇸 USA", city: "Los Angeles", tz: "America/Los_Angeles", offsetGMT: -8 },
{ name: "🇧🇷 Brazil", city: "São Paulo", tz: "America/Sao_Paulo", offsetGMT: -3 },
{ name: "🇺🇸 USA", city: "New York", tz: "America/New_York", offsetGMT: -5 },
{ name: "🇨🇦 Canada", city: "Toronto", tz: "America/Toronto", offsetGMT: -5 },
{ name: "🇩🇪 Germany", city: "Berlin", tz: "Europe/Berlin", offsetGMT: 1 },
{ name: "🇫🇷 France", city: "Paris", tz: "Europe/Paris", offsetGMT: 1 },
{ name: "🇮🇹 Italy", city: "Rome", tz: "Europe/Rome", offsetGMT: 1 },
{ name: "🇷🇺 Russia", city: "Moscow", tz: "Europe/Moscow", offsetGMT: 3 },
{ name: "🇦🇪 UAE", city: "Dubai", tz: "Asia/Dubai", offsetGMT: 4 },
{ name: "🇮🇳 India", city: "Delhi", tz: "Asia/Kolkata", offsetGMT: 5.5 },
{ name: "🇨🇳 China", city: "Beijing", tz: "Asia/Shanghai", offsetGMT: 8 },
{ name: "🇯🇵 Japan", city: "Tokyo", tz: "Asia/Tokyo", offsetGMT: 9 },
{ name: "🇦🇺 Australia", city: "Sydney", tz: "Australia/Sydney", offsetGMT: 11 },
{ name: "🇦🇶 Antarctica", city: "Rothera Station", tz: "Antarctica/Rothera", offsetGMT: -3 },
{ name: "🇿🇦 South Africa", city: "Cape Town", tz: "Africa/Johannesburg", offsetGMT: 2 },
{ name: "🇬🇷 Greece", city: "Athens", tz: "Europe/Athens", offsetGMT: 2 }
];


function updateTime() {
const now = new Date();

// Get London time
const londonTime = now.toLocaleTimeString("en-GB", { timeZone: "Europe/London", hour: "2-digit", minute: "2-digit", second: "2-digit" });
document.getElementById("london-time").innerText = londonTime;

// Get London's GMT offset dynamically in case of daylight savings
const londonOffset = new Date().getTimezoneOffset() / -60; // Offset in hours

// Sort countries from earliest to latest based on actual GMT offset
const sortedCountries = countries
.map(country => {
const time = now.toLocaleTimeString("en-GB", { timeZone: country.tz, hour: "2-digit", minute: "2-digit" });
const offset = country.offsetGMT - londonOffset;
return { ...country, time, offset };
})
.sort((a, b) => a.offset - b.offset); // Sort by actual offset

const beforeLondon = [];
const afterLondon = [];

sortedCountries.forEach(country => {
const offsetText = country.offset > 0 ? `+${country.offset}` : country.offset;
const countryHTML = `<div class="country-time">${country.name} ${offsetText} (${country.city}): ${country.time}</div>`;

if (country.offset < 0) {
beforeLondon.push(countryHTML);
} else {
afterLondon.push(countryHTML);
}
});

document.getElementById("before-london").innerHTML = beforeLondon.join("");
document.getElementById("after-london").innerHTML = afterLondon.join("");
}

updateTime();
setInterval(updateTime, 1000);
29 changes: 29 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
body {
font-family: Arial, sans-serif;
text-align: center;
background-color: #121212;
color: #fff;
margin: 20px;
}

h1 {
font-size: 2.5em;
margin: 20px 0;
color: #f1c40f;
}

.time-container {
display: flex;
flex-direction: column;
align-items: center;
gap: 10px;
}

.country-time {
font-size: 1.5em;
padding: 10px;
border-radius: 8px;
background: #222;
width: 350px;
text-align: center;
}

0 comments on commit 9fed8f5

Please sign in to comment.