-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsumer.py
More file actions
56 lines (45 loc) · 1.37 KB
/
Copy pathconsumer.py
File metadata and controls
56 lines (45 loc) · 1.37 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
import json
import os
import sys
import requests
from utils import dict_to_mail,TRANSCODE,APIKEY
import pika
from utils import datetime_convertor
connection = pika.BlockingConnection(
pika.ConnectionParameters(host='localhost', port=5672)
)
channel = connection.channel()
def send(mail):
url = f'http://www.setrowsend.com/email/send.php?k={APIKEY}&transcode={TRANSCODE}'
data = [{
"gonderen_adi": "Türkiye Teknoloji Takımı",
"musterigonderimid": "ID123Q",
"adres": f"{mail.to}",
"alanlar": {"content": f"{mail.content}", "subject": f"{mail.title}"},
"dosya_ek": []
}]
response = requests.post(url, json=data)
if response.status_code == 200:
print('başarılı')
print(response.json())
else:
print(response.status_code)
print(response.json())
def consumer():
def callback(ch, method, properties, body: bytes):
body = body.decode().__str__()
body = json.loads(body)
mail = dict_to_mail(body)
send(mail)
channel.basic_consume(queue='email', on_message_callback=callback, auto_ack=True, )
channel.start_consuming()
if __name__ == '__main__':
try:
consumer()
except KeyboardInterrupt:
connection.close()
print('Interrupted')
try:
sys.exit(0)
except SystemExit:
os._exit(0)