Example #1
0
def AutoReplyToTweets(searchText, message):
    tw = twStart.hitTwitter()

    targetedTweets, totalTweetCount = SearchTimeline(tw, searchText)

    # jsDump = json.dumps(targetedTweets, indent=4, sort_keys=True)
    # print(jsDump)

    fileName = twStart.DATA_FOLDER + "/AutoRepliedTweets_" + TODAY_FORMATTED + ".txt"
    fn = open(fileName, "a+")
    fn = open(fileName, "r")
    repliedTweets = fn.read()
    fn = open(fileName, "a+")

    for i in range(1, totalTweetCount):
        if (targetedTweets[i]["tweet_id"] not in repliedTweets):
            fn.write(targetedTweets[i]["tweet_id"] + "\n")
            print("User replied: {0}".format(targetedTweets[i]["user_name"]))
            # TODO: Uncomment the code below to be able to add a reply
            # AddReplyToTweet(tw, targetedTweets[i]["tweet_id"], message):
    print("All done! Happy tweeting :)\n")

    fn.close()

    return
Example #2
0
def blockRetweeters(TweetId, IsSilent):
    activeCursor = -1

    fileName = twStart.DATA_FOLDER + "/RTBlocked_" + TODAY_FORMATTED + ".txt"
    if (IN_DEBUG_MODE):
        fn = open(fileName, "w+")

    print("{:25s}{:25s}".format("User Id", "User Name"))
    print("-" * 100)

    if (IN_DEBUG_MODE):
        fn.write("{0}{1}".format("User Id", "User Name") + "\n")

    tw = twStart.hitTwitter()

    while activeCursor != 0:

        f = tw.statuses.retweeters.ids(cursor=activeCursor,
                                       count=100,
                                       _id=TweetId,
                                       stringify_ids=True)

        userIds = ",".join(f["ids"])
        users = tw.users.lookup(user_id=userIds)

        i = 0

        for usrId in f["ids"]:
            color = Fore.RED if usrId in twStart.WHITE_LIST_USERS else Fore.GREEN
            print(Style.BRIGHT + color +
                  "{:25s} {:25s}".format(usrId, users[i]["screen_name"]))
            if (IN_DEBUG_MODE):
                fn.write("{0}\t{1}".format(usrId, users[i]["screen_name"]) +
                         "\n")
            i += 1
        activeCursor = f["next_cursor"]

    if (IN_DEBUG_MODE):
        fn.close()

    print("-" * 96)
    print(_("What do you want to do with all these users (case sensitive)?"))
    remove = input(_("[B]lock / [U]nfollow / [M]ute / [E]xit: "))

    if (IsSilent == False):
        RUsure = input(_("Are you sure? [Y]es / [N]o: "))
    else:
        RUsure = "Y"

    if (RUsure == "Y"):
        for usrId in f["ids"]:
            BUM(tw, usrId, remove)
        print(_("All done! Happy tweeting :) "))
        return

    print(_("Nothing to do here!"))
