@mat1/

Epic Clickbait Title Generator

Python

No description

fork
loading
Files
  • main.py
  • altitles.txt
  • mainTitle.txt
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import requests
from bs4 import BeautifulSoup
import markovify
import time
url = "https://www.youtube.com/user/pewdiepie/videos"
# url = str(input("YouTube Video Section URL, note-should have /videos at the end: "))
user_agent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.47 Safari/537.36'
headers = {'User-Agent': user_agent}
page = requests.get(url, headers)
print(page)
soup = BeautifulSoup(page.content, 'html.parser')
allTitleDivs = soup.find_all("h3", "yt-lockup-title")
markovString = ""
open("mainTitle.txt", "w").close()
myFile = open("mainTitle.txt", 'a+')
i=0
while(True):
    markovString = allTitleDivs[i].find('a').get_text()
    myFile.write(markovString + "\n")
    if(i >= len(allTitleDivs)-1):
        break
    else:
        i = i + 1
        pass

myFile.close()

with open("mainTitle.txt") as f:
    text = f.read()

# Build the model.

text_model = markovify.NewlineText(text, state_size=1)
#Make the title
while(True):
    theSentence = text_model.make_sentence(max_overlap_ratio=96) #HIGHER for more random sentences
    #print(theSentence)
    if(theSentence == None):
        pass
    else:
        print(theSentence)
        time.sleep(2)
        pass