Skip to content

Bubeniuk Vlad #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
30f3c2e
Add env and readme.md
ZayJob Nov 9, 2019
816db01
Basic functionality added and application architecture
ZayJob Nov 16, 2019
2005715
Redone architecture and add documentation
ZayJob Nov 17, 2019
589c80b
Add dir tests and change logging
ZayJob Nov 17, 2019
1bfbade
Add setup.py file and requirement.txt
ZayJob Nov 17, 2019
08466f2
Change version
ZayJob Nov 17, 2019
061aaea
Change setup.py
ZayJob Nov 18, 2019
a839057
Add entry point in __main__
ZayJob Nov 19, 2019
cfbdb81
Change path
ZayJob Nov 19, 2019
bc80c7b
Add 3 iteration
ZayJob Nov 24, 2019
fad6d07
Add convert to html(base tamplate)
ZayJob Nov 25, 2019
54b83b4
Limit parameter processing fixed
ZayJob Nov 25, 2019
6bab677
Update README.md
ZayJob Nov 26, 2019
8cb8726
Change setup.py and docker-compose.yaml file
ZayJob Nov 27, 2019
020a7f7
Merge
ZayJob Nov 27, 2019
cb574a2
Change argument_parser.py
ZayJob Nov 27, 2019
80b0192
Change port in docker-compose.yaml
ZayJob Nov 27, 2019
cb3c78e
Add Guide in README.md
ZayJob Nov 27, 2019
1f7bb1a
Add app in docker-compose.yaml
ZayJob Nov 27, 2019
59a3f0d
Change host in mongo
ZayJob Nov 27, 2019
41faeb9
Change mongodb_config.py
ZayJob Nov 27, 2019
bdbde32
Optimized function get_news
ZayJob Nov 27, 2019
5142ca5
Cnahge docker-compose.yaml and Dockerfile
ZayJob Nov 27, 2019
3e7316c
Update README.md and add unit tests
ZayJob Nov 27, 2019
728adca
Add host
ZayJob Nov 28, 2019
3030202
Add Mongo-Express
ZayJob Nov 28, 2019
a781281
Add depends on mongo-express
ZayJob Nov 28, 2019
cfead5b
Add colored
ZayJob Nov 29, 2019
57f1901
Add --to-pdf and install script
ZayJob Nov 30, 2019
2441334
Change README.md
ZayJob Nov 30, 2019
3c681ca
Edit README.md
ZayJob Nov 30, 2019
108783d
Change lid for PDF
ZayJob Nov 30, 2019
2489650
Change README.md
ZayJob Nov 30, 2019
8f8d6c2
eh, not enough time (
ZayJob Dec 1, 2019
5318e0b
last commit
ZayJob Dec 1, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ celerybeat-schedule
# Environments
.env
.venv
.vscode
env/
venv/
ENV/
Expand All @@ -102,3 +103,15 @@ venv.bak/

# mypy
.mypy_cache/

#logging
.idea
apps.log

#file
News_feed.html

.nginx
config
.vscode
.pytest_cache
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM python:3.8

RUN mkdir /code

WORKDIR /code
ADD . /code
ADD requirements.txt code/requirements.txt

RUN python3.8 -m pip install --upgrade -r requirements.txt
ENV PYTHONPATH "${PATHONPATH}:/rss_reader_ft"
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
include requirements.txt
include json_schema.json
117 changes: 117 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
# RSS reader

RSS reader is a command-line utility which receives RSS URL and prints results in human-readable format.

## Specification

Utility provides the following interface:
+ positional arguments:
+ source - RSS URL
+ optional arguments:
+ -h, --help - Show help message and exit.
+ --version - Print version info.
+ --json - Print result as JSON in stdout.
+ --verbose - Outputs verbose status messages.
+ --limit - Limit news topics if this parameter is provided.
+ --date - Return cached news from the specified day. Format is %Y%M%D. **Shows the news of the day when you viewed them**
+ --to-html - Print result as in HTML file
+ --to-pdf - Print result as in PDF file

## Install RSS reader v2.0 (work)
1. Create docker container:
```
docker run -it python /bin/bash
```
2. Clone or Download repository https://github.com/ZayJob/PythonHomework
3. Go to folder /PythonHomework
4. **git branch**
5. There is no branch besides **master**? Then follow this tutorial:
```
git branch --track finalTask remotes/origin/finalTask
git checkout finalTask
git checkout cfbdb81
```

6. I recommend creating a virtual environment. **python3.8 -m venv env**, **. env/bin/activate**.
7. Let's collect our package **python3.8 setup.py sdist**.
8. Let's install our package **pip3.8 install dist/rss_reader_ft-2.0.tar.gz**
9. Let's install req. **pip3.8 install -r requirements.txt**.
10. Use:
```
rss-reader "https://news.yahoo.com/rss/" --limit 1
```

## About my unittests )))

![](https://raw.githubusercontent.com/ZayJob/Telegram-bot/master/CryptoTower/6gGLqaT30sw.jpg)

## Install RSS reader v5.0 (work)
1. Create docker container:
```
docker run -it -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock python /bin/bash
```
2. Paste this commands into the console:

```
git clone https://github.com/ZayJob/PythonHomework

cd PythonHomework

git branch --track finalTask remotes/origin/finalTask
git checkout finalTask
```

2. Paste this command into the console:

```
chmod +x install_script.sh && . install_script.sh
```

3. Use for run app:
```
docker-compose run app python -m rss_reader_ft "https://news.yahoo.com/rss" --limit 2 --colorize --to-html --to-pdf --verbose
```
4. If you want to see the database, then open a browser and paste the URL ( http://localhost:8081/db/News_feed/feeds )

5. If you want to get and view the HTML or PDF file, execute the following commands:
```
docker ps -a
```
You will see the following:
```
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f2091f9472f4 pythonhomework_app "python -m rss_reade…" 2 minutes ago Exited (0) About a minute ago pythonhomework_app_run_4b117e008e87
9036216a4c28 mongo "docker-entrypoint.s…" 6 minutes ago Up 6 minutes 0.0.0.0:27017->27017/tcp pythonhomework_mongo_1
4fc0cef77ca2 mongo-express "tini -- /docker-ent…" 6 minutes ago Up 6 minutes 0.0.0.0:8081->8081/tcp pythonhomework_mongo-express_1
b6288a095558 python "/bin/bash" 21 minutes ago Up 21 minutes interesting_chatterjee

```
Сopy the name of the last running container and paste as in the *example*
```
template: docker export <NAME> > latest.tar

example: docker export pythonhomework_app_run_4b117e008e87 > latest.tar
```
And we get file:
```
tar -xf latest.tar code/News_feed.html

```
or
```

tar -xf latest.tar code/News_feed.pdf
```
Go to folder /code

## Distribution
Utility is wrapped into package named rss_reader_ft. Additionally this package exports CLI utility named rss-reader.

## Caching
The RSS news are stored in a local storage while reading.

## Format converter
You should implement the conversion of news in at least two of the suggested format: .html, .pdf

## Output colorization
You should add new optional argument --colorize, that will print the result of the utility in colorized mode
32 changes: 32 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3.1'

services:
mongo:
image: mongo
hostname: mongo
ports:
- 27017:27017
depends_on:
- mongo-express

app:
tty: true
container_name: rss_reader
stdin_open: true
depends_on:
- mongo
build:
context: .
dockerfile: Dockerfile
ports:
- 3000:3000
links:
- mongo:mongodb
environment:
- MONGO_URL=mongodb://mongo:27017/

mongo-express:
image: mongo-express
restart: always
ports:
- 8081:8081
21 changes: 21 additions & 0 deletions install_script.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

apt-get update && \
apt-get -y install apt-transport-https \
ca-certificates \
curl \
gnupg2 \
software-properties-common && \
curl -fsSL https://download.docker.com/linux/$(. /etc/os-release; echo "$ID")/gpg > /tmp/dkey; apt-key add /tmp/dkey && \
add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/$(. /etc/os-release; echo "$ID") \
$(lsb_release -cs) \
stable" && \
apt-get update && \
apt-get -y install docker-ce

sudo curl -L https://github.com/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose

docker-compose build

126 changes: 126 additions & 0 deletions json_schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"type": "object",
"title": "The Root Schema",
"required": [
"Feed",
"Url",
"News"
],
"properties": {
"Feed": {
"$id": "#/properties/Feed",
"type": "string",
"title": "The Feed Schema",
"default": "",
"examples": [
"Yahoo News - Latest News & Headlines"
],
"pattern": "^(.*)$"
},
"Url": {
"$id": "#/properties/Url",
"type": "string",
"title": "The Url Schema",
"default": "",
"examples": [
"http://rss.news.yahoo.com/rss/"
],
"pattern": "^(.*)$"
},
"News": {
"$id": "#/properties/News",
"type": "array",
"title": "The News Schema",
"items": {
"$id": "#/properties/News/items",
"type": "object",
"title": "The Items Schema",
"required": [
"Title",
"Date",
"Link",
"Description",
"Links"
],
"properties": {
"Title": {
"$id": "#/properties/News/items/properties/Title",
"type": "string",
"title": "The Title Schema",
"default": "",
"examples": [
"House Democrat warns Trump could be reelected despite impeachment inquiry"
],
"pattern": "^(.*)$"
},
"Date": {
"$id": "#/properties/News/items/properties/Date",
"type": "string",
"title": "The Date Schema",
"default": "",
"examples": [
"Fri, 15 Nov 2019 18:07:20 -0500"
],
"pattern": "^(.*)$"
},
"Link": {
"$id": "#/properties/News/items/properties/Link",
"type": "string",
"title": "The Link Schema",
"default": "",
"examples": [
"https://news.yahoo.com/house-democrat-warns-trump-could-be-reelected-despite-impeachment-inquiry-230720070.html"
],
"pattern": "^(.*)$"
},
"Description": {
"$id": "#/properties/News/items/properties/Description",
"type": "string",
"title": "The Description Schema",
"default": "",
"examples": [
"Michigan Democrat Debbie Dingell thinks Trump could win reelection in 2020."
],
"pattern": "^(.*)$"
},
"Links": {
"$id": "#/properties/News/items/properties/Links",
"type": "object",
"title": "The Links Schema",
"required": [
"Source_link",
"Img_links"
],
"properties": {
"Source_link": {
"$id": "#/properties/News/items/properties/Links/properties/Source_link",
"type": "string",
"title": "The Source_link Schema",
"default": "",
"examples": [
"https://news.yahoo.com/house-democrat-warns-trump-could-be-reelected-despite-impeachment-inquiry-230720070.html"
],
"pattern": "^(.*)$"
},
"Img_links": {
"$id": "#/properties/News/items/properties/Links/properties/Img_links",
"type": "array",
"title": "The Img_links Schema",
"items": {
"$id": "#/properties/News/items/properties/Links/properties/Img_links/items",
"type": "string",
"title": "The Items Schema",
"default": "",
"examples": [
"http://l.yimg.com/uu/api/res/1.2/xLjRXbrMf4Uu4liSopZAig--/YXBwaWQ9eXRhY2h5b247aD04Njt3PTEzMDs-/https://media-mbst-pub-ue1.s3.amazonaws.com/creatr-uploaded-images/2019-11/68be2920-07fb-11ea-baff-2733831db38e"
],
"pattern": "^(.*)$"
}
}
}
}
}
}
}
}
}
6 changes: 6 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
feedparser==5.2.1
bs4==0.0.1
pymongo==3.9.0
colored==1.4.0
reportlab==3.5.32
requests==2.22.0
3 changes: 3 additions & 0 deletions rss_reader_ft/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
"""Сonnected modules"""
__all__ = ['app', 'conversion', 'rss', 'db', ]
10 changes: 10 additions & 0 deletions rss_reader_ft/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
"""Entry point for package"""
from rss_reader_ft import rss_reader


def main():
rss_reader.main()


if __name__ == "__main__":
main()
Empty file added rss_reader_ft/app/__init__.py
Empty file.
Loading