From fb186c4b35e4c205f4197bec7c4ebd8335fca485 Mon Sep 17 00:00:00 2001 From: Cesar Carmona Date: Mon, 23 Sep 2024 23:36:24 -0600 Subject: [PATCH 1/3] #38 - Python --- .../python/CesarCarmona30.py | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 Roadmap/38 - MOUREDEV PRO/python/CesarCarmona30.py diff --git a/Roadmap/38 - MOUREDEV PRO/python/CesarCarmona30.py b/Roadmap/38 - MOUREDEV PRO/python/CesarCarmona30.py new file mode 100644 index 0000000000..647f807af6 --- /dev/null +++ b/Roadmap/38 - MOUREDEV PRO/python/CesarCarmona30.py @@ -0,0 +1,36 @@ +import os +import csv +import random + +def read_csv_data(): + file_dir = os.path.dirname(os.path.abspath(__file__)) + csv_file = f"{file_dir}/subs.csv" + + data = [] + + with open(csv_file, mode="r") as file: + reader = csv.DictReader(file) + for row in reader: + if row["status"] == "activo": + data.append(row) + + return data + + +def select_winners(data): + if len(data) < 3: + raise ValueError("El número de elementos debe ser de mínimo 3.") + + return random.sample(data, 3) + +def display_winners(winners): + prizes = ["Suscripcion", "Descuento", "Libro"] + for winner, prize in zip(winners, prizes): + print(f"{prize}: {winner["email"]} (ID: {winner["id"]})") + +try: + data = read_csv_data() + winners = select_winners(data) + display_winners(winners) +except Exception as e: + print(e) \ No newline at end of file From caebb77e193b3acf7e5092a5b21846cbef1995f6 Mon Sep 17 00:00:00 2001 From: CesarCarmona Date: Thu, 10 Oct 2024 20:08:29 -0600 Subject: [PATCH 2/3] #39 - Python --- .../39 - BATMAN DAY/python/CesarCarmona30.py | 74 +++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 Roadmap/39 - BATMAN DAY/python/CesarCarmona30.py diff --git a/Roadmap/39 - BATMAN DAY/python/CesarCarmona30.py b/Roadmap/39 - BATMAN DAY/python/CesarCarmona30.py new file mode 100644 index 0000000000..24d8c501b6 --- /dev/null +++ b/Roadmap/39 - BATMAN DAY/python/CesarCarmona30.py @@ -0,0 +1,74 @@ +from datetime import datetime, timedelta + +year_of_creation = 1939 +anniversary_year = year_of_creation + 85 + +batman_day_anniversary_dates = [] + +while anniversary_year <= year_of_creation + 100: + + september = datetime(anniversary_year, 9, 1) + + first_saturday = 5 - september.weekday() if september.weekday() <= 5 else \ + 12 - september.weekday() + + third_saturday = september + timedelta(days=first_saturday + 14) + + batman_day_anniversary_dates.append( + ( + anniversary_year, + anniversary_year - year_of_creation, + third_saturday.strftime("%d-%m-%Y") + ) + ) + + anniversary_year += 1 + +for year, anniversary, batman_day in batman_day_anniversary_dates: + print(f"Batman day {year} ({anniversary} aniversario): {batman_day}") + + +def sum_subgrid_alerts(sensors, center_x, center_y): + total = 0 + + for x in range(center_x - 1, center_x + 2): + for y in range(center_y - 1, center_y + 2): + for sensor in sensors: + if sensor[0] == x and sensor[1] == y: + total += sensor[2] + + return total + +def batcave_security_system(sensors): + + max_alert_level = 0 + max_alert_coordinate = (0, 0) + + for x in range(1, 19): + for y in range(1, 19): + alert_level = sum_subgrid_alerts(sensors, x, y) + if alert_level > max_alert_level: + max_alert_level = alert_level + max_alert_coordinate = (x, y) + + distance = abs(max_alert_coordinate[0]) + abs(max_alert_coordinate[1]) + activate_protocol = max_alert_level > 20 + + return max_alert_coordinate, max_alert_level, distance, activate_protocol + +sensors = [ + (2, 3, 7), + (4, 3, 8), + (2, 2, 7), + (10, 12, 8), + (11, 11, 8), + (10, 11, 8), + (15, 18, 4) +] + +result = batcave_security_system(sensors) + +print(f"Centro de cuadrícula mas amenzada: {result[0]}") +print(f"Máximo nivel de alerta: {result[1]}") +print(f"Distancia a la Baticueva: {result[2]}") +print(f"Activar protocolo de seguridad: {result[3]}") \ No newline at end of file From 92f06ff388f9b95ae9bf1d10ca54eeda535a9f6e Mon Sep 17 00:00:00 2001 From: CesarCarmona Date: Thu, 10 Oct 2024 20:31:25 -0600 Subject: [PATCH 3/3] #40 - Python --- .../python/CesarCarmona30.py | 97 +++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 Roadmap/40 - FORTNITE RUBIUS CUP/python/CesarCarmona30.py diff --git a/Roadmap/40 - FORTNITE RUBIUS CUP/python/CesarCarmona30.py b/Roadmap/40 - FORTNITE RUBIUS CUP/python/CesarCarmona30.py new file mode 100644 index 0000000000..923b7312af --- /dev/null +++ b/Roadmap/40 - FORTNITE RUBIUS CUP/python/CesarCarmona30.py @@ -0,0 +1,97 @@ +import requests + +def get_access_token(client_id, client_secret): + url = "https://id.twitch.tv/oauth2/token" + params = { + "client_id": client_id, + "client_secret": client_secret, + "grant_type": "client_credentials" + } + response = requests.post(url, params=params) + response.raise_for_status() + return response.json().get("access_token") + +def get_user_info(token, client_id, login): + url = "https://api.twitch.tv/helix/users" + headers ={ + "Authorization": f"Bearer {token}", + "Client-Id": client_id + } + params = {"login": login} + response = requests.get(url, headers=headers, params=params) + response.raise_for_status() + data = response.json().get("data", None) + + if not data: + return None + + return data[0] + +def get_total_followers(token, client_id, id): + url = "https://api.twitch.tv/helix/channels/followers" + headers = { + "Authorization": f"Bearer {token}", + "Client-Id": client_id + } + params = {"broadcaster_id": id} + response = requests.get(url, headers=headers, params=params) + response.raise_for_status() + return response.json().get("total", 0) + +CLIENT_ID = "client_id" +CLIENT_SECRET = "client_secret" + +users = [ + "littleragergirl", "ache", "adricontreras4", "agustin51", "alexby11", "ampeterby7", "tvander", + "arigameplays", "arigeli_", "auronplay", "axozer", "beniju03", "bycalitos", + "byviruzz", "carreraaa", "celopan", "srcheeto", "crystalmolly", "darioemehache", + "dheylo", "djmariio", "doble", "elvisayomastercard", "elyas360", "folagorlives", "thegrefg", + "guanyar", "hika", "hiperop", "ibai", "ibelky_", "illojuan", "imantado", + "irinaissaia", "jesskiu", "jopa", "jordiwild", "kenaivsouza", "mrkeroro10", + "thekiddkeo95", "kikorivera", "knekro", "kokoop", "kronnozomberoficial", "leviathan", + "litkillah", "lolalolita", "lolitofdez", "luh", "luzu", "mangel", "mayichi", + "melo", "missasinfonia", "mixwell", "jaggerprincesa", "nategentile7", "nexxuz", + "lakshartnia", "nilojeda", "nissaxter", "olliegamerz", "orslok", "outconsumer", "papigavitv", + "paracetamor", "patica1999", "paulagonu", "pausenpaii", "perxitaa", "nosoyplex", + "polispol1", "quackity", "recuerd0p", "reventxz", "rivers_gg", "robertpg", "roier", + "ceuvebrokenheart", "rubius", "shadoune666", "silithur", "spok_sponha", "elspreen", "spursito", + "bystaxx", "suzyroxx", "vicens", "vitu", "werlyb", "xavi", "xcry", "elxokas", + "thezarcort", "zeling", "zormanworld", "mouredev" +] +users_data = [] +not_found_users = [] + +token = get_access_token(CLIENT_ID, CLIENT_SECRET) + +for username in users: + + user = get_user_info(token, CLIENT_ID, username) + + if user is None: + not_found_users.append(username) + else: + followers = get_total_followers(token, CLIENT_ID, user["id"]) + users_data.append({ + "username": username, + "created_at": user["created_at"], + "followers": followers + }) + +sort_by_followers = sorted( + users_data, key=lambda x: x["followers"], reverse=True) + +sort_by_date = sorted( + users_data, key=lambda x: x["created_at"]) + +print("\nRanking por número de seguidores:") +for id, user, in enumerate(sort_by_followers): + print(f"{id + 1} - {user["username"]}: {user["followers"]} seguidores") + +print("\nRanking por antigüedad:") +for id, user, in enumerate(sort_by_date): + print(f"{id + 1} - {user["username"]}: Creado el {user["created_at"]}") + +if not_found_users: + print("\nUsuarios no encontrados:") + for user in not_found_users: + print(user) \ No newline at end of file