Example #3
0
def listUsers(userAction, IsSilent):
    activeCursor = -1

    fileName = twStart.DATA_FOLDER + "/undoThanos_" + userAction + "_" + TODAY_FORMATTED + ".txt"
    if (IN_DEBUG_MODE):
        fn = open(fileName, "w+")

    print("{:25s}{:25s}".format("User Id", "User Name"))
    print("-" * 100)

    if (IN_DEBUG_MODE):
        fn.write("{0}{1}".format("User Id", "User Name") + "\n")

    tw = twStart.hitTwitter()

    while activeCursor != 0:
        if (userAction == 'B'):
            f = tw.blocks.ids(cursor=activeCursor, stringify_ids=True)
        elif (userAction == 'M'):
            f = tw.mutes.users.ids(cursor=activeCursor, stringify_ids=True)

        userIds = ",".join(f["ids"])
        users = tw.users.lookup(user_id=userIds)

        i = 0

        for usrId in f["ids"]:
            color = Fore.GREEN if usrId in twStart.BLACK_LIST_USERS else Fore.RED
            print(Style.BRIGHT + color +
                  "{:25s} {:25s}".format(usrId, users[i]["screen_name"]))
            if (IN_DEBUG_MODE):
                fn.write("{0}\t{1}".format(usrId, users[i]["screen_name"]) +
                         "\n")
            i += 1
        activeCursor = f["next_cursor"]

    if (IN_DEBUG_MODE):
        fn.close()

    print("-" * 96)

    if (IsSilent == False):
        RUsure = input("These users will be un" +
                       ("blocked" if userAction == 'B' else "muted") +
                       ". Are you sure? [Y]es / [N]o: ")
    else:
        RUsure = "Y"

    if (RUsure == "Y"):
        for usrId in f["ids"]:
            undoBlockMute(tw, usrId, userAction)
        print("All done! Happy tweeting :) ")
        return

    print("Nothing to do here!")
Example #4
0
def destroyHalfPercent(IsSilent):
    activeCursor = -1
    maxArraySize = 100
    usersToBeDestroyed = {1: {}}
    unluckyGuysCount = 0

    fileName = twStart.DATA_FOLDER + "/twThanosDestroyed_" + TODAY_FORMATTED + ".txt"
    if (IN_DEBUG_MODE):
        fn = open(fileName, "w+")

    print("{:25s}{:25s}{:25s}".format("User Id", "User Name", "Action"))
    print("-" * 100)

    if (IN_DEBUG_MODE):
        fn.write("{0}{1}{2}\n".format("User Id", "User Name", "Action"))

    tw = twStart.hitTwitter()

    allUserIds = []

    while activeCursor != 0:
        f = tw.friends.ids(cursor=activeCursor, count=2048, stringify_ids=True)
        allUserIds += f["ids"]
        activeCursor = f["next_cursor"]

    halfOfTheUsers = len(allUserIds) // 2

    sRandom = random.SystemRandom()
    selectedUsers = sRandom.choices(allUserIds, k=halfOfTheUsers)

    modulus, fixed = twStart.splitArray(halfOfTheUsers, maxArraySize)

    for x in range(fixed):
        usersToBeDestroyed, unluckyGuysCount = listUnluckyFriends(
            tw, selectedUsers, (x * maxArraySize),
            (x * maxArraySize + maxArraySize), unluckyGuysCount,
            usersToBeDestroyed)
    usersToBeDestroyed, unluckyGuysCount = listUnluckyFriends(
        tw, selectedUsers, (halfOfTheUsers - modulus),
        (halfOfTheUsers + modulus), unluckyGuysCount, usersToBeDestroyed)

    for i in range(1, unluckyGuysCount):
        color = Fore.RED if usersToBeDestroyed[i][
            "user_id"] in twStart.WHITE_LIST_USERS else Fore.GREEN
        print(Style.BRIGHT + color + "{:25s} {:25s} {:25s}".format(
            usersToBeDestroyed[i]["user_id"], usersToBeDestroyed[i]
            ["user_name"], usersToBeDestroyed[i]["action"]))
        if (IN_DEBUG_MODE):
            fn.write("{0}\t{1}\t{2}".format(
                usersToBeDestroyed[i]["user_id"], usersToBeDestroyed[i]
                ["user_name"], usersToBeDestroyed[i]["action"]) + "\n")

    if (IN_DEBUG_MODE):
        fn.close()

    print("-" * 96)

    if (IsSilent == False):
        RUsure = input("Are you sure? [Y]es / [N]o: ")
    else:
        RUsure = "Y"

    if (RUsure == "Y"):
        for i in range(1, unluckyGuysCount):
            twStart.BUM(tw, usersToBeDestroyed[i]["user_name"],
                        usersToBeDestroyed[i]["user_id"],
                        usersToBeDestroyed[i]["action"])
        print("All done! Happy tweeting :) ")
        return

    print("Nothing to do here!")
