-
Notifications
You must be signed in to change notification settings - Fork 0
/
actor_royale.py
53 lines (38 loc) · 1.17 KB
/
actor_royale.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
45
46
47
48
49
50
51
52
53
import requests
import bs4
import re
import random
page = 1
url = 'https://www.imdb.com/list/ls002984722/?page={:d}'
names = []
# Do while we are still on a valid page
while True:
# Grab and parse page
print ('Dealing with page {:d}...'.format(page))
r = requests.get(url.format(page))
soup = bs4.BeautifulSoup(r.text, 'lxml')
dirty_list = soup.findAll('a', href=re.compile('ref_=nmls_hd'))
# If this is no longer part of the main list, break out of loop
if len(dirty_list) == 0:
break
# Add names to full list
for name in dirty_list:
names.append(name.text[1:-1]) #remove space in beginning and \n at end
# Increment page number
page += 1
print(names)
# Select 32 random names
random_samples = random.sample(range(len(names)),32)
bracket_names = []
for sample in random_samples:
bracket_names.append(names[sample])
print(bracket_names)
# Create bracket with names
from PIL import Image, ImageDraw
img = Image.new('RGB', (640,480), color='white')
draw = ImageDraw.Draw(img)
current_y = 0
for name in bracket_names:
draw.text((0,current_y),name,(0,0,0))
current_y = current_y + 20
img.save('newimage.png')