-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tweet.py
29 lines (25 loc) · 1.03 KB
/
Tweet.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
class Tweet:
def __init__(self, status):
self.text = status.text
self.truncated = status.truncated
self.id = status.id
self.user = status.user.screen_name
self.cleaned = self.cleaned()
self.oneLine = self.oneLine()
def isAcceptable(self):
return not any(char.isdigit() for char in self.cleaned) and not self.text[0:2] == "RT" and not self.truncated
def cleaned(self):
indexOfAt = self.text.find("@")
indexOfHash = self.text.find("#")
indexOfLink = self.text.find("http")
forcedEnd = max(indexOfHash, indexOfLink)
endIndex = min(forcedEnd, len(self.text)) if forcedEnd > -1 else len(self.text)
startIndex = 0
if indexOfAt > -1:
for i in range(indexOfAt,len(self.text)):
if self.text[i] == " ":
startIndex = i + 1
break
return self.text[startIndex:endIndex].replace("&","&")
def oneLine(self):
return self.cleaned.replace('\n',' ')