Created
November 20, 2017 21:47
-
-
Save WoodProgrammer/0625f0d820e3392a86e97f1197f5d248 to your computer and use it in GitHub Desktop.
Download Photos to where your telegram bot run .
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import requests,json | |
| class Photo2Down: | |
| def __init__(self,TOKEN): | |
| self.TOKEN = TOKEN | |
| def download(self,file_id): | |
| file_meta_data = requests.get("https://api.telegram.org/bot{}/getFile?file_id={}".format(self.TOKEN,file_id)) ## resme ait meta data boyut,path vs | |
| tmp_file_meta_data = json.loads(file_meta_data.content) # converting | |
| if tmp_file_meta_data['ok'] == True: ##resim id status contorl | |
| file_path = tmp_file_meta_data['result']['file_path'] ## file path | |
| file_data = requests.get("https://api.telegram.org/file/bot{}/{}".format(self.TOKEN,file_path)) ##isterk ve gelen binary data | |
| if file_data.status_code != 200 : | |
| return "ERROR Code {}".format(file_data.status_code) | |
| else: | |
| self.create_jpeg(file_data.content,file_path.split('/')[1]) ## bu binary dosyaya yazılıyor. | |
| def create_jpeg(self,binary_content,file_name): | |
| file = open("{}".format(file_name),"wb") | |
| file.write(binary_content) | |
| file.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment