Comments Use f string
This commit is contained in:
parent
0a6e12b04f
commit
bc71e1765b
12
main.py
12
main.py
|
@ -1,5 +1,5 @@
|
||||||
try:
|
try:
|
||||||
import urequests as requests
|
import urequests as requests #For MicroPython
|
||||||
except :
|
except :
|
||||||
import requests
|
import requests
|
||||||
import json
|
import json
|
||||||
|
@ -9,10 +9,10 @@ with open("config.json", 'r') as f:
|
||||||
|
|
||||||
offset = "0"
|
offset = "0"
|
||||||
while True:
|
while True:
|
||||||
querry = "limit=1&offset={}&timeout=10".format(offset)
|
|
||||||
#long poll for response
|
#long poll for response
|
||||||
|
querry = f'limit=1&offset={offset}&timeout=10'
|
||||||
try:
|
try:
|
||||||
resp = requests.get(url='https://api.telegram.org/bot{}/{}?{}'.format(config["token"], "getUpdates" ,querry))
|
resp = requests.get(url=f'https://api.telegram.org/bot{config["token"]}/{"getUpdates"}?{querry}')
|
||||||
json = resp.json()
|
json = resp.json()
|
||||||
resp.close()
|
resp.close()
|
||||||
if json.get("result"):
|
if json.get("result"):
|
||||||
|
@ -20,9 +20,9 @@ while True:
|
||||||
offset = json.get("result")[0].get("update_id") + 1
|
offset = json.get("result")[0].get("update_id") + 1
|
||||||
text = json["result"][0]["message"]["text"]
|
text = json["result"][0]["message"]["text"]
|
||||||
print(text)
|
print(text)
|
||||||
#send acknowledgement
|
#echo message
|
||||||
querry = "chat_id={}&text={}".format(config["recipient"], text)
|
querry = f'chat_id={config["recipient"]}&text={text}'
|
||||||
requests.get(url='https://api.telegram.org/bot{}/{}?{}'.format(config["token"], "sendMessage" ,querry))
|
requests.get(url=f'https://api.telegram.org/bot{config["token"]}/{"sendMessage"}?{querry}')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(e)
|
print(e)
|
||||||
resp.close()
|
resp.close()
|
||||||
|
|
Loading…
Reference in New Issue