-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfood.py
66 lines (60 loc) · 1.65 KB
/
food.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
58
59
60
61
62
63
64
65
66
import urllib.request as url
import bs4 as bs
import requests
import random
import re
def recipe(food):
words=food.split(" ")
new=""
for i in words:
new+=i+'+'
fin='https://www.youtube.com/results?search_query='+new+'recipe'
html = url.urlopen(fin)
video_ids = re.findall(r"watch\?v=(\S{11})", html.read().decode())
select=video_ids[0]
link="https://www.youtube.com/watch?v="+select
return link
food1='https://www.jetsetter.com/magazine/20-best-comfort-foods-in-the-us/'
sourcef1= url.urlopen(food1).read()
soupf1=bs.BeautifulSoup(sourcef1,'lxml')
comfort=[]
elf1=soupf1.find_all("h2",{"class":"heading"})
for i in elf1:
a=i.contents[0].rstrip('\n\t')
b=a.lstrip('\n\t')
comfort.append(b)
veg='https://www.thespruceeats.com/vegetarian-comfort-food-recipes-5086173'
sourcev1= requests.get(veg).text
soupv1=bs.BeautifulSoup(sourcev1,'lxml')
elv1=soupv1.find_all("h2")
linkv1=[]
vegfood=[]
for i in elv1:
tag=i.find_all("a")
linkv1.append(tag[0]['href'])
vegfood.append(tag[0].contents[0])
veg2="https://thestrongtraveller.com/2020/07/20/12-indian-comfort-foods-that-can-easily-destress-you-after-a-busy-day/"
sourcev2= requests.get(veg2).text
soupv2=bs.BeautifulSoup(sourcev2,'lxml')
elv2=soupv2.find_all("h2")
indian=[]
for i in elv2[:12]:
b=i.find_all("b")
name=b[0].contents[0]
indian.append(name[3:])
def picknvfood():
food=random.choice(comfort+indian+vegfood)
if food in vegfood:
n=vegfood.index(food)
lk=linkv1[n]
else:
lk=recipe(food)
return food,lk
def pickvegfood():
food=random.choice(indian+vegfood)
if food in vegfood:
n=vegfood.index(food)
lk=linkv1[n]
else:
lk=recipe(food)
return food,lk