mirror of
				https://github.com/SlavikMIPT/tgcloud.git
				synced 2025-03-09 15:40:14 +00:00 
			
		
		
		
	working prototype(slow)
filebrowser: https://github.com/filebrowser/filebrowser
This commit is contained in:
		
							parent
							
								
									2db2eaaeaf
								
							
						
					
					
						commit
						b7028e786c
					
				
					 12 changed files with 257 additions and 155 deletions
				
			
		
							
								
								
									
										51
									
								
								test.py
									
										
									
									
									
								
							
							
						
						
									
										51
									
								
								test.py
									
										
									
									
									
								
							|  | @ -7,6 +7,8 @@ try: | |||
|     from StringIO import StringIO | ||||
| except ImportError: | ||||
|     from io import StringIO | ||||
| from io import BytesIO | ||||
| from download_service import download_block, upload_block | ||||
| 
 | ||||
| import subprocess | ||||
| import tempfile | ||||
|  | @ -19,7 +21,7 @@ class Buffer:  # {{{1 | |||
|     """ | ||||
| 
 | ||||
|     def __init__(self): | ||||
|         self.buf = StringIO() | ||||
|         self.buf = BytesIO() | ||||
|         self.dirty = False | ||||
| 
 | ||||
|     def __getattr__(self, attr, default=None): | ||||
|  | @ -46,43 +48,34 @@ class Buffer:  # {{{1 | |||
|         return self.buf.write(*args) | ||||
| 
 | ||||
| 
 | ||||
| chat_id = 709766994 | ||||
| user_id = 709766994 | ||||
| 
 | ||||
| file_id = '012345678910abcdef' | ||||
| 
 | ||||
| 
 | ||||
| def get_block_from_telegram(chat_id, digest): | ||||
|     # path = download_block(chat_id=chat_id, uid=digest) | ||||
|     # buf = open('tempfile2', 'wb') | ||||
|     buf = tempfile.TemporaryFile() | ||||
|     process = Popen(["python3.6", "download_service.py", "download", str(chat_id), str(digest)], stdout=buf, bufsize=-1,shell=False) | ||||
|     buf = tempfile.NamedTemporaryFile() | ||||
|     process = Popen(["python3.6", "download_service.py", "download", str(chat_id), str(digest)], stdout=buf,shell=False) | ||||
|     process.wait() | ||||
|     # buf.close() | ||||
|     # buf = open('tempfile2', 'rb') | ||||
|     buf.seek(0) | ||||
|     block = buf.read() | ||||
|     buf.close() | ||||
|     return block | ||||
| 
 | ||||
| chat_id = 123 | ||||
| user_id = 123 | ||||
| 
 | ||||
| file_id = 'a4ddb160d8a42a9379d6fbbd0cb72ff11efe9cb5' | ||||
| # #upload | ||||
| # buf = Buffer() | ||||
| # with open('test.mp4','rb') as fp: | ||||
| #     buf = fp.read() | ||||
| # import hashlib | ||||
| # | ||||
| # hexdigest = hashlib.sha1(buf).hexdigest() | ||||
| # process = Popen(["python3.6", "download_service.py", "upload", str(chat_id), str(hexdigest)], stdin=PIPE, bufsize=-1) | ||||
| # process.stdin.write(buf) | ||||
| # process.stdin.close() | ||||
| # process.wait() | ||||
| # #download | ||||
| block = get_block_from_telegram(chat_id, file_id) | ||||
| outfile = open('tempfile.mp3','wb') | ||||
| outfile = open('tempfile_read2.mp3','wb') | ||||
| outfile.write(block) | ||||
| outfile.close() | ||||
| buf = Buffer() | ||||
| buf = b'12345678' | ||||
| # with open('testfile.mp3','rb') as fp: | ||||
| #     buf = fp.read() | ||||
| # | ||||
| process = Popen(["python3.6", "download_service.py", "upload", str(chat_id), str(file_id)], stdin=PIPE, bufsize=-1) | ||||
| process.stdin.write(buf) | ||||
| process.stdin.close() | ||||
| process.wait() | ||||
| 
 | ||||
| 
 | ||||
| # upload_block(string_to_upload=buf.buf.getvalue(), chat_id=chat_id, hash_uid=str(file_id)) | ||||
| # storage = shelve.open('./storage.db') | ||||
| # object = get_block_from_telegram(chat_id, file_id) | ||||
| # | ||||
| # storage[file_id] = object | ||||
| # print(storage[file_id]) | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue