Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#38 - Python #6536

Merged
merged 5 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions Roadmap/38 - MOUREDEV PRO/python/CesarCarmona30.py
Original file line number Diff line number Diff line change
@@ -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)
74 changes: 74 additions & 0 deletions Roadmap/39 - BATMAN DAY/python/CesarCarmona30.py
Original file line number Diff line number Diff line change
@@ -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]}")
97 changes: 97 additions & 0 deletions Roadmap/40 - FORTNITE RUBIUS CUP/python/CesarCarmona30.py
Original file line number Diff line number Diff line change
@@ -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)