add hash calculator
This commit is contained in:
parent
bbd0b635ef
commit
eebf4805a3
1
Pipfile
1
Pipfile
@ -42,6 +42,7 @@ filetype = "*"
|
||||
qrtools = "*"
|
||||
vkwave = "*"
|
||||
imagehash = "*"
|
||||
tqdm = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
|
14
Pipfile.lock
generated
14
Pipfile.lock
generated
@ -1,7 +1,7 @@
|
||||
{
|
||||
"_meta": {
|
||||
"hash": {
|
||||
"sha256": "c2d348d08ed9c00095b97958b3ebbd6ddcfd4fc5ed46cbb8b4911c8b3580c577"
|
||||
"sha256": "6c5b61ec9cf199331a9e37fc352bb9d465471287a9d9694df6eb9a3dfbc234ed"
|
||||
},
|
||||
"pipfile-spec": 6,
|
||||
"requires": {
|
||||
@ -307,7 +307,7 @@
|
||||
"sha256:a0713dc7a1de3f06bc0df5a9567ad19ead2d3d5689b434768a6145bff77c0667",
|
||||
"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"
|
||||
},
|
||||
"click-plugins": {
|
||||
@ -1215,7 +1215,7 @@
|
||||
"sha256:7c5599b102feddaa661c826c56ab4fee28bfd17f5abca1ebbe3e7f19d7c97983",
|
||||
"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"
|
||||
},
|
||||
"requests-oauthlib": {
|
||||
@ -1389,6 +1389,14 @@
|
||||
"markers": "python_version >= '3.7'",
|
||||
"version": "==6.2"
|
||||
},
|
||||
"tqdm": {
|
||||
"hashes": [
|
||||
"sha256:40be55d30e200777a307a7585aee69e4eabb46b4ec6a4b4a5f2d9f11e7d5408d",
|
||||
"sha256:74a2cdefe14d11442cedf3ba4e21a3b84ff9a2dbdc6cfae2c34addb2a14a5ea6"
|
||||
],
|
||||
"index": "pypi",
|
||||
"version": "==4.64.0"
|
||||
},
|
||||
"twisted": {
|
||||
"extras": [
|
||||
"http2",
|
||||
|
22
bots/management/commands/channel_helper_calculate_hashes.py
Normal file
22
bots/management/commands/channel_helper_calculate_hashes.py
Normal 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()
|
Loading…
Reference in New Issue
Block a user