-
Notifications
You must be signed in to change notification settings - Fork 0
/
campaign.py
90 lines (73 loc) · 2.88 KB
/
campaign.py
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
84
85
86
87
88
89
90
import asyncio
from connection import Warmup_data
from core import Core
import sendEmail
class Campaign:
source_email = None
target_email = None
subject = None
Body = None
def __init__(self):
self.data = Warmup_data()
def get_target_db(self,email):
result = self.data.select_all(
"""SELECT * FROM target
where email = '""" + str(email) + """' """)
return result
def get_source_db(self):
result = self.data.select_all(
"""SELECT * FROM source
ORDER BY RAND()
LIMIT 1 """)
return result
def check_source_campaign(self):
target_email_ = self.get_target_db(self.target_email)
target_email_id = target_email_[0][0]
self.source_email = self.get_source_db()
source_id = self.source_email[0][0]
result = self.data.select_all(
""" SELECT * FROM campaign where source_email_id = """ + str(source_id) + """ and target_email_id = """+str(target_email_id))
return result
def sendEmail(self):
sendEmail.our_email = self.target_email
# sendEmail.main("source",self.source_email[0][2])
return sendEmail.get_user_service(self.source_email[0][2])
def func1(self):
source_camp = self.check_source_campaign()
service = self.sendEmail()
if source_camp:
result = self.data.select_all("Select * from gmailThreadId where id ="+str(source_camp[0][5]))
message = sendEmail.get_msg_headers(service,str(result[0][1]))
print("message",str(result[0][1]))
print(message)
print(self.source_email[0][2], self.subject,self.Body, str(result[0][2]), str(message['Message-Id']))
sendEmail.send_message_thread(service, self.source_email[0][2], self.subject,self.Body, str(result[0][2]), str(message['Message-Id']))
else:
sendEmail.send_message(service, 'farhan.pirzada@invozone.com',self.subject,self.Body)
print("Message sent")
def func2(self,task_no):
print(f'{task_no}... Blog!')
async def async_func(self,task_no):
self.func1()
await asyncio.sleep(1)
self.func2(task_no)
async def main(self):
taskA = loop.create_task (self.async_func('taskA'))
await asyncio.wait([taskA])
if __name__ == "__main__":
camp = Campaign()
camp.target_email = "farhan.pirzada@invozone.com"
camp.subject = "Campaign"
camp.Body = "Campaign Body"
## update the source in database
# run = Core()
# run.json_to_db('target')
## target email address
try:
# camp.check_source_campaign()
# loop = asyncio.get_event_loop()
# loop.run_until_complete(camp.main())
# import pdb; pdb.set_trace()
camp.func1()
except Exception as e:
print(e)