Fourth-week blog post for GSoC 2021

LeoCumpli21
Published: 06/28/2021

Once again, I'm writing this as part of my Google Summer of Code (GSoC) for Python Software Foundation (PSF). The third week has ended, and along with it I finished my first milestone... Or at least that's what I thought. Last post I told you I was ready to tackle my second milestone, however, I forgot some lectures need to be checked as well. So, I did start my second milestone, but I had to pause it. Let the questions begin.

What am I working on

I worked on 2 different things. First, regarding my second milestone, I worked on two tickets. Before ellaborating on them, let me introduce you to what this milestone is about: It consists of refactoring Facebook's API lesson. The expected outcome is to have created new exercises with other APIs, public ones so that no special requirements are asked for.

  • The 1st ticket was a piece of cake. I just had to debug a block of code that involved using Reddit API.
  • The 2nd one wasn't as easy. Here's why: I had to create 3 exercises from scratch involving TestDive API. Here's one of them:
        
            import requests
            import json
            
            api_url = "https://tastedive.com/api/similar"
            proxy = "https://cors.bridged.cc/"
            parametros = {"q": "Coco", "limit": 5, "info": 1}
            
            solicitud = requests.get(proxy + api_url, params=parametros)
            datos = json.loads(solicitud.text)
            
            resultados = len(datos["Similar"]["Results"])
            print(f"resultados: {resultados}")
            
            peliculas_similares = []
            for peli in datos["Similar"]["Results"]:
                peliculas_similares.append(peli["Name"])
            
            print(f"Pelis: {peliculas_similares} len: {len(peliculas_similares)}")
            
            pixar = 0
            for peli in datos["Similar"]["Results"]:
                for pal in peli["wTeaser"].split():
                    if pal == "Pixar":
                        pixar += 1
            
            print(f"Pixar: {pixar}")
        
    
I also added unittest for automatic grading to it. Apart from that, I made a web test with playwright for this same exercise. I learned about page.keyboard from Playwright.
Keyboard provides an api for managing a virtual keyboard. The high level api is keyboard.type(text, **kwargs), which takes raw characters and generates proper keydown, keypress/input, and keyup events on your page.
Before this, to press a key or type something I used:
        
            page.press("text=def remplazar_primer_caracter(s):", "Tab")
            page.type(
                "text=def remplazar_primer_caracter(s):",
                "return s[0] + s[1:].replace(s[0], '*')",
            )
        
    
Notice the first argument, which is the "selector", an element to tell playwright where to apply an event. Now, I just have to place the cursor where I want to start typing and, with the keyboard class, tell it what to do. For example:
        
            page.click("#ac_l45_5 >> text=parametros = {}")
            # Clear all code
            page.keyboard.press("Control+A")
            page.keyboard.press("Backspace")
            # Type something
            page.keyboard.type("Hello world")
        
    
The second thing I worked on was fixing 2 lectures.

What have I struggled with this week?

Once again, git gave me trouble. I don't know why, but git push and all its variants decided to not work anymore. Regarding python, my major problem was when I wanted to clear all code with playwright using the ctrl+A & backspace keys.

What solutions have I found?

For the git problem, I had to install GitHub Desktop to push my local commits to my remote repo. For playwright doubts, I checked its documentation and found the keyboard class.
This is all for now :)

DJDT

Versions

Time

Settings from gsoc.settings

Headers

Request

SQL queries from 1 connection

Static files (2312 found, 3 used)

Templates (11 rendered)

Cache calls from 1 backend

Signals

Log messages