Skip to content

Commit

Permalink
added necessary comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Aayush Badoni authored and Aayush Badoni committed Mar 16, 2024
1 parent 77eef35 commit 1952d29
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
23 changes: 11 additions & 12 deletions _sources/lectures/TWP45/TWP45_3_en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ TasteDive is a tool that:
In the following exercise, we will use the TasteDive API to search for works or artists similar to another of our choice.
The documentation for the `TasteDive API <https://tastedive.com/read/api>`_.

.. activecode:: ac_l45_3a_en
.. activecode:: ac_l45_3a_enfds
:nocodelens:
:language: python

Expand All @@ -23,14 +23,13 @@ The documentation for the `TasteDive API <https://tastedive.com/read/api>`_.
import requests
import json

api_url = "https://tastedive.com/api/similar"
proxy = "https://cors.bridged.cc/"
api_url = "https://uselessfacts.jsph.pl/api/v2/facts/random"

# The parameters that will be passed to the url are written inside a dictionary
parameters = {"q": "ariana grande"}
parameters = {"language": "en"}

# We request the data from the api
response = requests.get(proxy + api_url, params=parameters)
response = requests.get(api_url, params=parameters)

# Now we print the url
print(response.url)
Expand All @@ -46,7 +45,7 @@ In the previous example, you could see that the API returns text, which if passe
transforms into a Python dictionary. However, it is not entirely readable. This can be solved with
``json.dumps``.

.. activecode:: ac_l45_3b_en
.. activecode:: ac_l45_3hb_efdf
:language: python3
:python3_interpreter: brython

Expand All @@ -59,19 +58,19 @@ transforms into a Python dictionary. However, it is not entirely readable. This
import urllib.parse
import json

api_url = "https://tastedive.com/api/similar?"
proxy = "https://cors.bridged.cc/"
api_url = "https://uselessfacts.jsph.pl/api/v2/facts/random?"

# The following line is for the url parameters
parameters = urllib.parse.urlencode({"q": "coldplay"})
parameters = urllib.parse.urlencode({"language": "en"})

request = urllib.request.urlopen(proxy + api_url + parameters)
request = urllib.request.urlopen(api_url + parameters)
data = json.loads(request.read())

# We print the data in a user-readable format
print(json.dumps(data, indent=4))

# We can see that the api returned 20 results related to the request
print(len(data["Similar"]["Results"]))
# We can see that api returned 6 related fields for the random fact
print(len(data))


|
Expand Down
5 changes: 4 additions & 1 deletion _sources/quiz/BasicQuiz.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ Ejercicios básicos
Dada una lista de tuplas no vacías, devuelve una lista ordenada en orden creciente por el último elemento en cada tupla. |br|

~~~~
# Extraer el último elemento de una tupla, utilizado para ordenación personalizada a continuación
def last(a):

def sort_last(tuples):

====
Expand Down Expand Up @@ -135,7 +138,7 @@ Ejercicios básicos
.. activecode:: basic_q6es
:nocodelens:

Dada una cadena s, devuelve una cadena donde todas las ocurrencias de su primer carácter se han cambiado a '*', excepto no cambie el primer carácter en sí. Por ejemplo, 'babble' produce 'ba**le'. Suponga que la cadena tiene una longitud de 1 o más. |br|
Dada una cadenas, devuelve una cadena donde todas las ocurrencias de su primer carácter se han cambiado a '*', excepto no cambie el primer carácter en sí. Por ejemplo, 'babble' produce 'ba**le'. Suponga que la cadena tiene una longitud de 1 o más. |br|

~~~~
def fix_start(s):
Expand Down
1 change: 1 addition & 0 deletions _sources/quiz/BasicQuiz_en.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Basic Exercises
Given a list of non-empty tuples, return a list sorted in increasing order by the last element in each tuple. |br|

~~~~
# Extract the last element from a tuple -- used for custom sorting below.
def last(a):

def sort_last(tuples):
Expand Down
1 change: 0 additions & 1 deletion build_info

This file was deleted.

0 comments on commit 1952d29

Please sign in to comment.