Hello fellow programmers/ followers.
I sincerely hope this past week has been treating you great, because I sure have gotten stomped to the ground due to various things in my academic career -cough- Game Dev... #ThanksGeorge
I also got shot down hard by someone in my personal life. But that is too personal for the internet.
So anyyyyways.......
This week is a little bit of a continuation of the plans I made for my open source development ventures last week. A little bit of a recap.. Last week I decided to pick a repo that I have contributed to in the past. Seeing as my schedule is super tight until the end of the semester, I decided to go back a month and revisit the automating whatsapp web platform. I picked two issues because one was easier than the other and I had created something similar.
Ok!
So I saw that most people on the issues that have been assigned have made little or no progress. I asked Navpreet (the owner/maintainer of the repo) if I could take this issue. He gave me the green light. Although, to be honest I already had started working on the issue before he said it is fine (I knew it would be fine).
I was tasked with creating a function similar to one that already existed. I had to create a function to remove Administrative privileges from a person/people in a whatsapp group.
As I began working I first examined the steps I had to manually take to remove admin privileges in order to replicate them and adding them into the automation bot.
Since the main logic is being done by Selector constants I had to find the selectors that were responsible for removing admin status from a person in a group.
I inspected the element with the chrome dev tools and quickly found exactly what I was looking for (this took me a while in Release 0.2, but I knew what to look for now).
P.S. The steps you take to removing an admin all lead to using the same selector regardless.
Now that I had my selector. It was time to actually put it in the constants .py file that is used for everything.
GROUPS__REMOVE_ADMIN =
(By.CSS_SELECTOR, '._1OwwW ._3oTCZ[title="Dismiss as admin"]')
After that was done it was time to start writing the actual code.
The first thing I had to do was to iterate through the groups and find group name with the passed in one. This is being done by querying the selector and looking for it to match with whatever element you are on. Once the group chat was open, the bot needed to open the group chat info and navigate to the participants section. From there it searches for the name(s) passed in to remove admin privileges from, this is done by finding if the admin logo is present on their name. Clicks their name box and selects "Dismiss as admin".
Everything worked. there was a couple of bugs at first. I was not checking if the user of the group was already an admin or not and the bot started hanging because it was trying to find an element to click on that did not exist yet. Another problem I actually ran into was that I had to tweak the CSS selector a bit because it is the same selector for making an admin and removing an admin. This is why in the above snippet I decided to include the title as well so it does not create an admin by accident.
Now, that I was done with this feature I could hurry back to Navpreet and have him run it on his end. I submitted a PR and since Navpreet and I are somewhat acquainted from my previous contributions, he knows my secret love most hated feeling is towards python and everything python related. So he gave me a little praise to help me with the next big issue I was going to do for him.
Everything is going swell. My PR even got merged. ONTO better things... not really. OSD is probably my most enjoyed course right now. Everything else feels like such a drag and there is sooo much work.
Anyways this is where I end things for my ventures of open source this week. I have actually started working on my other issue for Navpreet but it is proving to be a little more difficult than I expected. 0.4 amiright?!
I am now going to crack open a beer and enjoy the rest of my night, and try not to think about stupid little details.
Till next time,
XOXO,
Gossip Plamen
No comments:
Post a Comment