Example #5
0
activeCursor = -1

myStats = {
    "followers": 0,
    "following": 0,
    "muted_me": 0,
    "i_ve_muted": 0,
    "i_follow_but_they_dont": 0,
    "they_follow_but_i_dont": 0,
    "we_both_follow_each_other": 0,
    "mysterious_followers_that_i_dont_follow": 0
}

# myStats["followers"] += 1
# print("{:25s} {:25s} {:25s} {:25s} {:25s} {:25s} {:25s} {:25s}".format("Name", "Connections", "followin", "requested", "followed_by", "none", "blocking", "muting")
# print("---------------------------------------------------------------------------------------------------------------------------------------------")

print("{:25s} {:25s} {:25s} {:25s} {:25s} {:25s}".format(
    "Name", "Muted", "IFollow", "TheyFollow", "Both", "Hidden"))
print(
    "---------------------------------------------------------------------------------------------------------------------------------------------"
)

# friendShips = f = tw.friendships.lookup(screen_name="tevfik_uyar")
ntw = twStart.hitTwitter()
follower_ids = ntw.followers.ids(screen_name="mirmirik")
all_ids = follower_ids["ids"]

print(all_ids[:100])
Example #6
0
def blockRetweeters(TweetId, IsSilent):
    activeCursor = -1

    fileName = "data/RTBlocked_" + TODAY_FORMATTED + ".txt"
    if (IN_DEBUG_MODE):
        fn = open(fileName, "w+")

    print("{:25s}{:25s}".format("User Id", "User Name"))
    print(
        "------------------------------------------------------------------------------------------------"
    )

    if (IN_DEBUG_MODE):
        fn.write("{0}{1}".format("User Id", "User Name") + "\n")

    tw = twStart.hitTwitter()

    while activeCursor != 0:

        f = tw.statuses.retweeters.ids(cursor=activeCursor,
                                       count=100,
                                       _id=TweetId,
                                       stringify_ids=True)

        userIds = ",".join(f["ids"])
        users = tw.users.lookup(user_id=userIds)

        i = 0

        for usrId in f["ids"]:
            print("{:25s} {:25s}".format(usrId, users[i]["screen_name"]))
            if (IN_DEBUG_MODE):
                fn.write("{0}\t{1}".format(usrId, users[i]["screen_name"]) +
                         "\n")
            i += 1
        activeCursor = f["next_cursor"]
    if (IN_DEBUG_MODE):
        fn.close()
    print(
        "------------------------------------------------------------------------------------------------"
    )
    print("What do you want to do with all these users?")
    remove = input("[B]lock / [U]nfollow / [M]ute / [E]xit: ")

    if (IsSilent == False):
        RUsure = input("Are you sure? [Y]es / [N]o: ")
    else:
        RUsure = "Y"

    if (RUsure == "Y"):
        if (remove == "B"):
            for usrId in f["ids"]:
                print("Blocked: {0}".format(usrId))
                # TODO: Kulanıcı bloklama kodu buraya gelecek
                # Şu kod iş görüyor olmalı: tw.blocks.create(user_id=usrId, skip_status=1, include_entities=False)
            print("All blocked :)")
            return
        if (remove == "M"):
            for usrId in f["ids"]:
                print("Muted: {0}".format(usrId))
                # TODO: Kulanıcıyı sessize alma kodu buraya gelecek
                # Şu kod iş görüyor olmalı: tw.users.mutes(user_id=usrId)
            print("All muted :)")
            return
        if (remove == "U"):
            for usrId in f["ids"]:
                print("Unfollowed: {0}".format(usrId))
                # TODO: Kulanıcı takipten çıkarma kodu buraya gelecek
                # Şu kod iş görüyor olmalı: tw.friendships.destroy(user_id=usrId)
            print("All unfollowed :)")
            return

    print("Nothing to do here!")
