Skip to content

Instantly share code, notes, and snippets.

@steeve85
Created May 12, 2012 18:32
Show Gist options
  • Save steeve85/2668063 to your computer and use it in GitHub Desktop.
Save steeve85/2668063 to your computer and use it in GitHub Desktop.
Punish twitter account who tweet "crypter" or "cryptage"
#!/usr/bin/env python
import twitter, argparse, time
"""
twicrypter.py
v0.1
Steeve Barbeau
@steevebarbeau
steeve-barbeau.blogspot.com
bit.ly link redirects to http://www.ryfe.fr/2011/08/les-mots-crypter-et-cryptage-n%E2%80%99existent-pas/
"""
class TwiCrypter:
def __init__(self):
self.t = twitter.Api(consumer_key = "XXX",
consumer_secret = "XXX",
access_token_key = "XXX",
access_token_secret = "XXX")
self.offensive_words = ['crypter', 'cryptage']
self.off_tweets = []
self.punishment = "Merci de ne plus utiliser les mots crypter et cryptage, ce n'est pas francais : http://bit.ly/mYeHZH"
self.since_id = 0
def get_offenders(self):
for off_word in self.offensive_words:
res = self.t.GetSearch(term = off_word, lang = 'fr', per_page = '100', since_id = self.since_id)
for i in res:
if i not in self.off_tweets:
self.off_tweets.append(i)
def send_punishment(self):
for i in self.off_tweets:
try:
if i._id > self.since_id:
self.since_id = i._id
self.t.PostUpdate("@%s %s" % (i.user.screen_name, self.punishment), i._id)
print "Replay sent to @%s" % i.user.screen_name
except twitter.TwitterError, e:
print e
if __name__ == "__main__":
t = TwiCrypter()
while True:
t.get_offenders()
t.send_punishment()
time.sleep(3600)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment