Skip to content

Commit 8b32f96

Browse files
authored
Add files via upload
1 parent 455cc66 commit 8b32f96

9 files changed

+94
-0
lines changed

__pycache__/config.cpython-311.pyc

491 Bytes
Binary file not shown.

__pycache__/twilio.cpython-311.pyc

776 Bytes
Binary file not shown.
935 Bytes
Binary file not shown.
968 Bytes
Binary file not shown.

config.py

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import os
2+
3+
4+
account_sid = os.environ.get('TWILIO_ACC_SID')#'AC725620106f3ce30fe8fe1ff8744aef7f'
5+
auth_token = os.environ.get('TWILIO_ACC_TOKEN') #'84dc547828853e624da51bf7fc1ffac3'
6+
phone_number = os.environ.get('PHONE')

cron.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from apscheduler.schedulers.background import BackgroundScheduler
2+
3+
from twilio_prac import send_whatsapp_text,client,ques
4+
import time
5+
scheduler = BackgroundScheduler(timezone="Asia/Kolkata")
6+
scheduler.start()
7+
8+
job=scheduler.add_job(send_whatsapp_text,'cron',[client,ques],hour='19',minute='09')
9+
print(job)
10+
11+
while True:
12+
time.sleep(1)

db.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"success": {
3+
"total": 4,
4+
"assignments": [
5+
{
6+
"question": "Create a Jenkins pipeline for CI/CD",
7+
"date": "2024-03-16",
8+
"title": "DevOps Task",
9+
"id": "1"
10+
},
11+
{
12+
"question": "Deploy Docker containers using Kubernetes",
13+
"date": "2024-03-15",
14+
"title": "DevOps Task",
15+
"id": "2"
16+
},
17+
{
18+
"question": "Automate server provisioning with Ansible",
19+
"date": "2024-03-14",
20+
"title": "DevOps Task",
21+
"id": "3"
22+
},
23+
{
24+
"question": "Monitor system health using Prometheus and Grafana",
25+
"date": "2024-03-13",
26+
"title": "DevOps Task",
27+
"id": "4"
28+
}
29+
]
30+
},
31+
"error": {
32+
"message": "Failed to retrieve DevOps tasks",
33+
"code": 500
34+
}
35+
}
36+

twilio_conn.py

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from twilio.rest import Client
2+
from config import account_sid, auth_token, phone_number
3+
4+
def twilio_connection(account_sid, auth_token):
5+
client = Client(account_sid, auth_token)
6+
return client
7+
8+
def send_whatsapp_text(client,ques):
9+
message = client.messages.create(
10+
from_='whatsapp:+14155238886',
11+
body=ques,
12+
to=f'whatsapp:{phone_number}'
13+
)
14+
15+
return message.sid
16+
17+
client=twilio_connection(account_sid,auth_token)

twilio_prac.py

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import requests
2+
from twilio_conn import send_whatsapp_text, client
3+
4+
def ques_of_the_day():
5+
link="http://localhost:8000/success"
6+
res = requests.get(url=link)
7+
# print(res)
8+
9+
data=res.json()
10+
status=res.status_code
11+
match status:
12+
case 200:
13+
ques = data['assignments'][0]['question']
14+
case 400:
15+
ques = data['error']['message']
16+
case _:
17+
return "Sorry!"
18+
return ques
19+
20+
ques = ques_of_the_day()
21+
send_whatsapp_text(client,ques)
22+
23+

0 commit comments

Comments
 (0)