Example #7
0
def getTwitterData():
    activeCursor = -1

    fileName = "/follower_" + TODAY_FORMATTED + ".txt" if GET_FOLLOWERS else "/following_" + TODAY_FORMATTED + ".txt"

    fn = open(twStart.DATA_FOLDER + fileName, "w+")

    print("{:10s} {:25s} {:25s} {:25s} {:25s} {:25s} {:25s} {:25s}".format(
        "Index", "Screen Name", "Name", "ID", "Follower-Friend",
        "Last Interaction", "Account Created", "Protected"))
    print("-" * 190)

    fn.write("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}".format(
        "screen_name", "name", "id_str", "followers_count", "friends_count",
        "flwr_frnds", "last_interaction", "acc_created", "protected") + "\n")

    tw = twStart.hitTwitter()

    index = 1

    while activeCursor != 0:

        f = tw.followers.list(cursor=activeCursor,
                              count=500) if GET_FOLLOWERS else tw.friends.list(
                                  cursor=activeCursor, count=200)

        _lastInteraction = ""
        for usr in f["users"]:
            try:
                if (usr["status"]):
                    _lastInteraction = twStart.FormatTwitterDate(
                        usr["status"]["created_at"])
                    _accountCreated = twStart.FormatTwitterDate(
                        usr["created_at"])
            except:  # status alınamıyorsa, kullanıcı "kilitli" hesaba sahiptir.
                _lastInteraction = "Not found"

            try:
                _follower_friend_ratio = usr["followers_count"] / usr[
                    "friends_count"]
            except:
                _follower_friend_ratio = usr["followers_count"]

            print("{:4d} {:25s} {:25s} {:25s} {:6.4f} {:25s} {:25s} {:25s}".
                  format(index, usr["screen_name"], usr["name"], usr["id_str"],
                         _follower_friend_ratio, _lastInteraction,
                         _accountCreated, str(usr["protected"])))

            fn.write("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}".format(
                usr["screen_name"], usr["name"], usr["id_str"],
                usr["followers_count"], usr["friends_count"],
                _follower_friend_ratio, _lastInteraction, _accountCreated,
                str(usr["protected"]) + "\n"))

            index += 1

        activeCursor = f["next_cursor"]
        if IN_DEBUG_MODE:
            with open(twStart.DATA_FOLDER + "/raw_data.json", "w+") as fl:
                jsDump = json.dumps(f, indent=4, sort_keys=False)
                fl.write(jsDump)
    fn.close()
