Skip to content

Commit 23e5d96

Browse files
authored
Chapter 4 - clean up code, switch to f-strings, remove tokens, and unwanted fluff (#20)
* change to python 3 syntax * clean up for ch 04
1 parent 259ec84 commit 23e5d96

19 files changed

Lines changed: 89 additions & 109 deletions

File tree

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
**/*.pyc
2-
**/venv/*
2+
**/*venv/*
33
**/.idea/*
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
FROM python:3-alpine
22

3-
LABEL author="sathyabhat"
43
LABEL description="Dockerfile for Python script which prints Hello, Name"
54

65
COPY hello-world.py /app/
7-
ENV NAME=Sathya
6+
ENV NAME=Readers
87
CMD python3 /app/hello-world.py
98

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#!/usr/bin/env python3
2-
32
from os import getenv
43

54
if getenv('NAME') is None:
65
name = 'World'
76
else:
87
name = getenv('NAME')
9-
10-
print("Hello, {}!".format(name))
8+
print(f"Hello, {name}!")
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
### README
22

3-
This exercise contains the source code for the second exercise of chapter 4. In this exercise, you will build two Docker images, the first one using a standard build process using python:3 as the base image.
3+
This exercise contains the source code for the second exercise of chapter 4. In this exercise, you will build two Docker images
4+
5+
- Using the standard build process using python:3 as the base image (present in [docker-multi-stage/standard-build](docker-multi-stage/standard-build) directory.
6+
- Using Multi-Stage builds (present [docker-multi-stage/multistage-build](docker-multi-stage/multistage-build) directory.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
praw
1+
praw==3.6.0
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
FROM python:3
22
COPY requirements.txt .
33
RUN pip install -r requirements.txt
4-
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
praw
1+
praw==3.6.0
Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
11
### README
22

3-
This exercise contains the source code for the third exercise of chapter 4. In this exercise, we’ll try writing the Dockerfile for the project.
3+
This exercise contains the source code for the third exercise of chapter 4. In this exercise, we compose a Dockerfile for Newsbot and then use the Dockerfile to build a Docker image and run the container.
4+
5+
6+
### Building the Docker image
7+
8+
Build the image using the below command
9+
10+
```
11+
docker build -t sathyabhat/newsbot
12+
```
13+
14+
Run the container using
15+
16+
```
17+
docker run -e NBT_ACCESS_TOKEN=<token> sathyabhat/newsbot
18+
```
19+
20+
Replace `<token>` with the Telegram API Token that was generated.

source-code/chapter-4/exercise-3/docker-subreddit-fetcher/main.py

Lines changed: 0 additions & 22 deletions
This file was deleted.

source-code/chapter-4/exercise-3/docker-subreddit-fetcher/reddit.py

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)