Skip to content
Open
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
1 change: 1 addition & 0 deletions your-code/Github_token.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
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
39 changes: 39 additions & 0 deletions your-code/challenge-1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import requests
import json

user_name = "TGLSpain1"

with open("Github_token.txt", "r") as f:
password = f.read()

repo_owner_name = "ta-data-mexpt"
repo_name = "project-build-your-own-game"

base_url = "https://api.github.com"
path = f"/repos/{repo_owner_name}/{repo_name}/forks"

languages = set()
i = 1
exist_more_results = True

languages = set()

while exist_more_results:
final_url = base_url + path + f"?page={i}"
print(final_url)
all_forks = requests.get(final_url, auth = (user_name, password))
forks_response = json.loads(all_forks.content)
print(forks_response)
more_languages = {element["language"] for element in forks_response}
languages = languages | more_languages
next_url_element = all_forks.headers["Link"]
check_next_url = next_url_element.split(" ")[1]
if check_next_url == 'rel="next"':
i += 1
else:
exist_more_results = False

print(languages)
print("finished")


24 changes: 24 additions & 0 deletions your-code/challenge-2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import requests
import json

user_name = "TGLSpain1"

with open("Github_token.txt", "r") as f:
password = f.read()

repo_owner_name = "tglspain1"
repo_name = "project-build-your-own-game"

base_url = "https://api.github.com"
path = f"/repos/{repo_owner_name}/{repo_name}/commits"
rate_path = "/rate_limit"

final_url = base_url + path
all_commits = requests.get(final_url, auth = (user_name, password))
commits_response = json.loads(all_commits.content)
total_commits = len(commits_response)
print(f"Total number of commits for this repository is {total_commits}")
print("finished")



77 changes: 77 additions & 0 deletions your-code/challenge-3.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import requests
import json
import time
import base64

# FALTA DESCODIFICAR BASE 64 CADA CONTENT, ORDENAR ARCHIVOS Y JUNTAR EN LISTA O EN STRING

user_name = "TGLSpain1"

with open("Github_token.txt", "r") as f:
password = f.read()

repo_owner_name = "ironhack-datalabs"
repo_name = "scavenger"

base_url = "https://api.github.com"
path = f"/repos/{repo_owner_name}/{repo_name}/contents"
rate_path = "/rate_limit"
final_url = base_url + path

all_files = requests.get(final_url, auth = (user_name, password))
all_files_response = json.loads(all_files.content)
if 400 <= all_files.status_code < 500:
print(all_files.content)

file_list = [(file["name"], file["type"]) for file in all_files_response]
folder_list = [file_element for file_element in file_list if file_element[1] == "dir"]
folder_paths = [folder[0] for folder in folder_list]

print("Getting all files")
total_files_list = []
for folder_path in folder_paths:
folder_contents = requests.get(final_url + f"/{folder_path}", auth = (user_name, password))
folder_contents_response = json.loads(folder_contents.content)
total_files_list.append(folder_contents_response)
time.sleep(0.5)

print(len(total_files_list))

total_files_list_flat = [folder_files for folder in total_files_list for folder_files in folder]
print(total_files_list_flat)

final_total_files_list = [flat_file for flat_file in total_files_list_flat if "scavengerhunt" in flat_file["name"]]

with open ("folder_contents.txt", "w") as f:
for final_total_file in final_total_files_list:
print(f"{final_total_file['path']}\n")
f.write(f"{final_total_file['path']}\n")


file_names = []
with open ("folder_contents.txt", "r") as f:
for row in f:
name = row[:-1]
file_names.append(name)

file_tuples = [(file_name, int(file_name.split(".")[1])) for file_name in file_names]

sorted_file_tuples = sorted(file_tuples, key = lambda x: x[1])

texts = []

for file_tuple in sorted_file_tuples:
file_contents = requests.get(final_url + f"/{file_tuple[0]}", auth = (user_name, password))
file_response = json.loads(file_contents.content)
content_base64 = file_response["content"]
content_ascii = content_base64.encode('ascii')
content_decoded = base64.b64decode(content_ascii)
final_content = content_decoded.decode('ascii')
texts.append(final_content)

final_text = " ".join(texts)
print(final_text)




24 changes: 24 additions & 0 deletions your-code/folder_contents.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
15024/.0006.scavengerhunt
15534/.0008.scavengerhunt
15534/.0012.scavengerhunt
17020/.0007.scavengerhunt
30351/.0021.scavengerhunt
40303/.0022.scavengerhunt
44639/.0005.scavengerhunt
45525/.0018.scavengerhunt
47222/.0016.scavengerhunt
47222/.0024.scavengerhunt
47830/.0010.scavengerhunt
49418/.0014.scavengerhunt
50896/.0011.scavengerhunt
55417/.0023.scavengerhunt
55685/.0020.scavengerhunt
60224/.0003.scavengerhunt
68848/.0004.scavengerhunt
70751/.0019.scavengerhunt
70985/.0017.scavengerhunt
88596/.0002.scavengerhunt
89338/.0013.scavengerhunt
91701/.0015.scavengerhunt
97881/.0009.scavengerhunt
98750/.0001.scavengerhunt