Example #8
0
def removeFriend():
    activeCursor = -1

    tw = twStart.hitTwitter()

    removeFriendCount = 0
    removeableUsers = {1:{}}

    while activeCursor != 0:

        f = tw.friends.list(cursor=activeCursor, count=200)

        lastInteraction = ""

        for usr in f["users"]:
            try: 
                if (usr["status"]):
                    lastInteraction = twStart.FormatTwitterDate(usr["status"]["created_at"], 'D')
                    accountCreated = twStart.FormatTwitterDate(usr["created_at"], 'D')

                    r = relativedelta.relativedelta(datetime.today(), lastInteraction)

                    accountCreation_Rule = (accountCreated.year == rules['ACCOUNT_CREATED_YEAR'] 
                            and accountCreated.month == rules['ACCOUNT_CREATED_MONTH'])
                    
                    lastInteraction_Rule = (r.months > rules['LAST_STATUS_UPDATE_IN_MONTHS'])

                    userIsNotInWhitelist = usr["id_str"] not in twStart.WHITE_LIST_USERS

                    if (
                        (accountCreation_Rule or lastInteraction_Rule) and userIsNotInWhitelist
                        ):
                        removeFriendCount += 1
                        lastInteractionJSON = twStart.FormatTwitterDate(usr["status"]["created_at"], 'S')
                        accountCreatedJSON = twStart.FormatTwitterDate(usr["created_at"], 'S')
                        removeableUsers[removeFriendCount] = {}
                        removeableUsers[removeFriendCount]["user_id"] = usr["id_str"]
                        removeableUsers[removeFriendCount]["user_name"] = usr["name"]
                        removeableUsers[removeFriendCount]["account_created"] = accountCreatedJSON
                        removeableUsers[removeFriendCount]["last_interaction"] = lastInteractionJSON
                        if lastInteraction_Rule:
                            removeableUsers[removeFriendCount]["remove_reason"] = "Last interaction date is too old. (" + lastInteractionJSON + ")"
                        elif accountCreation_Rule:
                            removeableUsers[removeFriendCount]["remove_reason"] = "Account is too young. (" + accountCreatedJSON + ")"
                        
            except:
                lastInteraction = "Not found"

        activeCursor = f["next_cursor"]

    ''' Test commands '''
    # pprint.pprint(removeableUsers)
    # jsDump = json.dumps(removeableUsers, indent=4, sort_keys=True)
    # print(jsDump)

    print("{:10s} {:25s} {:35s}".format("Index", "User Name", "Reason"))
    print("-" * 96)

    for i in range(1, removeFriendCount):
        print("{:10d} {:25s} {:35s}".format(i, removeableUsers[i]["user_name"], removeableUsers[i]["remove_reason"]))

    print("="*96 + "\n\n")

    print("These users will be UNFOLLOWED. Are you sure? (case sensitive)?")
    RUsure = input("Are you sure? [Y]es / [N]o: ")

    if(RUsure=="Y"):
        for i in range(1, removeFriendCount):
            print("Unfollowed: {0}".format(removeableUsers[i]["user_name"]))
            # TODO: Kulanıcı takipten çıkarma kodu açılmalı
            # İşler hale gelmesi için aşağıdaki satırı açmalısınız
            # tw.friendships.destroy(user_id=removeableUsers[i]["user_id"])
        print ("All done! Happy tweeting :)\n")
        return

    print("Nothing to do here! Go on.\n")
Example #9
0
def getTwitterData():
    activeCursor = -1

    fileName = "data/follower_" + TODAY_FORMATTED + ".txt" if GET_FOLLOWERS else "data/following_" + TODAY_FORMATTED + ".txt"

    fl = open("data/raw_data.json", "w+")
    fn = open(fileName, "w+")

    print("{:25s} {:25s} {:25s} {:25s} {:25s} {:25s} {:25s}".format(
        "Screen Name", "Name", "ID", "Follower-Friend", "Last Interaction",
        "Account Created", "Protected"))
    print(
        "---------------------------------------------------------------------------------------------------------------------------------------------"
    )

    fn.write("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}".format(
        "screen_name", "name", "id_str", "followers_count", "friends_count",
        "flwr_frnds", "last_interaction", "acc_created", "protected") + "\n")

    tw = twStart.hitTwitter()

    while activeCursor != 0:

        f = tw.followers.list(cursor=activeCursor,
                              count=500) if GET_FOLLOWERS else tw.friends.list(
                                  cursor=activeCursor, count=200)

        _lastInteraction = ""
        for usr in f["users"]:
            try:
                if (usr["status"]):
                    # status alınamıyorsa, kullanıcı "kilitli" hesaba sahiptir.
                    # TW standart tarih formatı: Sat Aug 11 12:51:00 +0000 2018
                    _tempDate = usr["status"]["created_at"]
                    lastStatusDate = datetime.strptime(
                        _tempDate, '%a %b %d %H:%M:%S %z %Y')
                    _lastInteraction = "{2}{1}{0}".format(
                        str(lastStatusDate.day).zfill(2),
                        str(lastStatusDate.month).zfill(2),
                        str(lastStatusDate.year))

                    # En son 2019'dan önce tweet atmışları takipten çıkaralım.
                    if (lastStatusDate.year < 2019):
                        tw.friendships.destroy(user_id=usr["id_str"])

                    dtObj = datetime.strptime(usr["created_at"],
                                              '%a %b %d %H:%M:%S %z %Y')
                    _accountCreated = "{2}{1}{0}".format(
                        str(dtObj.day).zfill(2),
                        str(dtObj.month).zfill(2), str(dtObj.year))

            except KeyError as ke:
                _lastInteraction = "Not found"

            try:
                _follower_friend_ratio = usr["followers_count"] / usr[
                    "friends_count"]
            except:
                _follower_friend_ratio = usr["followers_count"]

            print("{:25s} {:25s} {:25s} {:25s} {:25s} {:25s} {:25s}".format(
                usr["screen_name"], usr["name"], usr["id_str"],
                str(_follower_friend_ratio), _lastInteraction, _accountCreated,
                str(usr["protected"])))

            fn.write("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}".format(
                usr["screen_name"], usr["name"], usr["id_str"],
                usr["followers_count"], usr["friends_count"],
                _follower_friend_ratio, _lastInteraction, _accountCreated,
                str(usr["protected"]) + "\n"))

        activeCursor = f["next_cursor"]
        if IN_DEBUG_MODE:
            jsDump = json.dumps(f, indent=4, sort_keys=False)
            fl.write(jsDump)

    fl.close()
    fn.close()
