Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
6512975
Version 2.1: Complete version of first and second Iterations
karimoff96 Jun 16, 2022
87f9816
Adding requirements.txt file
karimoff96 Jun 16, 2022
63f97dd
Full completion of III iteration. Added new optional argument --date …
karimoff96 Jun 22, 2022
ec048ae
Setting up the setuptools` path and adding some other features
karimoff96 Jun 22, 2022
296d1a3
Completing verbose and json versions '--date' option
karimoff96 Jun 23, 2022
b0907b7
Final version of 3rd Iteration(version 3.3)
karimoff96 Jun 24, 2022
c6cf6d9
Base html file for further html files creation
karimoff96 Jun 27, 2022
fbe12ba
Convert news to .html format and save it into 'html_convert' director…
karimoff96 Jun 27, 2022
79f9570
Completion first part of 4th Iteration. (convert into html)- version 4.1
karimoff96 Jun 27, 2022
0b0f5d2
--version 4.1
karimoff96 Jun 27, 2022
c14a92a
Converting specified data into pdf format, works with all other options
karimoff96 Jun 28, 2022
c694bdc
rss_reader version 4.2
karimoff96 Jun 28, 2022
f1cef38
Add README.md
karimoff96 Jun 28, 2022
821324f
Modifying and optimizing html convertion
karimoff96 Jun 28, 2022
7d43e23
Configuration files for project
karimoff96 Jun 29, 2022
cefa12a
MIT License
karimoff96 Jun 29, 2022
dda5ea6
Requirements
karimoff96 Jun 29, 2022
349f91f
Iteration 4, Version 4.3
karimoff96 Jun 29, 2022
32adbff
README.md modification
karimoff96 Jun 29, 2022
5b529b3
Testing project of all 4 Iterations
karimoff96 Jun 29, 2022
ab2899b
Readme.md
karimoff96 Jun 29, 2022
0191ba5
Iteration 4, Version 4.3
karimoff96 Jun 29, 2022
5e1f615
Final test
karimoff96 Jun 29, 2022
834c5df
README.md
karimoff96 Jun 29, 2022
edee3f9
Update README.md
karimoff96 Jun 29, 2022
495fa63
Update README.md
karimoff96 Jun 29, 2022
ef08345
Update README.md
karimoff96 Jun 29, 2022
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
96 changes: 96 additions & 0 deletions HTML_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import os
from json2html import *
from bs4 import BeautifulSoup
import datetime


with open('base.html', 'r', encoding='utf-8') as readfile:
html_file = readfile.read()

soup = BeautifulSoup(html_file, "html.parser")
readfile.close()
def convert_to_html(dataset, date=None):
'''Method of data convertion into html'''
folder = 'html_convert'
if os.path.exists(folder):
pass
else:
os.mkdir(folder)
dir_path = "img_storage"
for data in dataset:
main_div = soup.new_tag('div', **{'class': 'card mb-3 em'})
body_div = soup.new_tag('div', **{'class': 'card-body'})
tag_p = soup.new_tag('p', **{'class': 'card-text'})
body_div.append(tag_p)
for key, value in data.items():
if date:
img_source = "News image_link:"
if key == img_source:
img_tag = soup.new_tag(
"img", **{'class': 'card-img-top'}, src=value, alt="No image link")
main_div.append(img_tag)
else:
# list to store files
res = []
# Iterate directory
for path in os.listdir(dir_path):
# check if current path is a file
if os.path.isfile(os.path.join(dir_path, path)):
res.append(path)
if key == 'News image_link:':
img_name = value.split('/')[-1]
for i in res:
if img_name == i[:-5]:
img_tag = soup.new_tag(
"img", **{'class': 'card-img-top'}, src=f"../{dir_path}/{img_name}.jpeg", alt="No image link")
main_div.append(img_tag)
if key == 'News title:':
title_h5 = soup.new_tag('h5', **{'class': 'card-title'})
title_h5.string = value
body_div.append(title_h5)
if key == "News description:":
p_tag = soup.new_tag('p', **{'class': 'card-text'})
p_tag.string = value
body_div.append(p_tag)
if key == "News link:":
small_tag_link = soup.new_tag(
'a', **{'class': 'text-muted links'}, href=value)
small_tag_link.string = value
tag_p.append(small_tag_link)
tag_p.append(soup.new_tag('br'))
if key == "News date:":
small_tag_date = soup.new_tag(
'span', **{'class': 'text-muted'})
small_tag_date.string = value
tag_p.append(small_tag_date)
tag_p.append(soup.new_tag('br'))
if key == "News source:":
small_tag_source = soup.new_tag(
'a', **{'class': 'text-muted links'}, href=f"{value} <br>")
small_tag_source.string = value
tag_p.append(small_tag_source)
tag_p.append(soup.new_tag('br'))
if key == "News creator:":
small_tag_creator = soup.new_tag(
'small', **{'class': 'text-muted'})
small_tag_creator.string = value
tag_p.append(small_tag_creator)
if key == "News enclosure:":
small_tag_enclosure = soup.new_tag(
'small', **{'class': 'text-muted'}, href=value)
small_tag_enclosure.string = value
tag_p.append(small_tag_enclosure)
body_div.append(tag_p)
main_div.append(body_div)
soup.body.div.append(main_div)

if date:
file = datetime.datetime.now().strftime("%Y-%m-%d_%H.%M.%S")+'(offline)'+'.html'
else:
file = datetime.datetime.now().strftime("%Y-%m-%d_%H.%M.%S")+'(online)'+'.html'

with open(f'{folder}/{file}', 'w', encoding='utf-8') as writefile:
writefile.write(str(soup))
writefile.close()
print("\n", f"Your data has been successfully converted into .html and saved in {folder} folder as {file}", "\n")
return 'test'
10 changes: 10 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
MIT License

Copyright (c) 2022 Doniyor Karimov

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
41 changes: 41 additions & 0 deletions PDF_converter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from reportlab.pdfgen import canvas
import os
import textwrap
import datetime


info = "Your data has been successfully converted into .html and saved in 'pdf_convert' directory with 'local datetime' name"
def convert_to_pdf(infoFromJson, date=None):
'''Method of data convertion into html'''
folder = 'pdf_convert'
if os.path.exists(folder):
pass
else:
os.mkdir(folder)
if date:
file = datetime.datetime.now().strftime("%Y-%m-%d_%H.%M.%S")+'(offline)'+'.pdf'
else:
file = datetime.datetime.now().strftime("%Y-%m-%d_%H.%M.%S")+'(online)'+'.pdf'
can = canvas.Canvas(f'PDF_convert/{file}')
dir_path = "img_storage"
for item in infoFromJson:
x = 10
y = 800
for k, v in item.items():
img_source = "News image_link:"
if img_source in item:
img_name= item[img_source].split('/')[-1]
can.drawImage(f"{dir_path}/{img_name}"+'.jpeg', 30, 300, width=250, height=200)
text = f"{k}: {v}"
wrap_text = textwrap.wrap(text, width=100)
can.drawString(x, y, wrap_text[0])
try:
y -= 25
can.drawString(x+50, y, wrap_text[1])
except:
pass
y -= 25
can.showPage()
can.save()
print("\n", info, "\n")
return "test"
Loading