LeoCumpli21's Blog

Seventh-week check in for GSoC 2021

LeoCumpli21
Published: 07/20/2021

Hi! This weeks check in may be short but interesting. Firstly, I was given great news: I passed the first evaluation 😃. Now, the second period begins, and I plan to keep my good workflow ongoing.

What did I do this week?

I focused on my third milestone. I made two challenges for the course. The first one is a called Hangman challenge, and it is about creating a hangman game. The hard thing was coding its web test. I'll explain this later. The second challenge is called Pergamino challenge, and it is about deciphering a parchment with Python code. This was very straightforward, even its web test.

Did I get stuck anywhere?

Yes. The playwright test for the hangman challenge was tricky. Interacting with the exercises of this challenge meant dealing with several dialog prompts. I already knew how to accept one dialog prompt:
page.on("dialog", lambda dialog: dialog.accept("sth"))
But I had trouble when more than one needed to be handled in the same test. By looking at playwrights documentation I found a solution. First, expect for the dialog event to appear on screen. Then, accept that single dialog once. This, translated to code, is:

            
                with page.expect_event("dialog") as prompt1:
                    page.once("dialog", lambda dialog: dialog.accept("sth"))
                with page.expect_event("dialog") as prompt2:
                    page.once("dialog", lambda dialog: dialog.accept("sth"))
            
        

What is coming up next?

I made two PRs this week. Both are regarding the new challenges. They are still awaiting review. So this week I will tackle the review suggestions, and will review my peers PRs.

View Blog Post

Sixth-week blog post for GSoC 2021

LeoCumpli21
Published: 07/13/2021

Welcome to my sixth blog post about my experience in Google Summer of Code (GSoC) 2021.

What am I working on

Last week I finished working with my second milestone. This is what I did. There is a lecture in the project called Hackeando con Pyhton that is supposed to teach how to access an API and retrieve information using pyhton. Before last week, this lecture had only one exercise because others were eliminated due to the APIs they used (They have changed a lot and they are no longer public). Now, this lecture has six new exercises.
You might know these two python modules to do HTTP requests: urllib and requests. For the new exercises I used both, mainly because I encountered a problem with Runestone and I had to change the python interpreter to solve this.
This week I will be working on my third milestone.

What have I struggled with this week?

I had trouble with the dumps method from the json module. For an exercise I needed to display on screen the json data retrieved from an API. In order to print it with indentation I passed the indent argument. Like this:
print(json.dumps(datos, indent=4))
However, it wasn't working.

What solutions have I found?

So, I was using requests module before this. I had to change the python interpreter to brython for some exercises, because in Brython json.dumps with the indent arg works just fine, but Brython doesn't support the requests module yet. This is why I changed to urllib. In the Brython's console, the output finally dislplayed nicely with indentation.

View Blog Post

Fifth-week check-in for GSoC 2021

LeoCumpli21
Published: 07/04/2021

It's been a month since the coding period started. The upcoming week in particular is important because it's the last week before the first evaluation period, meaning I have to deliver everything I've worked on for the past month.

What did I do this week?

I finally finished my first milestone. In total, for this milestone I opened 21 issues, and closed 16 so far. The missing 5 have linked pull requests (PRs) that are awaiting review.
For 2 lectures I had to use Brython for their exercises.

Brython is designed to replace Javascript as the scripting language for the Web. As such, it is a Python 3 implementation (you can take it for a test drive through a web console), adapted to the HTML5 environment, that is to say with an interface to the DOM objects and events.
I use Brython beacause the current python interpreter of Runestone is skulpt, and it doesn't support some python libraries that Brython does. So this past week I had to recall how Brython works. I had to read its documentation again, where I found the browser.timer module, which I found helpful.

Did I get stuck anywhere?

Not really. I did take time to do the Brython stuff, but I didn't feel stuck.

What is coming up next?

This fifth week I will be aware of my existing PRs in case the mentors suggest changes. Meanwhile, I'll continue with my second milestone.

View Blog Post

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 :)

View Blog Post

Third-week check-in for GSoC 2021

LeoCumpli21
Published: 06/23/2021

Hi! Today June 21 I begin my third week for GSoC 2021. I am loving this experience so far. Now, I'm going to answer 3 questions regarding my work last week, what I struggled with, and what I will focus on this week.

What did I do this week?

In my last post, I mentioned I was working on fixing the existing quizzes of the project. I kept doing that, and I finished. I started fixing some lectures. By fixing I mean:

  • Formatting all python code with black.
  • Changing static snippets to activecode.
  • Creating some exercises with automating grading using unit test
  • Creating some web tests (where needed), with playwright
I've already finished fixing 4 lectures. This week I made 8 PRs, some of which were proposing simple changes.

Did I get stuck anywhere?

Yes I did. As I've mentioned over the past posts, we use pytest-playwright as our web tester. I've been coding easy tests for the quizzes, and I thought that was enough. Until I got to program a test for a lecture that involved writing into a prompt box. I got stuck in there beacause I didn't know playwright had a special way to deal with dialog prompts. So I had to search in their documentation for an answer, and I got one.
Here's the piece of code I was looking for:

            
                def test_TWP18_ac_5(page):
                    # Deal with prompt box
                    def handle_dialog(dialog):
                        dialog.accept("una palabra")

                    # Code to go to TWP18 page, do the exercise and run it.

                    # Fill prompt box
                    page.on("dialog", handle_dialog)
            
        

What is coming up next?

Last Saturday (June 19), the team got together in a videocall to discuss what we've done so far and what is coming up. So, now that I've finished with the quizzes and the easy lectures, some of which are awaiting review, I will begin my second milestone. It consists on refactoring a lecture that involves accesing some APIs. My idea is to fix one existing exercise that uses Reddit API, and to create two exercises using two different public and easy to manipulate API's. Meanwhile, I'll continue searching for ways to make the SQL lecture work.

View Blog Post