-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsend_update_old.py
More file actions
83 lines (60 loc) · 2.09 KB
/
Copy pathsend_update_old.py
File metadata and controls
83 lines (60 loc) · 2.09 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import telegram
import os
import json
import threading
_arquivolock = threading.Lock()
base_path = "/home/ferraroni/Documents/telegram_bot/subs/"
def envia(bot,processo,mensagem):
for filename in os.listdir(base_path):
try:
file_path = base_path+filename
_arquivolock.acquire()
file = open(file_path,"r")
infos = json.loads(file.read())
file.close()
_arquivolock.release()
envia = None
if processo in infos["inscritos"]:
primeira = None
try:
infos["mensagens_enviadas"][processo]
primeira = False
except:
primeira = True
if primeira==True:
infos["mensagens_enviadas"][processo] = mensagem
envia = True
elif primeira==False:
if infos["mensagens_enviadas"][processo]==mensagem:
envia = False
else:
infos["mensagens_enviadas"][processo] = mensagem
envia = True
_arquivolock.acquire()
file = open(file_path,"w")
file.write(json.dumps(infos))
file.close()
_arquivolock.release()
if envia:
msg = ""
msg += processo+": "+mensagem
bot.sendMessage(chat_id=infos["cod"], text=msg)
except Exception as e:
a = open("erros","a")
a.write(str(e)+"\n")
a.close()
class Enviador():
def __init__(self):
file = open("/home/ferraroni/apis/telegram","r")
key = file.read()
file.close()
self.bot = telegram.Bot(token=key)
def envia_notificacao(self, processo, mensagem):
t = threading.Thread(target=envia,args=[self.bot,processo,mensagem])
t.start()
return
# if __name__ == '__main__':
# e = Enviador()
# for i in range(100):
# e.envia_notificacao("a", str(i)+"%")
# print "Fim"