Medium | python4you
801 FOLLOWERS
Publications about python, tips and tricks and some useful pieces of code
Medium | python4you
2y ago
Photo by olieman.eth on Unsplash
With the increasing number of security threats, it is important to use (and follow the best practices) only those “secrets” that you really need in your Github repository.
You may have a situation where you have a lot of Github repositories to manage and each of them is using repository secrets. Probably some of the secrets are not used anymore, maybe they are already not valid, or maybe not, who knows and why not just get rid of them.
I wrote a small Python utility that detects unused repository secrets (https://github.com/artemrys/detect-gh-actions ..read more
Medium | python4you
5y ago
Why Should You Use typing In Python?
Photo by Nicole Wolf on Unsplash (I just like this photo)I am using typing at my work project and now trying to use it for my personal or freelance projects only if it is not a one-time script. No sense to invest time in the 15-minute thing. And why you should use it too.
Lots of people like Python because it provides a fast way to build software. But on the other hand, after some time of the team development, it can be hard to understand the code for the team members. Especially, for the new ones.
I do personally believe that it increases the readability o ..read more
Medium | python4you
5y ago
“Effective Python” by Brett Slatkin Book Review
I was mailed with a proposition to review a book. I wanted to try so here we go.
The book is from Brett Slatkin (it is the second edition), he is Googler who developed AppEngine and lots of other things in Google.
Let’s start with the target audience for this book. I’d recommend it to the people who are using Python at least several months and are feeling good with the basics. If you need more practical advice you are definitely welcome.
I do personally like the structure and the idea of the book — there are 90 tips to make your Python programmin ..read more
Medium | python4you
5y ago
Photo by Jason Leung on UnsplashI have been writing a small scraping application these days. I wanted it to send metrics and use chromedriver. I also wanted to be able to run it locally and don’t send metrics while running locally. So, I needed some way to separate local and production environments. The easiest way to do that — use flags.
My options:
optparse — deprecated
argparse — builtin Python library to deal with flags
abseil — an open-source library from Google
That time I did not know anything about abseil, so my only choice was to use argparse. That’s what I have got with it.
import ..read more
Medium | python4you
5y ago
In this story, I will point you to the 5 tips that I have collected while working on my freelance scraping projects ..read more
Medium | python4you
5y ago
Monitoring traffic of your Github repositories using Python and Google Cloud Platform — Part 1
Photo by Paweł Czerwiński on UnsplashIt is an article about monitoring your Github open-source repositories traffic. Unfortunately, you can see these statistics only by accessing each repository step by step. You may not want to access them at all… But if you do, you can use this small tool.
Technical stack:
Python 3.7, PyGithub
Google Cloud: Functions, Firestore
Github API v3
And from the perspective of $ — this solution is zero cost because of the free quota you have in Google Cloud Platform. N ..read more
Medium | python4you
5y ago
Photo by Khadeeja Yasser on UnsplashRecently being in Budapest (great city by the way) I saw lots of Starbucks coffee shops and decided to write a small script that will rank capitals by the number of Starbucks there.
I am not pretending to get the most accurate results, it is just an example. So, please don’t use it make some serious business decisions :)
We will use Google Places API and a local copy of a bit reworked list of capitals’ coordinates from here.
The full code is available here.
First of all, let me say that Google Places API has a serious limitation of returning maximum 60 resul ..read more
Medium | python4you
5y ago
I have been on the several Python interviews again and have passed an Upwork Python test. And I have noticed that the interviewers like using task as the following one.Photo by Joanna Kosinska on Unsplashdef f(x, l=[]): for i in range(x): l.append(i * i) return l>>> f(2) >>> f(3, [0, 1, 2]) >>> f(3)Question: what is the output of those lines?The output of the first two lines is pretty obvious, but the result of the third line f(3) wasn’t so intuitive for me.So let’s investigate what is going on after the initialization of the f function. I use IPython ..read more
Medium | python4you
6y ago
Some Python magic around sys.exit() function.Photo by Christopher Burns on UnsplashRecently I’ve been at the interview for one big Israel startup. They asked me to read the code below and say what will be in the output.https://medium.com/media/3bcfa01872a34dbaf8a433ec94c8d12e/hrefWhat do you think to be the output after running this code snippet?Is it depend on the body of some_func function?Let’s try to figure out what is going on within this small piece of code.Did you know that sys.exit(code) raises SystemExit exception?Lines 10–11 will raise an SystemExit exception2. SystemExit exception i ..read more
Medium | python4you
6y ago
It’s a small note about the Scrapy Item Pipeline that publishes a Scrapy Item to the RabbitMQ.Photo by rawpixel on UnsplashIf you are interested in parsing/scraping projects in Python, you should know about Scrapy. Let’s imagine that your project is something bigger than a one-time data extraction. This means that you need to do something with your data. One of the possible approaches is to use RabbitMQ to publish items to some queue. This method can help you to build a custom consumer that can process Scrapy items.Code (repository can be found out here):https://medium.com/media/da4bfe94193999 ..read more