cleaning some code (from MR #9)

This commit is contained in:
Carl Chenet 2017-07-31 15:58:30 +02:00
parent 67b7e72507
commit 37ee1e5a67
6 changed files with 27 additions and 29 deletions

View file

@ -17,7 +17,7 @@
# Remove duplicates from the final string before sending the tweet
'''Remove duplicates from the final string before sending the tweet'''
class RemoveDuplicates(object):
class RemoveDuplicates:
'''Remove duplicates from the final string before sending the tweet'''
def __init__(self, tweet):
'''Constructor of RemoveDuplicates class'''
@ -32,12 +32,12 @@ class RemoveDuplicates(object):
if element != ' ' and (element.startswith('http://') or element.startswith('https://')):
newlink = True
# if we already found this link, increment the counter
for i,_ in enumerate(links):
for i, _ in enumerate(links):
if links[i]['link'] == element:
newlink = False
links[i]['count'] += 1
if newlink:
links.append({'link': element, 'count': 1})
links.append({'link': element, 'count': 1})
# remove duplicates
validatedlinks = []
for i in range(len(links)):
@ -45,14 +45,14 @@ class RemoveDuplicates(object):
validatedlinks.append(links[i])
wildcard = 'FEED2TOOTWILDCARD'
for element in validatedlinks:
for i in range(element['count']):
for i in range(element['count']):
# needed for not inversing the order of links if it is a duplicate
# and the second link is not one
if i == 0:
self.tweet = self.tweet.replace(element['link'], wildcard, 1 )
self.tweet = self.tweet.replace(element['link'], wildcard, 1)
else:
self.tweet = self.tweet.replace(element['link'], '', 1)
# finally
# finally
self.tweet = self.tweet.replace(wildcard, element['link'], 1)
# remove all 2xspaces
self.tweet = self.tweet.replace(' ', ' ')