1
0
Fork 0
mirror of https://github.com/SlavikMIPT/tgcloud.git synced 2025-02-14 20:22:12 +00:00

Check if block has already uploaded

This commit is contained in:
Вячеслав Баженов 2019-07-10 05:09:27 +03:00
parent efc882715f
commit d194c27e0f

View file

@ -6,11 +6,11 @@ from __future__ import unicode_literals
import os import os
import time import time
from telethon.tl.types import DocumentAttributeFilename from telethon.tl.types import DocumentAttributeFilename
from telethon.telegram_client import TelegramClient
from telegram_client_x import TelegramClientX
from secret import * from secret import *
from telegram_client_x import TelegramClientX
path_home = './' # os.path.abspath('.') path_home = './' # os.path.abspath('.')
client = TelegramClientX(entity, api_id, api_hash, update_workers=None, spawn_read_thread=True) client = TelegramClientX(entity, api_id, api_hash, update_workers=None, spawn_read_thread=True)
@ -64,9 +64,9 @@ def download_block(hash_uid, filename):
# if oe.errno != errno.EEXIST: # if oe.errno != errno.EEXIST:
# raise # raise
# outbuf = open(FIFO, "wb"): # outbuf = open(FIFO, "wb"):
# os.unlink(FIFO) # os.unlink(FIFO)
client.download_media(msg, file=filename, progress_callback=on_download_progress) client.download_media(msg, file=filename, progress_callback=on_download_progress)
# outbuf.flush() # outbuf.flush()
return 0 return 0
except Exception as e: except Exception as e:
return -1 return -1
@ -86,7 +86,10 @@ def upload_block(hash_uid):
except OSError as oe: except OSError as oe:
if oe.errno != errno.EEXIST: if oe.errno != errno.EEXIST:
raise raise
messages = client.get_messages(entity, limit=1, search=hash_uid)
with open(FIFO, 'rb') as bytesin: with open(FIFO, 'rb') as bytesin:
if messages:
return 0
message = client.send_file(entity, message = client.send_file(entity,
file=bytesin, file=bytesin,
caption=f'{hash_uid}', caption=f'{hash_uid}',
@ -107,8 +110,8 @@ def main(argv):
service = str(argv[1]) service = str(argv[1])
if service == 'download': if service == 'download':
uid = str(argv[2]) uid = str(argv[2])
filename = str (argv[3]) filename = str(argv[3])
download_block(hash_uid=uid,filename=filename) download_block(hash_uid=uid, filename=filename)
return 0 return 0
elif service == 'upload': elif service == 'upload':
uid = str(argv[2]) uid = str(argv[2])