Last active
May 24, 2018 20:14
-
-
Save cryptobabel/dc9556e2eb890648f3d3952d04606cfc to your computer and use it in GitHub Desktop.
Help get rid of eth scammers...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import json | |
import tweepy | |
from tweepy.streaming import StreamListener | |
# Get your tokens by adding/creating an app on Twitter for this script | |
# https://iag.me/socialmedia/how-to-create-a-twitter-app-in-8-easy-steps/ | |
ACCESS_TOKEN = '39487530945739047853-asodfalksjasd8asdlasd' | |
ACCESS_TOKEN_SECRET = 'oneFyUkasda099sadlkasldkas0dasdasdlk' | |
CONSUMER_KEY = 'iZasd09asdlasdasd' | |
CONSUMER_SECRET = 'Fasdlkafsad0asdiapsdkaskdasidklasd8adasd' | |
# The problem as I see it boils down to users seeing the handle itself since it | |
# does not have to be unique as the confusing part that leads them to being | |
# scammed. Especially when the bots have matching blue checks/emoji etc. | |
# With that considered we can check that the handle, if similar, belongs to the | |
# user_name or the @<user> and if not block the user as soon as it posts. | |
# I think blocking now moves the replies on same tweet down further to hide, | |
# would have to experiment... | |
# If bots start tweaking handle and that somehow still confuses users we | |
# can add some regex pattern checking on the handle too.... | |
# bots may start replying to other users at that point and yeah... | |
# This isn't perfect, we can rework this entirely tbh.. but I think with this | |
# and the help of some of twitter's 'algo fixes' | |
# it should help to further minimize the scams. | |
# If there's interest we can build it out to look into past tweet etc. | |
# Right now it's set up to listen to replies to your tweets and | |
# zap the scammers | |
auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) | |
auth.set_access_token(ACCESS_TOKEN, ACCESS_TOKEN_SECRET) | |
api = tweepy.API(auth) | |
class StdOutListener( StreamListener ): | |
def __init__(self): | |
self.tweetCount = 0 | |
def on_connect(self): | |
print("Connection established!!") | |
def on_disconnect( self, notice ): | |
print("Connection lost!! : ", notice) | |
def on_data(self, status): | |
# print("Entered on_data()") | |
print(status) | |
if "in_reply_to_screen_name" in status: | |
data = json.loads(status) | |
if data['in_reply_to_screen_name']: | |
print('REPLY: ', status) | |
validate_reply(data) | |
return True | |
def on_direct_message(self, status): | |
print("Entered on_direct_message()") | |
return True | |
def on_error(self, status): | |
print(status) | |
def block_user(replying_user_screenname): | |
# Do whatever else you'd like with this pos | |
api.create_block(replying_user_screenname) | |
def validate_reply(data): | |
# Update for stricter validation... | |
scammer_handle = data['user']['name'] | |
scammer_screen_name = data['user']['screen_name'] | |
if api.me().name in scammer_handle \ | |
and scammer_screen_name != api.me().screen_name: | |
# It's a scammer, no one gets to user our handle! | |
block_user(scammer_screen_name) | |
def main(): | |
try: | |
print('Monitoring ethscams for: {}'.format(api.me().name)) | |
stream = tweepy.Stream(auth, StdOutListener()) | |
stream.userstream() | |
except BaseException as e: | |
print("Error in main()", e) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment