forked from Manis99803/Emotion_Analysis
-
Notifications
You must be signed in to change notification settings - Fork 1
/
code.py
63 lines (48 loc) · 1.54 KB
/
code.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
import urllib.request
import string
from datetime import datetime
fp = open("twe.txt", "w+")
twi="https://twitter.com/manish99803"
page=urllib.request.urlopen(twi)
from bs4 import BeautifulSoup
soup=BeautifulSoup(page,"lxml")
k=0
l=[]
n=[]
h=soup.findAll('div',attrs={"class" :"content"})
for sup in h:
k=k+1
time=sup.find('div',{"class":"stream-item-header"})
time1=time.find('a',attrs={"class" :"tweet-timestamp js-permalink js-nav js-tooltip"})
#hola= datetime.strptime(time1['title'],'%I:%M %p - %d %b %Y')
hola= datetime.strptime(time1['title'],'%I:%M %p - %d %b %Y')
hola=str(hola)
m=hola[0:10]
if m not in n:
n.append(m)
fp.write("$$$")
fp.write(m)
fp.write('\n')
a=sup.find('p',attrs={"class" :"TweetTextSize TweetTextSize--normal js-tweet-text tweet-text"})
#if(a.string!=None):
# print("\n")
hashtag=a.find('b')
if(a.find(text=True)!=None):
fp.write("\n"+a.find(text=True))
fp.write("\n")
#if(hashtag!=None):
# fp.write(str(hashtag).strip("<b/>"))
ar=a.findAll('img',{"title":True})
for emoji in ar:
if(emoji!=None):
emoji=str(emoji)
emoji=emoji.split("title=")
k=len(emoji)
emo=emoji[k-1].strip("/>")
emo=emo[1:len(emo)-1]
if emo not in l:
l.append(emo)
fp.write(emo)
fp.write("\n")
#print( str(k)+" Tweets present")
fp.close()