Skip to content

Commit 90c485e

Browse files
authored
Merge pull request #14 from tainguyenbp/feat/learing-python-language
learning python language
2 parents e465ed7 + 2762a3b commit 90c485e

File tree

6 files changed

+110
-0
lines changed

6 files changed

+110
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# FROM python:3.9-slim
2+
3+
# WORKDIR /app
4+
5+
# COPY requirements.txt requirements.txt
6+
# RUN pip3 install -r requirements.txt
7+
8+
# COPY . .
9+
10+
# CMD ["flask", "run", "--host=0.0.0.0", "--port=5000"]
11+
12+
13+
# Use an official Python runtime as a parent image
14+
FROM python:3.9-slim
15+
16+
# Set the working directory in the container
17+
WORKDIR /app
18+
19+
# Copy the requirements file into the container
20+
COPY requirements.txt .
21+
22+
# Install any needed packages specified in requirements.txt
23+
RUN pip3 install --no-cache-dir -r requirements.txt
24+
25+
# Copy the current directory contents into the container at /app
26+
COPY . .
27+
28+
# Make port 5000 available to the world outside this container
29+
EXPOSE 5000
30+
31+
# Define environment variable
32+
ENV FLASK_ENV=production
33+
34+
# Run app.py when the container launches
35+
CMD ["flask", "run", "--host=0.0.0.0", "--port=5000"]
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from flask import Flask
2+
from twilio.rest import Client
3+
app = Flask(__name__)
4+
@app.route('/trigger-calls', methods=['GET', 'POST'])
5+
def trigger_call():
6+
account_sid = '<acc-sid>'
7+
auth_token = '<acc-auth>'
8+
client = Client(account_sid, auth_token)
9+
# List of numbers to call
10+
numbers_to_call = ['<country-code-number>', '<country-code-number>']
11+
call_sid = [] # To store Call SIDs
12+
for number in numbers_to_call:
13+
call = client.calls.create(
14+
twim='<Response><Say>"change Alert message here"</Say></Response>',
15+
to=number,
16+
from_='<twilio-number>'
17+
)
18+
call_sids.append(call.sid)
19+
# Joining all the Call SIDs to return in response
20+
call_sids_str = ', 'join(call_sids)
21+
return f"Call initiated with SIDs: {call_sids_str}", 200
22+
if __name__ == '__main__':
23+
app.run(host'0.0.0.0', port=5000)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
### test
2+
```
3+
sudo apt install python3-pip
4+
sudo apt install python3.12-venv
5+
python3 -m venv venv
6+
source venv/bin/activate
7+
8+
pip install -r requirements.txt
9+
10+
docker build -t webhook .
11+
docker run -d --name webhook -p 5000:5000 webhook:v1.0.0
12+
13+
```
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Flask==2.0.1
2+
twilio==7.4.0
3+
Werkzeug==2.0.1
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/python3
2+
3+
import requests
4+
import sys
5+
6+
7+
if __name__ == "__main__":
8+
# Define the URL for the REST API
9+
url = "https://jsonplaceholder.typicode.com/"
10+
11+
# send a GET request to retrieve user info
12+
user = requests.get(url + "users/{}".format(sys.argv[1])).json()
13+
14+
# send a GET request to retrive the TODO list
15+
todos = requests.get(url + "todos", params={"userId": sys.argv[1]}).json()
16+
17+
# filter completed TODO list and store titles in a list
18+
completed = [t.get("title") for t in todos if t.get("completed") is True]
19+
20+
# print employee's name, completed tasks & total no of tasks
21+
print("Employee {} is done with tasks({}/{}):".format(
22+
user.get("name"), len(completed), len(todos)))
23+
24+
# print the titles of completed tasks with indentation
25+
[print("\t {}".format(c)) for c in completed]
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### test
2+
```
3+
sudo apt install python3-pip
4+
sudo apt install python3.12-venv
5+
python3 -m venv venv
6+
source venv/bin/activate
7+
8+
pip install -r requirements.txt
9+
10+
python3 gather-data-api .py
11+
```

0 commit comments

Comments
 (0)