-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChannel.py
More file actions
51 lines (42 loc) · 2.35 KB
/
Channel.py
File metadata and controls
51 lines (42 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import requests, os, errno
class Channel:
def __init__(self, handler):
try:
get_chat_URL = 'https://api.telegram.org/bot1071915503:AAG6OVmjh_NfNIz21aSFmBv85d3sEBhfxns/getChat'
get_chat_members_count_URL = 'https://api.telegram.org/bot1071915503:AAG6OVmjh_NfNIz21aSFmBv85d3sEBhfxns/getChatMembersCount'
get_user_profile_photos_URL = 'https://api.telegram.org/bot1071915503:AAG6OVmjh_NfNIz21aSFmBv85d3sEBhfxns/getUserProfilePhotos'
get_profile_picture_path_URL = 'https://api.telegram.org/bot1071915503:AAG6OVmjh_NfNIz21aSFmBv85d3sEBhfxns/getFile'
get_profile_picture_URL = 'https://api.telegram.org/file/bot1071915503:AAG6OVmjh_NfNIz21aSFmBv85d3sEBhfxns/'
PARAMS = {'chat_id':handler}
r = requests.get(url = get_chat_URL, params = PARAMS)
data = r.json()
r2 = requests.get (url = get_chat_members_count_URL, params = {'chat_id':handler})
r3 = requests.get (url = get_profile_picture_path_URL, params = {'file_id':data['result']['photo']['big_file_id']})
r4 = requests.get (url = get_profile_picture_URL+ r3.json()['result']['file_path'])
self.handler = handler
self.title = data['result']['title']
self.id = data['result']['id']
self.username = data['result']['username']
self.description = data['result']['description']
self.subscribers_count = r2.json()['result'] if r2.json()['ok'] else 0
# self.profile_pic_path = 'http://localhost:8000/images/'+str(self.id)+'.jpg'
self.image = r4.content
self.valid = 'valid'
except:
self.valid = 'invalid'
self.title = None
self.id = None
self.username = None
self.description = None
self.subscribers_count = None
self.profile_pic_path = None
self.image = None
return
# if not os.path.exists(os.path.dirname(self.profile_pic_path)):
# try:
# os.makedirs(os.path.dirname(self.profile_pic_path))
# except OSError as exc:
# if exc.errno != errno.EEXIST:
# raise
# with open(self.profile_pic_path, 'wb') as f:
# f.write(r4.content)