add hash calculator

This commit is contained in:
bakatrouble 2022-08-08 04:18:07 +03:00
parent bbd0b635ef
commit eebf4805a3
3 changed files with 34 additions and 3 deletions

View File

@ -42,6 +42,7 @@ filetype = "*"
qrtools = "*" qrtools = "*"
vkwave = "*" vkwave = "*"
imagehash = "*" imagehash = "*"
tqdm = "*"
[dev-packages] [dev-packages]

14
Pipfile.lock generated
View File

@ -1,7 +1,7 @@
{ {
"_meta": { "_meta": {
"hash": { "hash": {
"sha256": "c2d348d08ed9c00095b97958b3ebbd6ddcfd4fc5ed46cbb8b4911c8b3580c577" "sha256": "6c5b61ec9cf199331a9e37fc352bb9d465471287a9d9694df6eb9a3dfbc234ed"
}, },
"pipfile-spec": 6, "pipfile-spec": 6,
"requires": { "requires": {
@ -307,7 +307,7 @@
"sha256:a0713dc7a1de3f06bc0df5a9567ad19ead2d3d5689b434768a6145bff77c0667", "sha256:a0713dc7a1de3f06bc0df5a9567ad19ead2d3d5689b434768a6145bff77c0667",
"sha256:f184f0d851d96b6d29297354ed981b7dd71df7ff500d82fa6d11f0856bee8035" "sha256:f184f0d851d96b6d29297354ed981b7dd71df7ff500d82fa6d11f0856bee8035"
], ],
"markers": "python_version < '4' and python_full_version >= '3.6.2'", "markers": "python_version < '4.0' and python_full_version >= '3.6.2'",
"version": "==0.3.0" "version": "==0.3.0"
}, },
"click-plugins": { "click-plugins": {
@ -1215,7 +1215,7 @@
"sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983", "sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983",
"sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349" "sha256:8fefa2a1a1365bf5520aac41836fbee479da67864514bdb821f31ce07ce65349"
], ],
"markers": "python_version >= '3.7' and python_version < '4'", "markers": "python_version >= '3.7' and python_version < '4.0'",
"version": "==2.28.1" "version": "==2.28.1"
}, },
"requests-oauthlib": { "requests-oauthlib": {
@ -1389,6 +1389,14 @@
"markers": "python_version >= '3.7'", "markers": "python_version >= '3.7'",
"version": "==6.2" "version": "==6.2"
}, },
"tqdm": {
"hashes": [
"sha256:40be55d30e200777a307a7585aee69e4eabb46b4ec6a4b4a5f2d9f11e7d5408d",
"sha256:74a2cdefe14d11442cedf3ba4e21a3b84ff9a2dbdc6cfae2c34addb2a14a5ea6"
],
"index": "pypi",
"version": "==4.64.0"
},
"twisted": { "twisted": {
"extras": [ "extras": [
"http2", "http2",

View File

@ -0,0 +1,22 @@
from io import BytesIO
import imagehash
from PIL import Image
from django.core.management import BaseCommand
from telegram import Bot
from tqdm import tqdm
from bots.modules import QueuedItem
class Command(BaseCommand):
def handle(self, *args, **options):
for item in tqdm(QueuedItem.objects.filter(type='photo', image_hash__isnull=True)):
bot: Bot = item.config.bot.get_bot()
file = bot.get_file(item.args[0])
io = BytesIO()
io.name = 'file.jpg'
file.download(out=io)
im = Image.open(io)
item.image_hash = imagehash.phash(im)
item.save()