So i finally completed the Python 2 course and managed to finish the final project.
Here you can find my code. I would really appreciate some review and ideas to improve it and make it better!!
Here the link to gitHub: https://github.com/AleGuarnieri/Codacademy_python_final_project
import requests from bs4 import BeautifulSoup url = "https://filmsimili.com/film/blow-2001/simili/" code = requests.get(url) plain = code.text soup = BeautifulSoup(plain, "html.parser") number_paragraph = raw_input("Enter the number of stories to retrieve (max 5): ") if int(number_paragraph) > 5: raise (ValueError, "Too many paragraphs!") counter = 0 with open("example.txt", "w") as file: for paragraph in soup.find_all('p'): if counter < int(number_paragraph): file.write(str(paragraph)[3:-4]) file.write("\n") counter += 1 else: break
from markov_python.cc_markov import MarkovChain import fetch_data mc = MarkovChain() mc.add_file('example.txt') result = mc.generate_text(80) result = ' '.join(result) print (result)