Skip to content

Commit

Permalink
added threading for speedUP
Browse files Browse the repository at this point in the history
  • Loading branch information
rs9899 committed Jul 27, 2020
1 parent 72ca5a1 commit 30ae2d8
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import random
import time
import concurrent.futures

class Episode:
def __init__(self , seasonNum , episodeNum, Name, Description):
Expand Down Expand Up @@ -62,17 +63,21 @@ def printShort(self):


### List pf episodes
epList = []
def parallelFun(urlEp):
p = requests.get(urlEp)
s = BeautifulSoup(p.text, 'html.parser')
Titl = [elem.select('a')[0]['title'].strip() for elem in s.find('div' , class_ = 'eplist').select('strong') ]
desc = [elem.text.strip() for elem in s.find('div' , class_ = 'eplist').findAll('div' , class_ = 'item_description')]
return (Titl , desc)
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [executor.submit(parallelFun, imdbShow + 'episodes?season='+str(sesn+1)) for sesn in range(maxSeason)]
res = [f.result() for f in futures]
epList = []
for sesn in range(maxSeason):
p = requests.get(imdbShow + 'episodes?season='+str(sesn+1))
s = BeautifulSoup(p.text, 'html.parser')
Titl = [elem.select('a')[0]['title'].strip() for elem in s.find('div' , class_ = 'eplist').select('strong') ]
desc = [elem.text.strip() for elem in s.find('div' , class_ = 'eplist').findAll('div' , class_ = 'item_description')]
Titl , desc = res[sesn]
for i in range(len(Titl)):
epList.append(Episode(sesn+1, i+1 , Titl[i] , desc[i] ))



### Random picker
TotalChoice = len(epList)
randEpisode = random.randint(1,TotalChoice)
Expand Down

0 comments on commit 30ae2d8

Please sign in to comment.