Spaces:
Runtime error
Runtime error
CognitiveScience
commited on
Commit
•
a4ec550
1
Parent(s):
b7718a5
Create bcogsphere.py
Browse files- bcogsphere.py +46 -0
bcogsphere.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from bs4 import BeautifulSoup
|
2 |
+
import requests
|
3 |
+
#from python_actr import *
|
4 |
+
#from cogscidighum import *
|
5 |
+
|
6 |
+
|
7 |
+
#class myCelSci(Model):
|
8 |
+
# pass
|
9 |
+
|
10 |
+
def bcf(link): #add source? and for sentsummary: https://huggingface.co/themanas021
|
11 |
+
HEADER = {"User-Agent": 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36'}
|
12 |
+
#link = "https://youtu.be/vQUCSHUlN-k?si=FfIsODGjJDzIHOAS"
|
13 |
+
bcfresponse = requests.get(link) #, headers=HEADER)
|
14 |
+
soup = BeautifulSoup(bcfresponse.text, "html.parser")
|
15 |
+
#print (soup.prettify())
|
16 |
+
|
17 |
+
titleSoupMeta = soup.find("meta", property="og:title")
|
18 |
+
videoTitle = titleSoupMeta["content"] if titleSoupMeta else "NotFound"
|
19 |
+
|
20 |
+
bcfresult = {}
|
21 |
+
bcfresult["views"] = soup.find("meta", itemprop="interactionCount")['content']
|
22 |
+
|
23 |
+
#soup=soup.prettify()
|
24 |
+
#viewSoupMeta = [line for line in soup.split('viewCount') if "views" in line]
|
25 |
+
|
26 |
+
#response2=bcfresult.text[bcfresponse.text.find("viewCount"):].split('"')[2]
|
27 |
+
|
28 |
+
# Store JSON data in API_Data
|
29 |
+
#for key in API_Data:{
|
30 |
+
# print(key,":", API_Data[key])
|
31 |
+
#}
|
32 |
+
#viewSoupMeta=viewSoupMeta[19:25]
|
33 |
+
##videoViews = viewSoupMeta["content"] if titleSoupMeta else "NotFound"
|
34 |
+
'''
|
35 |
+
if soup.find(attrs={"viewCount": "3363"}) == None:
|
36 |
+
viewSoupMeta = "3363" #soup.find(attrs={"class": "watch-view-count"}).text
|
37 |
+
else:
|
38 |
+
viewSoupMeta= soup
|
39 |
+
'''
|
40 |
+
#viewSoupMeta = API_Data #str(response).find("viewCount")
|
41 |
+
|
42 |
+
#celsci1=myCelSci()
|
43 |
+
|
44 |
+
#response3= bcfresponse #celsci1.ax1 #celsci1.fame(300) #checkfame("dd")
|
45 |
+
|
46 |
+
return bcfresult #result #soup.prettify()
|