Celery – schedule tasks with pauses between them

I needed to schedule 10 tasks that have these conditions

  1. A time gap between tasks is fixed (but varies)
  2. No need to pass results of one task to another
  3. Need to read a database in every task (important: at the moment of the execution)

I tried a few options, and this one worked

 ret = chain(task1.si(args).set(countdown=30*1), ..., task10.si(args).set(countdown=30*10)).apply_sync()

Important note – the signature here is not .s() but .si() this way you don’t pass the result of task1 to task2. You set the countdown with set() and not inside the apply_sync().

It is simple but it took me some time to figure out.

To my from now on wandering friends (RU)

Сложные времена лишений впереди, но они как ничто другое толкают нас на великие свершения. Вы не одиноки. Всё когда-то кончается - и плохое, и хорошее.

Если кто-нибудь из ваших знакомых хочет заняться кодингом, и когда если не сейчас - пишите в телегу - я помогаю начинающим (и продолжающим) бесплатно.

A message for my russian-speaking readers:

Difficult times are ahead of us, but they are forcing us to do great things like nothing else. You are not alome. Everything ends - both bad and good.

If your friends are willing to try and start coding now for the first time, now or never - message my Telegram account - I am helping beginners who want to code.

A short note about JS

I have been working with JavaScript lately, and I enjoy it so much. It gives me the whole “mobile development vibe” but it is much quicker and easier – no need to build all the time etc. I have to say, it is inclining me to resuming mobile dev activities… not gonna lie.

Just a short note to tell you about the fun I’ve having 😉

macOS (M1/M1 Pro) – ffmpeg with mp3 support and OpenCV

This is not funny – I spent a few evening fixing and fixing and fixing. Now ./configure then make and sudo make, but where is binary? Why is it not is /usr/bin/ OR /usr/local/bin/? Oh you do brew install opencv – but it does not work in terminal? Amazing. I was THIS close to wiping mac os and installing Linux on my macbook guys, THIS CLOSE.

Anyhow it is simple if you do the right thing.

ffmpeg with mp3 support

brew uninstall lame —force
brew uninstall homebrew-ffmpeg/ffmpeg/ffmpeg
brew install homebrew-ffmpeg/ffmpeg/ffmpeg —with-fdk-aac

In your virtualenv

pip uninstall ffmpeg
pip uninstall ffmpeg-python
pip install ffmpeg-python

And then install OpenCV (it is now working with pip):

pip install opencv-python

How to speed up Django Admin: Foreignkey and ManyToManyField

If you have a Foreignkey or ManyToManyField in your admin form, but you don’t need to change it in any way, replace it with a label. Say, you have a model:

class Student(models.Model):
    class_obj = models.ForeignKey('Class', on_delete=models.CASCADE)

And in your Django Admin you want to have thic field:

class StudentAdmin(admin.ModelAdmin):
    fields = ('class_obj',)

There is no problem if you have, say, 10-100 Class instances, but if you have thousands of them – the interface would take a lot of time to load.

Instead of that, make a label property and replace the original field with it.

class Student(models.Model):
    class_obj = models.ForeignKey('Class', on_delete=models.CASCADE)

    def class_obj_str(self):
        return self.class.name

And then in the ModelAdmin:

class StudentAdmin(admin.ModelAdmin):
    readonly_fields = ('class_str',)
    fields = ('class_obj_str',)

What I am up to these unsettling days

The world is crazy, but I don’t let it deter me. I am a great believer in doing things during challenging times. So my brother and I are spending our spare (from work) time at Codewars and Hackerrank.


First, I returned to HackerRank to do some SQL, and I completed everything I found relevant to my current studies. It seems like from the lack of use I lost some of my SQL knowledge and I want to fix that.

My modest achievements at HackerRank

I plan to do much more with Problem Solving (there are a few data structures and algorithms I am not yet very familiar with). Maybe I will return and do more of Python, but at this point I just feel bored and uninspired.

SQL Academy

Then I jumped to SQL Academy, and I loved it, but it has too many bugs to my taste

UPD. 24.03.22 – I am a moron. I don’t see bugs, I just missed some details and therefore couldn’t successfully submit a few tasks. Now I bought a Premium account for $10 and realized my mistakes. I use it after I complete the tasks to see how a DB expert would solve it. Can’t wait to finish the task list by end of the week (wish me luck hehe).

One downside for me – it requires MySQL syntax, and I am not really interested in it. I personally find PostgreSQL more accomodating to Python users and those who don’t specialize solely in databases too.

The interface is fantastic and I love how you can see queries and tables and an ERM. I will be completing everything that bugs will let me – it has been very useful to me.


Meanwhile my brother has been devoured by Codewars, so after all these websites I returned to it. I have a rather old account there (since 2018), but I haven’t touched it in a while. I have had 5 kyu since forever, now I really want to get 4 kyu, even though it is not just in Python hehe.

My modest achievements at Codewars

In February I upgraded my DS/Algorithms skills with Udemy courses, Yandex Youtube lectures and personal studies here and there. I am excited to return to Problem Solving katas at Codewars with all this acquired knowledge.

Summing Up

All in all, right now I am very much into coding simulators. They bring me a sense of accomplishment that I desperately need right now. Badges and certificates – small achievements you can touch. That brings comfort if anything. So I encourage everybody I know who struggles with reality right now – to do the same. At very least, you came out of it more educated and with brighter prospects.

GitPython – Diff between two branches

My dear brother started his own blog on Airflow, Python, PostgreSQL and Javascript!!!

Congrats, Ilia!

Ilia's Airflow, Python, PostgreSQL, Javascript Journey


import os
from pathlib import Path 
from git import Repo

# path to repo folder
path = Path(os.path.dirname(os.path.abspath(__file__)))

# repo variable
repo = Repo(path)

# Your last commit of the current branch
commit_feature = repo.head.commit.tree

# Your last commit of the dev branch
commit_origin_dev = repo.commit("origin/dev")
new_files = []
deleted_files = []
modified_files = []

# Comparing 
diff_index = commit_origin_dev.diff(commit_feature)

# Collection all new files
for file in diff_index.iter_change_type('A'):

# Collection all deleted files
for file in diff_index.iter_change_type('D'):

# Collection all modified files
for file in diff_index.iter_change_type('M'):


Let’s imagine the situation:

You are before code review and you need to get all changes between feature and develop with GitPython.
First you need to get last commits from two branches:

# Your last commit of the current branch
commit_dev = repo.head.commit.tree

# Your last commit of the dev branch
commit_origin_dev = repo.commit("origin/dev")

Then get your changes:

View original post 81 more words

Google Drive API with Python – Upload & Download a file

For how to authenticate yourself please go watch this video.

You will need a token.json with this content in the root of your project:

  "token": "generated_access_token",
  "refresh_token": "generated_refresh_token",
  "token_uri": "https://oauth2.googleapis.com/token",
  "client_id": "your_client_id",
  "client_secret": "your_client_secret",
  "scopes": [

I will be using Google’s Quickstart as a foundation for what I am doing.

Read More »