Example #10
0
def unfollowUsersFriends(UserName, IsSilent):
    activeCursor = -1

    fileName = twStart.DATA_FOLDER + "/unFollowUsersFriends_" + TODAY_FORMATTED + ".txt"
    if(IN_DEBUG_MODE):
        fn = open(fileName, "w+")

    tw = twStart.hitTwitter()

    nemesisFriends = []
    myFriends = []

    while activeCursor != 0:
        f = tw.followers.ids(cursor=activeCursor, count=2048, stringify_ids=True, screen_name=UserName)
        nemesisFriends += f["ids"]
        activeCursor = f["next_cursor"]
    
    print("Nemesis's friends count: {}".format(len(nemesisFriends)))

    activeCursor = -1
    while activeCursor != 0:
        f = tw.friends.ids(cursor=activeCursor, count=2048, stringify_ids=True)
        myFriends += f["ids"]
        activeCursor = f["next_cursor"]

    print("My friends count: {}".format(len(myFriends)))

    commonFriendsList = list(set(nemesisFriends) & set(myFriends))
    print("Common friends count: {}".format(len(commonFriendsList)))

    print(Style.BRIGHT + Fore.GREEN + "{:25s}{:25s}".format("User Id", "User Name"))
    print(Style.BRIGHT + Fore.GREEN + "-" * 70)

    if(IN_DEBUG_MODE):
        fn.write("{0}{1}\n".format("User Id", "User Name"))

    userIds = ",".join(commonFriendsList)
    users = tw.users.lookup(user_id=userIds)

    for user in users:
        if user["id_str"] in twStart.WHITE_LIST_USERS:
            # twStart.sendMessage(tw, user["id_str"], "WUT?")
            color = Fore.RED  
        else:
            Fore.GREEN
        print(color + "{:25s} {:25s}".format(user["id_str"], user["screen_name"]))
        if(IN_DEBUG_MODE):
            fn.write("{0}\t{1}".format(user["id_str"], user["screen_name"]) + "\n")

    if(IN_DEBUG_MODE):
        fn.close()

    print(Style.BRIGHT + Fore.GREEN + "-"*96)
    
    if (IsSilent==False):
        RUsure = input(Style.BRIGHT + Fore.RED + "Are you sure? [Y]es / [N]o: ")
        print(Style.BRIGHT + Fore.GREEN + "-"*96)
    else:
        RUsure = "Y"

    if(RUsure=="Y"):
        for user in users:
            twStart.BUM(tw, user["screen_name"], user["id_str"], "U")
        print ("All done! Happy tweeting :) ")
        return

    print("Nothing to do here!")