-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTranslatoBot.py
More file actions
26 lines (21 loc) · 838 Bytes
/
TranslatoBot.py
File metadata and controls
26 lines (21 loc) · 838 Bytes
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
import json
import requests
import configparser as cfg
class translato():
def __init__(self, config):
self.token = self.read_token(config)
self.base = "https://api.telegram.org/bot{}/".format(self.token)
def get_updates(self, offset=None):
url = "https://api.telegram.org/bot<token_key>/getUpdates?timeout=100"
if offset:
url = url + "&offset={}".format(offset + 1)
r = requests.get(url)
return json.loads(r.content)
def send_message(self, msg, chat_id):
url = self.base + "sendMessage?chat_id={}&text={}".format(chat_id, msg)
if msg is not None:
requests.get(url)
def read_token(self, config):
parser = cfg.ConfigParser()
parser.read(config)
return parser.get('creds', 'token')