forked from DhananjayPurohit/ISO-12-E1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
recommendation.py
57 lines (51 loc) · 2.27 KB
/
recommendation.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
54
55
56
57
from pytrends.request import TrendReq
from youtube_search import YoutubeSearch as ys
import wikipediaapi
keyword = ['java']
class Trends():
def __init__(self, keyword):
self.keyword = keyword
self.pyt = TrendReq(hl='en-US', tz=360,timeout=(10,25), retries=2, backoff_factor=0.1)
self.web = self.pyt.get_historical_interest(self.keyword, year_start=2018,
month_start=1, day_start=1, hour_start=0, cat=0,
geo='', gprop='', sleep=0)
self.you = self.pyt.get_historical_interest(self.keyword, year_start=2018,
month_start=1, day_start=1, hour_start=0, cat=0,
geo='', gprop='youtube', sleep=0)
self.pref()
def pref(self):
if self.web.mean()[self.keyword[0]] > self.you.mean()[self.keyword[0]]:
self.preference_video = False
else:
self.preference_video = True
return self.preference_video
def get_content(self):
if self.preference_video:
print("Youtube Video")
self.youtube_link = ys(self.keyword[0], max_results=5).to_json()
self.link = eval(self.youtube_link)['videos'][0]['link']
return "http://youtube.com"+self.link
else:
print("Text Content")
self.wiki = wikipediaapi.Wikipedia('en')
if self.wiki.page(self.keyword[0]).exists():
self.summary = self.wiki.page(self.keyword[0]).summary
else:
self.summary = "No info found !"
return self.summary
class getCONTENT():
def __init__(self, preference, keyword):
self.keyword = keyword
self.preference_video = preference
if self.preference_video:
print("Youtube Video")
self.youtube_link = ys(self.keyword[0], max_results=5).to_json()
self.link = eval(self.youtube_link)['videos'][0]['link']
self.summary= "http://youtube.com"+self.link
else:
print("Text Content")
self.wiki = wikipediaapi.Wikipedia('en')
if self.wiki.page(self.keyword[0]).exists():
self.summary = self.wiki.page(self.keyword[0]).summary
else:
self.summary = "No info found !"