Advertisement
Guest User

Untitled

a guest
May 6th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. #!/usr/bin/python
  2. # -*- coding:Utf-8 -*-
  3.  
  4. import sys
  5.  
  6. import twitter
  7.  
  8. def unfollowator(api, argv):
  9. if (len(argv) < 3) or (len(argv) > 2 and argv[2] != "force"):
  10. print "WARNING this will unfollow all the friends you have who doesn't"\
  11. "follow you !"
  12. print
  13. print 'Write "python twitterscript.py unfollow force" if you know what'\
  14. ' you are doing.\n'
  15. sys.exit(1)
  16.  
  17. if len(argv) <= 3:
  18. stop = 1000
  19. else:
  20. stop = int(argv[3])
  21.  
  22. my_friends = api.GetFriends()
  23. my_followers = api.GetFollowers()
  24.  
  25. # get name of my followers
  26. my_followers = [i.screen_name for i in my_followers]
  27.  
  28. a = 0
  29. for i in my_friends:
  30. if i.screen_name not in my_followers:
  31. print "bye bye", i.screen_name
  32. api.DestroyFriendship(i.screen_name)
  33.  
  34. # oui ce code est imonde
  35. a += 1
  36. if a == stop:
  37. print "Stop at %s unfollow" % stop
  38. break
  39.  
  40. def steal_friends(api, argv):
  41. if len(argv) <= 2:
  42. print "Need user name"
  43. sys.exit(1)
  44. if len(argv) <= 3:
  45. stop = 1000
  46. else:
  47. stop = int(argv[3])
  48.  
  49. user = argv[2]
  50. amis = api.GetFriends(user)
  51.  
  52. a = 0
  53. for i in amis:
  54. try:
  55. api.CreateFriendship(i.screen_name)
  56. except Exception, e:
  57. print "Exception for %s" % i.screen_name, e
  58. else:
  59. print i.screen_name
  60. # oui ce code est imonde
  61. a += 1
  62. if a == stop:
  63. print "Stop at %s new friends" % stop
  64. break
  65.  
  66. def follow_followers(api, argv):
  67. if len(argv) <= 2:
  68. stop = 1000
  69. else:
  70. stop = int(argv[2])
  71.  
  72. amis = api.GetFriends()
  73.  
  74. a = 0
  75. for i in amis:
  76. try:
  77. api.CreateFriendship(i.screen_name)
  78. except Exception, e:
  79. print "Exception for %s" % i.screen_name, e
  80. else:
  81. print i.screen_name
  82. # oui ce code est imonde
  83. a += 1
  84. if a == stop:
  85. print "Stop at %s new friends" % stop
  86. break
  87.  
  88. def print_help():
  89. print "Commands:"
  90. print " unfollow unfollow all the people that aren't following me"
  91. print " steal follow all the friends off someone, user name require"
  92. print " ff follow my followers"
  93. print
  94. print "Don't forget to put your user name and your password in the script !"
  95.  
  96. if __name__ == "__main__":
  97. api = twitter.Api(username='zoubiboulba', password='hophophop')
  98.  
  99. if len(sys.argv) <= 1:
  100. print_help()
  101. sys.exit(1)
  102.  
  103. command = {"steal" : steal_friends, "unfollow" : unfollowator,
  104. "ff" : follow_followers}
  105.  
  106. if sys.argv[1] not in command.keys():
  107. print "Unknow command", sys.argv[1]
  108. else:
  109. command[sys.argv[1]](api, sys.argv)
  110.  
  111. # vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement