From b97290c27072540855f857bf631491e15f23b7f9 Mon Sep 17 00:00:00 2001 From: TGLSpain Date: Sun, 14 Aug 2022 20:36:58 -0300 Subject: [PATCH 1/2] First commit, challenge 1 --- your-code/Github_token.txt | 1 + your-code/challenge-1.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 your-code/Github_token.txt create mode 100644 your-code/challenge-1.py diff --git a/your-code/Github_token.txt b/your-code/Github_token.txt new file mode 100644 index 0000000..2fbf38c --- /dev/null +++ b/your-code/Github_token.txt @@ -0,0 +1 @@ +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 \ No newline at end of file diff --git a/your-code/challenge-1.py b/your-code/challenge-1.py new file mode 100644 index 0000000..f85e29c --- /dev/null +++ b/your-code/challenge-1.py @@ -0,0 +1,38 @@ +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) + 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") + + From 63d6ee4560d77d0b54e189db0924f5bfe292bc6f Mon Sep 17 00:00:00 2001 From: TGLSpain Date: Tue, 16 Aug 2022 20:09:52 -0300 Subject: [PATCH 2/2] three challenges completed --- your-code/Github_token.txt | 2 +- your-code/challenge-1.py | 1 + your-code/challenge-2.py | 24 +++++++++++ your-code/challenge-3.py | 77 +++++++++++++++++++++++++++++++++++ your-code/folder_contents.txt | 24 +++++++++++ 5 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 your-code/challenge-2.py create mode 100644 your-code/challenge-3.py create mode 100644 your-code/folder_contents.txt diff --git a/your-code/Github_token.txt b/your-code/Github_token.txt index 2fbf38c..003b82f 100644 --- a/your-code/Github_token.txt +++ b/your-code/Github_token.txt @@ -1 +1 @@ -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 \ No newline at end of file +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 \ No newline at end of file diff --git a/your-code/challenge-1.py b/your-code/challenge-1.py index f85e29c..18079f9 100644 --- a/your-code/challenge-1.py +++ b/your-code/challenge-1.py @@ -23,6 +23,7 @@ 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"] diff --git a/your-code/challenge-2.py b/your-code/challenge-2.py new file mode 100644 index 0000000..af2927a --- /dev/null +++ b/your-code/challenge-2.py @@ -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") + + + diff --git a/your-code/challenge-3.py b/your-code/challenge-3.py new file mode 100644 index 0000000..2241b04 --- /dev/null +++ b/your-code/challenge-3.py @@ -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) + + + + diff --git a/your-code/folder_contents.txt b/your-code/folder_contents.txt new file mode 100644 index 0000000..4158ed3 --- /dev/null +++ b/your-code/folder_contents.txt @@ -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