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: 0 additions & 1 deletion challenge-1.py

This file was deleted.

86 changes: 86 additions & 0 deletions your-code/Challenge-1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "e1c00878",
"metadata": {},
"source": [
"### Challenge 1: Fork Languages\n",
"\n",
"You will find out how many programming languages are used among all the forks created from the main lab repo of your bootcamp. Assuming the main lab repo is `ironhack-datalabs/madrid-oct-2018`, you will:\n",
"\n",
"1. Obtain the full list of forks created from the main lab repo via Github API.\n",
"\n",
"1. Loop the JSON response to find out the `language` attribute of each fork. Use an array to store the `language` attributes of each fork.\n",
" * *Hint: Each language should appear only once in your array.*\n",
"\n",
"1. Print the language array. It should be something like:\n",
"\n",
"\t```[\"Python\", \"Jupyter Notebook\", \"HTML\"]```\n",
"\n",
"Again, the documentation of Github API is [here](https://developer.github.com/v3/)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "5ea4fe37",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import regex as re\n",
"import numpy as np\n",
"\n",
"forks = requests.get(\"https://api.github.com/repos/ta-data-mexpt/lab-api-scavenger/forks\")"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "52f98e0b",
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"text/plain": [
"['Jupyter Notebook', None]"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"lista=[]\n",
"for i in forks.json():\n",
" lista.append(i['language'])\n",
"list(set(lista))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
86 changes: 86 additions & 0 deletions your-code/Challenge-2.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "dcec229a",
"metadata": {},
"source": [
"### Challenge 2: Count Commits\n",
"\n",
"Count how many commits were made in the past week.\n",
"\n",
"1. Obtain all the commits made in the past week via API, which is a JSON array that contains multiple commit objects.\n",
"\n",
"1. Count how many commit objects are contained in the array.\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "9e72dc75",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import regex as re\n",
"import numpy as np\n",
"from datetime import datetime, timedelta\n"
]
},
{
"cell_type": "code",
"execution_count": 72,
"id": "889a517d",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0"
]
},
"execution_count": 72,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"\n",
"# El repo de ta-data-mexpt/data-labs tiene sólo un commit así que utilicé el lab ta-data-mexpt/data-labs\n",
"# pero igual los commits son más antiguos a 7 días así que no se tomaron commits\n",
"\n",
"commits = requests.get(\"https://api.github.com/repos/ta-data-mexpt/data-labs/commits\")\n",
"lista_commits=[]\n",
"\n",
"for comit in commits.json():\n",
" fecha_commit=comit['commit']['committer']['date'][0:10]\n",
" fecha_commit=datetime.strptime(fecha_commit[0:10], \"%Y-%m-%d\").date()\n",
" if (date.today()-fecha_commit).days<=7 :\n",
" lista_commits.append(comit)\n",
"\n",
"len(lista_commits)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
95 changes: 95 additions & 0 deletions your-code/Challenge-3.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "935d134c",
"metadata": {},
"source": [
"### Challenge 3: Hidden Cold Joke\n",
"\n",
"Using Python, call Github API to find out the cold joke contained in the 24 secret files in the following repo:\n",
"\n",
"https://github.com/ironhack-datalabs/scavenger\n",
"\n",
"The filenames of the secret files contain `.scavengerhunt` and they are scattered in different directories of this repo. The secret files are named from `.0001.scavengerhunt` to `.0024.scavengerhunt`. They are scattered randomly throughout this repo. You need to **search for these files by calling the Github API**, not searching the local files on your computer.\n",
"\n",
"Notes:\n",
"\n",
"* Github API documentation can be found [here](https://developer.github.com/v3/).\n",
"\n",
"* You will need to study the Github API documentation to decide which API endpoint to call and what parameters to use in order to obtain the information you need. Unless you are already super familiar with Github API or super lucky, you probably will do some trials and errors. Therefore, be prepared to go back and forth in studying the API documentation, testing, and revising until you obtain what you need.\n",
"\n",
"* After receiving the JSON data object, you need to inspect its structure and decide how to parse the data.\n",
"\n",
"* When you test your requests with Github API, sometimes you may be blocked by Github with an error message that reads:\n",
"\n",
"\t> You have triggered an abuse detection mechanism and have been temporarily blocked from content creation. Please retry your request again later.\n",
"\n",
"\tDon't worry. Check the parameters in your request and wait for a minute or two before you make additional requests.\n",
"\n",
"**After you find out the secrete files:**\n",
"\n",
"1. Sort the filenames ascendingly.\n",
"\n",
"1. Read the content of each secret files into an array of strings.\n",
"\n",
"1. Concatenate the strings in the array separating each two with a whitespace.\n",
"\n",
"1. Print out the joke.\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "28524da3",
"metadata": {},
"outputs": [],
"source": [
"import requests\n",
"import regex as re\n",
"\n",
"repo = requests.get(\"https://api.github.com/repos/ironhack-datalabs/scavenger/contents\")\n",
"\n",
"len(repo.json())\n",
"nombre_carpeta=[carpeta['name'] for carpeta in repo.json()]\n",
"\n",
"archivos=[requests.get(f\"https://api.github.com/repos/ironhack-datalabs/scavenger/contents/{carpeta}\") for carpeta in nombre_carpeta]\n",
"\n",
"archivos.pop(0)\n",
"\n",
"dic={}\n",
"for i in archivos:\n",
" nombre=i.json()[0]['name']\n",
" url=i.json()[0]['download_url']\n",
" cont=requests.get(url)\n",
" text=cont.text\n",
" if nombre.endswith(\"hunt\")==True:\n",
" dic[nombre]=text\n",
"\n",
"chiste=[elemento[1].replace(\"\\n\", \"\") for elemento in sorted(dic.items())]\n",
"print(\" \".join(chiste))"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 5
}