-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #14 from tainguyenbp/feat/learing-python-language
learning python language
- Loading branch information
Showing
6 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# FROM python:3.9-slim | ||
|
||
# WORKDIR /app | ||
|
||
# COPY requirements.txt requirements.txt | ||
# RUN pip3 install -r requirements.txt | ||
|
||
# COPY . . | ||
|
||
# CMD ["flask", "run", "--host=0.0.0.0", "--port=5000"] | ||
|
||
|
||
# Use an official Python runtime as a parent image | ||
FROM python:3.9-slim | ||
|
||
# Set the working directory in the container | ||
WORKDIR /app | ||
|
||
# Copy the requirements file into the container | ||
COPY requirements.txt . | ||
|
||
# Install any needed packages specified in requirements.txt | ||
RUN pip3 install --no-cache-dir -r requirements.txt | ||
|
||
# Copy the current directory contents into the container at /app | ||
COPY . . | ||
|
||
# Make port 5000 available to the world outside this container | ||
EXPOSE 5000 | ||
|
||
# Define environment variable | ||
ENV FLASK_ENV=production | ||
|
||
# Run app.py when the container launches | ||
CMD ["flask", "run", "--host=0.0.0.0", "--port=5000"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from flask import Flask | ||
from twilio.rest import Client | ||
app = Flask(__name__) | ||
@app.route('/trigger-calls', methods=['GET', 'POST']) | ||
def trigger_call(): | ||
account_sid = '<acc-sid>' | ||
auth_token = '<acc-auth>' | ||
client = Client(account_sid, auth_token) | ||
# List of numbers to call | ||
numbers_to_call = ['<country-code-number>', '<country-code-number>'] | ||
call_sid = [] # To store Call SIDs | ||
for number in numbers_to_call: | ||
call = client.calls.create( | ||
twim='<Response><Say>"change Alert message here"</Say></Response>', | ||
to=number, | ||
from_='<twilio-number>' | ||
) | ||
call_sids.append(call.sid) | ||
# Joining all the Call SIDs to return in response | ||
call_sids_str = ', 'join(call_sids) | ||
return f"Call initiated with SIDs: {call_sids_str}", 200 | ||
if __name__ == '__main__': | ||
app.run(host'0.0.0.0', port=5000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
### test | ||
``` | ||
sudo apt install python3-pip | ||
sudo apt install python3.12-venv | ||
python3 -m venv venv | ||
source venv/bin/activate | ||
pip install -r requirements.txt | ||
docker build -t webhook . | ||
docker run -d --name webhook -p 5000:5000 webhook:v1.0.0 | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Flask==2.0.1 | ||
twilio==7.4.0 | ||
Werkzeug==2.0.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/python3 | ||
|
||
import requests | ||
import sys | ||
|
||
|
||
if __name__ == "__main__": | ||
# Define the URL for the REST API | ||
url = "https://jsonplaceholder.typicode.com/" | ||
|
||
# send a GET request to retrieve user info | ||
user = requests.get(url + "users/{}".format(sys.argv[1])).json() | ||
|
||
# send a GET request to retrive the TODO list | ||
todos = requests.get(url + "todos", params={"userId": sys.argv[1]}).json() | ||
|
||
# filter completed TODO list and store titles in a list | ||
completed = [t.get("title") for t in todos if t.get("completed") is True] | ||
|
||
# print employee's name, completed tasks & total no of tasks | ||
print("Employee {} is done with tasks({}/{}):".format( | ||
user.get("name"), len(completed), len(todos))) | ||
|
||
# print the titles of completed tasks with indentation | ||
[print("\t {}".format(c)) for c in completed] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
### test | ||
``` | ||
sudo apt install python3-pip | ||
sudo apt install python3.12-venv | ||
python3 -m venv venv | ||
source venv/bin/activate | ||
pip install -r requirements.txt | ||
python3 gather-data-api .py | ||
``` |